import { GoodOmit } from '@/generated/prisma/models' import { PrismaService } from '@/prisma/prisma.service' import { Injectable } from '@nestjs/common' import { ResponseMapper } from 'common/response/response-mapper' import { CreateGoodDto } from './dto/create-good.dto' @Injectable() export class GoodsService { constructor(private prisma: PrismaService) {} private readonly goodOmit = { complex_id: true, barcode: true, base_sale_price: true, is_default_guild_good: true, local_sku: true, guild_id: true, } as GoodOmit async findAll(guildId: string) { const [goods, count] = await this.prisma.$transaction([ this.prisma.good.findMany({ where: { guild_id: guildId, is_default_guild_good: true, }, omit: this.goodOmit, }), this.prisma.good.count(), ]) return ResponseMapper.paginate(goods, { count, }) } async findOne(guild_id: string, id: string) { const good = await this.prisma.good.findUnique({ where: { guild_id, id, is_default_guild_good: true, }, omit: this.goodOmit, }) return ResponseMapper.single(good) } async create(guild_id: string, data: CreateGoodDto) { const { category_id, ...rest } = data const good = await this.prisma.good.create({ data: { guild: { connect: { id: guild_id, }, }, category: { connect: { id: category_id, }, }, ...rest, is_default_guild_good: true, }, omit: this.goodOmit, }) return ResponseMapper.create(good) } }