mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import type { db } from '$lib/server/api/packages/drizzle'
|
|
import { generateRandomAnimalName } from '$lib/utils/randomDataUtil'
|
|
import { inject, injectable } from 'tsyringe'
|
|
import { WishlistsRepository } from '../repositories/wishlists.repository'
|
|
|
|
@injectable()
|
|
export class WishlistsService {
|
|
constructor(@inject(WishlistsRepository) private readonly wishlistsRepository: WishlistsRepository) {}
|
|
|
|
async findAllByUserId(userId: string) {
|
|
return this.wishlistsRepository.findAllByUserId(userId)
|
|
}
|
|
|
|
async findOneById(id: string) {
|
|
return this.wishlistsRepository.findOneById(id)
|
|
}
|
|
|
|
async findOneByCuid(cuid: string) {
|
|
return this.wishlistsRepository.findOneByCuid(cuid)
|
|
}
|
|
|
|
async createEmptyNoName(userId: string, trx: Parameters<Parameters<typeof db.transaction>[0]>[0] | null = null) {
|
|
return this.createEmpty(userId, null, trx)
|
|
}
|
|
|
|
async createEmpty(userId: string, name: string | null, trx: Parameters<Parameters<typeof db.transaction>[0]>[0] | null = null) {
|
|
if (!trx) {
|
|
return this.wishlistsRepository.create({
|
|
user_id: userId,
|
|
name: name ?? generateRandomAnimalName(),
|
|
})
|
|
}
|
|
return this.wishlistsRepository.create(
|
|
{
|
|
user_id: userId,
|
|
name: name ?? generateRandomAnimalName(),
|
|
},
|
|
trx,
|
|
)
|
|
}
|
|
}
|