2026-05-20 11:42:59 +03:30
|
|
|
import { RedisService } from '@/redis/redis.service'
|
|
|
|
|
import { Injectable } from '@nestjs/common'
|
2026-05-20 20:22:00 +03:30
|
|
|
import { ResponseMapper } from '../../../../common/response/response-mapper'
|
|
|
|
|
import { PrismaService } from '../../../../prisma/prisma.service'
|
|
|
|
|
import { PosCacheInvalidationService } from '../../cache/pos-cache-invalidation.service'
|
2026-05-20 11:42:59 +03:30
|
|
|
|
|
|
|
|
@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,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
2026-05-20 20:22:00 +03:30
|
|
|
await this.posCacheInvalidationService.invalidatePosGoodsList(guild_id, business_id)
|
2026-05-20 11:42:59 +03:30
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
2026-05-20 20:22:00 +03:30
|
|
|
await this.posCacheInvalidationService.invalidatePosGoodsList(guild_id, business_id)
|
2026-05-20 11:42:59 +03:30
|
|
|
|
|
|
|
|
return ResponseMapper.delete()
|
|
|
|
|
}
|
|
|
|
|
}
|