feat(pos): add favorite functionality for goods

- Implemented PosGoodFavoriteController to handle attaching and detaching favorites for goods.
- Created PosGoodFavoriteService to manage the business logic for favorites, including database operations and cache invalidation.
- Added PosGoodFavoriteModule to encapsulate the controller and service.
This commit is contained in:
2026-05-20 11:42:59 +03:30
parent 98099e97e7
commit fc27b9d616
19 changed files with 1989 additions and 62 deletions
+20 -4
View File
@@ -51,7 +51,11 @@ export class GoodsService {
},
}
async findAll(business_activity_id: string, guild_id: string) {
async findAll(
business_activity_id: string,
guild_id: string,
consumer_account_id: string,
) {
const cacheKey = RedisKeyMaker.posGoodsList(business_activity_id, guild_id)
const cached = await this.redisService.getJson<unknown[]>(cacheKey)
if (cached) {
@@ -72,12 +76,24 @@ export class GoodsService {
},
],
},
select: this.defaultSelect,
select: {
...this.defaultSelect,
consumer_account_good_favorites: {
where: {
consumer_account_id,
},
},
},
})
await this.redisService.setJson(cacheKey, goods, this.listCacheTtlSeconds)
const mappedGoods = goods.map(good => ({
...good,
is_favorite: good.consumer_account_good_favorites.length > 0,
}))
return ResponseMapper.list(goods)
await this.redisService.setJson(cacheKey, mappedGoods, this.listCacheTtlSeconds)
return ResponseMapper.list(mappedGoods)
}
async findOne(good_id: string, business_activity_id: string, guild_id: string) {