@@ -3,15 +3,26 @@ import { Prisma } from '@prisma/client';
|
||||
import { PrismaService } from '../../common/prisma/prisma.module';
|
||||
import { serializeBigInt } from '../../common/decorators/current-user.decorator';
|
||||
import type { AdminStoreRatingsQueryDto } from './dto/admin-query.dto';
|
||||
import { HqPermissionsResolver, mergeHqStoreCityWhere } from '../../common/guards/hq-permission.guard';
|
||||
|
||||
@Injectable()
|
||||
export class AdminStoreRatingsService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly hqPermissions: HqPermissionsResolver,
|
||||
) {}
|
||||
|
||||
async list(query: AdminStoreRatingsQueryDto) {
|
||||
async list(query: AdminStoreRatingsQueryDto, actorId: bigint) {
|
||||
const page = query.page ?? 1;
|
||||
const pageSize = query.pageSize ?? 20;
|
||||
const where: Prisma.StoreRatingWhereInput = {};
|
||||
const scope = await this.hqPermissions.resolveCityScope(actorId);
|
||||
if (query.storeId) {
|
||||
await this.hqPermissions.assertStoreIdInScope(actorId, BigInt(query.storeId));
|
||||
}
|
||||
const storeWhere = mergeHqStoreCityWhere({}, scope, query.cityId);
|
||||
const where: Prisma.StoreRatingWhereInput = {
|
||||
store: storeWhere,
|
||||
};
|
||||
if (query.storeId) where.storeId = BigInt(query.storeId);
|
||||
if (query.redeemNo) {
|
||||
where.redeemRecord = { redeemNo: { contains: query.redeemNo } };
|
||||
|
||||
Reference in New Issue
Block a user