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:
@@ -0,0 +1,84 @@
|
||||
import { RedisService } from '@/redis/redis.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from '../../../../common/response/response-mapper'
|
||||
import { PrismaService } from '../../../../prisma/prisma.service'
|
||||
import { PosCacheInvalidationService } from '../../cache/pos-cache-invalidation.service'
|
||||
|
||||
@Injectable()
|
||||
export class PosGoodFavoriteService {
|
||||
constructor(
|
||||
private prisma: PrismaService,
|
||||
|
||||
private readonly redisService: RedisService,
|
||||
private readonly posCacheInvalidationService: PosCacheInvalidationService,
|
||||
) {}
|
||||
|
||||
async attach(
|
||||
good_id: string,
|
||||
business_id: string,
|
||||
guild_id: string,
|
||||
consumer_account_id: string,
|
||||
) {
|
||||
const favorite = await this.prisma.consumerAccountGoodFavorite.upsert({
|
||||
where: {
|
||||
consumer_account_id_good_id: {
|
||||
consumer_account_id,
|
||||
good_id,
|
||||
},
|
||||
good: {
|
||||
OR: [
|
||||
{
|
||||
business_activity_id: business_id,
|
||||
},
|
||||
{
|
||||
sku: {
|
||||
guild_id,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
update: {},
|
||||
create: {
|
||||
consumer_account_id,
|
||||
good_id,
|
||||
},
|
||||
})
|
||||
|
||||
await this.posCacheInvalidationService.invalidatePosGoodsList(guild_id, business_id)
|
||||
|
||||
return ResponseMapper.create(favorite)
|
||||
}
|
||||
|
||||
async detach(
|
||||
good_id: string,
|
||||
business_id: string,
|
||||
guild_id: string,
|
||||
consumer_account_id: string,
|
||||
) {
|
||||
const favorite = await this.prisma.consumerAccountGoodFavorite.delete({
|
||||
where: {
|
||||
consumer_account_id_good_id: {
|
||||
consumer_account_id,
|
||||
good_id,
|
||||
},
|
||||
good: {
|
||||
OR: [
|
||||
{
|
||||
business_activity_id: business_id,
|
||||
},
|
||||
{
|
||||
sku: {
|
||||
guild_id,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
await this.posCacheInvalidationService.invalidatePosGoodsList(guild_id, business_id)
|
||||
|
||||
return ResponseMapper.delete()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user