2024-08-13 22:19:57 +00:00
|
|
|
import { inject, injectable } from "tsyringe";
|
|
|
|
|
import { WishlistsRepository } from "../repositories/wishlists.repository";
|
|
|
|
|
import { generateRandomAnimalName } from "$lib/utils/randomDataUtil";
|
|
|
|
|
|
|
|
|
|
@injectable()
|
|
|
|
|
export class WishlistsService {
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
@inject(WishlistsRepository) private readonly wishlistsRepository: WishlistsRepository
|
|
|
|
|
) { }
|
|
|
|
|
|
|
|
|
|
async findAllByUserId(userId: string) {
|
|
|
|
|
return this.wishlistsRepository.findAllByUserId(userId);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-23 02:26:22 +00:00
|
|
|
async findOneById(id: string) {
|
|
|
|
|
return this.wishlistsRepository.findOneById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async findOneByCuid(cuid: string) {
|
|
|
|
|
return this.wishlistsRepository.findOneByCuid(cuid);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-13 22:19:57 +00:00
|
|
|
async createEmptyNoName(userId: string) {
|
|
|
|
|
return this.createEmpty(userId, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async createEmpty(userId: string, name: string | null) {
|
|
|
|
|
return this.wishlistsRepository.create({
|
|
|
|
|
user_id: userId,
|
|
|
|
|
name: name ?? generateRandomAnimalName(),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|