refactor(goods): streamline goods service and controller, remove favorites module

- Removed the PosGoodFavorite module, controller, and service to simplify the codebase.
- Updated goods service to handle cache invalidation directly.
- Refactored goods controller to remove commented-out code and improve clarity.
- Introduced OwnedGoods module for better organization of owned goods functionality.
- Updated DTOs to extend from existing structures for consistency.
- Enhanced cache invalidation logic in goods service and owned goods service.
This commit is contained in:
2026-05-20 20:22:00 +03:30
parent fc27b9d616
commit 1d47fb1a1d
31 changed files with 1166 additions and 345 deletions
+10 -31
View File
@@ -91,12 +91,8 @@ export class GoodsService {
return ResponseMapper.single(good)
}
async create(data: CreateGuildGoodDto, file: Express.Multer.File) {
async create(guildId: string, data: CreateGuildGoodDto, file: Express.Multer.File) {
const { category_id, measure_unit_id, sku_id, ...rest } = data
const category = await this.prisma.goodCategory.findUnique({
where: { id: category_id },
select: { guild_id: true },
})
const good = await this.prisma.$transaction(async tx => {
let image_url = ''
@@ -133,28 +129,21 @@ export class GoodsService {
})
})
if (category?.guild_id) {
await this.cacheInvalidationService.invalidateGoodsList(category.guild_id)
}
await this.cacheInvalidationService.invalidateGoodsList(guildId)
return ResponseMapper.create(good)
}
async update(id: string, data: UpdateGuildGoodDto, file: Express.Multer.File) {
async update(
guildId: string,
id: string,
data: UpdateGuildGoodDto,
file: Express.Multer.File,
) {
const { category_id, measure_unit_id, sku_id, ...rest } = data
const prevGood = await this.prisma.good.findUnique({
where: { id },
select: { category: { select: { guild_id: true } } },
})
const nextCategory = category_id
? await this.prisma.goodCategory.findUnique({
where: { id: category_id },
select: { guild_id: true },
})
: null
const good = await this.prisma.$transaction(async tx => {
let image_url = ''
let image_url = undefined as string | undefined
if (file) {
const uploadedUrl = await this.uploaderService.uploadFile(
file,
@@ -198,17 +187,7 @@ export class GoodsService {
})
})
const cacheGuildIds = new Set<string>()
if (prevGood?.category?.guild_id) {
cacheGuildIds.add(prevGood.category.guild_id)
}
if (nextCategory?.guild_id) {
cacheGuildIds.add(nextCategory.guild_id)
}
for (const guildId of cacheGuildIds) {
await this.cacheInvalidationService.invalidateGoodsList(guildId)
}
await this.cacheInvalidationService.invalidateGoodsList(guildId)
return ResponseMapper.create(good)
}