2026-03-07 11:25:11 +03:30
|
|
|
import { GoodOmit } from '@/generated/prisma/models'
|
|
|
|
|
import { PrismaService } from '@/prisma/prisma.service'
|
|
|
|
|
import { Injectable } from '@nestjs/common'
|
|
|
|
|
import { ResponseMapper } from 'common/response/response-mapper'
|
2026-03-11 20:42:34 +03:30
|
|
|
import { CreateGuildGoodDto } from './dto/create-good.dto'
|
2026-03-07 11:25:11 +03:30
|
|
|
|
|
|
|
|
@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,
|
|
|
|
|
} as GoodOmit
|
|
|
|
|
|
|
|
|
|
async findAll(guildId: string) {
|
|
|
|
|
const [goods, count] = await this.prisma.$transaction([
|
|
|
|
|
this.prisma.good.findMany({
|
|
|
|
|
where: {
|
|
|
|
|
is_default_guild_good: true,
|
2026-03-16 00:33:40 +03:30
|
|
|
category: {
|
|
|
|
|
guild_id: guildId,
|
|
|
|
|
},
|
2026-03-07 11:25:11 +03:30
|
|
|
},
|
2026-03-11 20:42:34 +03:30
|
|
|
include: {
|
|
|
|
|
category: {
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-03-07 11:25:11 +03:30
|
|
|
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: {
|
|
|
|
|
id,
|
|
|
|
|
is_default_guild_good: true,
|
2026-03-16 00:33:40 +03:30
|
|
|
category: {
|
|
|
|
|
guild_id,
|
|
|
|
|
},
|
2026-03-07 11:25:11 +03:30
|
|
|
},
|
|
|
|
|
|
2026-03-11 20:42:34 +03:30
|
|
|
include: {
|
|
|
|
|
category: {
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
2026-03-07 11:25:11 +03:30
|
|
|
omit: this.goodOmit,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return ResponseMapper.single(good)
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 13:31:40 +03:30
|
|
|
async create(data: CreateGuildGoodDto) {
|
2026-03-07 11:25:11 +03:30
|
|
|
const { category_id, ...rest } = data
|
|
|
|
|
|
|
|
|
|
const good = await this.prisma.good.create({
|
|
|
|
|
data: {
|
|
|
|
|
category: {
|
|
|
|
|
connect: {
|
|
|
|
|
id: category_id,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
...rest,
|
|
|
|
|
is_default_guild_good: true,
|
|
|
|
|
},
|
|
|
|
|
omit: this.goodOmit,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return ResponseMapper.create(good)
|
|
|
|
|
}
|
|
|
|
|
}
|