review
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user