mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import type {db} from '$lib/server/api/packages/drizzle'
|
|
import {generateRandomAnimalName} from '$lib/utils/randomDataUtil'
|
|
import {inject, injectable} from '@needle-di/core'
|
|
import {CollectionsRepository} from '../repositories/collections.repository'
|
|
|
|
@injectable()
|
|
export class CollectionsService {
|
|
constructor(private collectionsRepository = inject(CollectionsRepository)) {}
|
|
|
|
async findOneByUserId(userId: string) {
|
|
return this.collectionsRepository.findOneByUserId(userId)
|
|
}
|
|
|
|
async findAllByUserId(userId: string) {
|
|
return this.collectionsRepository.findAllByUserId(userId)
|
|
}
|
|
|
|
async findAllByUserIdWithDetails(userId: string) {
|
|
return this.collectionsRepository.findAllByUserIdWithDetails(userId)
|
|
}
|
|
|
|
async findOneById(id: string) {
|
|
return this.collectionsRepository.findOneById(id)
|
|
}
|
|
|
|
async findOneByCuid(cuid: string) {
|
|
return this.collectionsRepository.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.collectionsRepository.create({
|
|
user_id: userId,
|
|
name: name ?? generateRandomAnimalName(),
|
|
})
|
|
}
|
|
|
|
return this.collectionsRepository.create(
|
|
{
|
|
user_id: userId,
|
|
name: name ?? generateRandomAnimalName(),
|
|
},
|
|
trx,
|
|
)
|
|
}
|
|
}
|