boredgame/src/lib/server/api/services/collections.service.ts

41 lines
1.1 KiB
TypeScript
Raw Normal View History

import { inject, injectable } from "tsyringe";
import { generateRandomAnimalName } from "$lib/utils/randomDataUtil";
import { CollectionsRepository } from "../repositories/collections.repository";
@injectable()
export class CollectionsService {
constructor(
@inject(CollectionsRepository) private readonly collectionsRepository: CollectionsRepository
) { }
async findOneByUserId(userId: string) {
return this.collectionsRepository.findOneByUserId(userId);
}
async findAllByUserId(userId: string) {
return this.collectionsRepository.findAllByUserId(userId);
}
2024-09-16 16:07:22 +00:00
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) {
return this.createEmpty(userId, null);
}
async createEmpty(userId: string, name: string | null) {
return this.collectionsRepository.create({
user_id: userId,
name: name ?? generateRandomAnimalName(),
});
}
}