import { PrismaService } from "@cv/system"; import { Injectable } from "@nestjs/common"; import { notFound } from "../errors"; import type { User } from "./user.entity"; import { UserMapper } from "./user.mapper"; @Injectable() export class UserService { private readonly userInclude = { credentials: true, }; constructor( private prisma: PrismaService, private userMapper: UserMapper, ) {} async create(name: string): Promise { const prismaUser = await this.prisma.user.create({ data: { name, }, include: this.userInclude, }); return this.userMapper.toDomain(prismaUser); } async findById(id: string): Promise { const prismaUser = await this.prisma.user.findUnique({ where: { id }, include: this.userInclude, }); return this.userMapper.toDomain(prismaUser); } async findByIdOrFail(id: string): Promise { const user = await this.findById(id); return user ?? notFound("User", "id", id); } async delete(id: string): Promise { await this.prisma.user.delete({ where: { id }, }); } }