This commit is contained in:
2026-07-17 10:18:39 +03:30
parent 4abc2ae6e5
commit 443b62eb8e
10 changed files with 214 additions and 20 deletions
@@ -14,6 +14,8 @@ type FindReviewsOpts = {
orderBy?: string;
restId?: string;
order?: 'asc' | 'desc';
parentId?: string;
topLevel?: boolean;
};
@Injectable()
@@ -27,11 +29,20 @@ export class ReviewRepository extends EntityRepository<Review> {
* Supports: foodId, userId, status, ordering.
*/
async findAllPaginated(opts: FindReviewsOpts = {}): Promise<PaginatedResult<Review>> {
const { page = 1, limit = 10, foodId, restId, userId, status, orderBy = 'createdAt', order = 'desc' } = opts;
const { page = 1, limit = 10, parentId, topLevel,
foodId, restId, userId, status, orderBy = 'createdAt', order = 'desc' } = opts;
const offset = (page - 1) * limit;
// Only list top-level reviews; replies are nested under their parent
const where: FilterQuery<Review> = {};
if (topLevel) {
where.parent = null;
}
if (parentId) {
where.parent = { id: parentId };
}
if (foodId) {
where.food = { id: foodId };
@@ -53,7 +64,7 @@ export class ReviewRepository extends EntityRepository<Review> {
limit,
offset,
orderBy: { [orderBy]: order.toLowerCase() as 'asc' | 'desc' },
populate: ['food', 'user'],
populate: ['user'],
});
const totalPages = Math.ceil(total / limit);