import { Injectable } from '@nestjs/common'; import { PrismaService } from '@/prisma/prisma.service'; import { ResponseMapper } from '@/common/response/response-mapper' import { Create{{pascalCase name}}Dto } from './dto/create-{{kebabCase name}}.dto'; import { Update{{pascalCase name}}Dto } from './dto/update-{{kebabCase name}}.dto'; @Injectable() export class {{pascalCase name}}Service { constructor(private readonly prisma: PrismaService) {} private readonly summarySelect = { id: true, } private readonly select = { ...this.summarySelect, } private readonly where = () => ({}) async findAll() { const items = await this.prisma.{{camelCase name}}.findMany({ where: this.where(), select: this.summarySelect, }); return ResponseMapper.list(items) } async findOne(id: string) { const item = this.prisma.{{camelCase name}}.findUnique({ where: {...this.where(), id }, select: this.select, }); return ResponseMapper.single(item) } async create(createDto: Create{{pascalCase name}}Dto) { const item = this.prisma.{{camelCase name}}.create({ data: createDto, select: this.select, }); return ResponseMapper.create(item) } async update(id: string, updateDto: Update{{pascalCase name}}Dto) { const item = this.prisma.{{camelCase name}}.update({ where: { id }, data: updateDto, select: this.select, }); return ResponseMapper.update(item) } async remove(id: string) { return this.prisma.{{camelCase name}}.delete({ where: { id }, }); } }