89 lines
2.0 KiB
TypeScript
89 lines
2.0 KiB
TypeScript
|
|
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.invalidateGoodsListByBusinessActivity(
|
||
|
|
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.invalidateGoodsListByBusinessActivity(
|
||
|
|
business_id,
|
||
|
|
)
|
||
|
|
|
||
|
|
return ResponseMapper.delete()
|
||
|
|
}
|
||
|
|
}
|