This commit is contained in:
2025-12-09 11:18:56 +03:30
parent aa642bf5b4
commit 53eb7f3ace
9 changed files with 79 additions and 27 deletions
@@ -3,13 +3,14 @@ import { EntityManager, EntityRepository } from '@mikro-orm/postgresql';
import { FilterQuery } from '@mikro-orm/core';
import { Review } from '../entities/review.entity';
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
import { ReviewStatus } from '../enums/review-status.enum';
type FindReviewsOpts = {
page?: number;
limit?: number;
foodId?: string;
userId?: string;
isApproved?: boolean;
status?: ReviewStatus;
orderBy?: string;
restId?: string;
order?: 'asc' | 'desc';
@@ -23,10 +24,10 @@ export class ReviewRepository extends EntityRepository<Review> {
/**
* Find reviews with pagination and optional filters.
* Supports: foodId, userId, isApproved, ordering.
* Supports: foodId, userId, status, ordering.
*/
async findAllPaginated(opts: FindReviewsOpts = {}): Promise<PaginatedResult<Review>> {
const { page = 1, limit = 10, foodId, restId, userId, isApproved, orderBy = 'createdAt', order = 'desc' } = opts;
const { page = 1, limit = 10, foodId, restId, userId, status, orderBy = 'createdAt', order = 'desc' } = opts;
const offset = (page - 1) * limit;
@@ -44,8 +45,8 @@ export class ReviewRepository extends EntityRepository<Review> {
where.user = { id: userId };
}
if (typeof isApproved === 'boolean') {
where.isApproved = isApproved;
if (status) {
where.status = status;
}
const [data, total] = await this.findAndCount(where, {