because I got bored of customising my CV for every job
1import { PrismaService } from "@cv/system";
2import { Injectable } from "@nestjs/common";
3import { notFound } from "../errors";
4import type { User } from "./user.entity";
5import { UserMapper } from "./user.mapper";
6
7@Injectable()
8export class UserService {
9 private readonly userInclude = {
10 credentials: true,
11 };
12
13 constructor(
14 private prisma: PrismaService,
15 private userMapper: UserMapper,
16 ) {}
17
18 async create(name: string): Promise<User> {
19 const prismaUser = await this.prisma.user.create({
20 data: {
21 name,
22 },
23 include: this.userInclude,
24 });
25
26 return this.userMapper.toDomain(prismaUser);
27 }
28
29 async findById(id: string): Promise<User | null> {
30 const prismaUser = await this.prisma.user.findUnique({
31 where: { id },
32 include: this.userInclude,
33 });
34
35 return this.userMapper.toDomain(prismaUser);
36 }
37
38 async findByIdOrFail(id: string): Promise<User> {
39 const user = await this.findById(id);
40 return user ?? notFound("User", "id", id);
41 }
42
43 async delete(id: string): Promise<void> {
44 await this.prisma.user.delete({
45 where: { id },
46 });
47 }
48}