all food endponit
This commit is contained in:
@@ -62,7 +62,37 @@ export class FoodRepository extends EntityRepository<Food> {
|
||||
totalPages,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async searchActiveAcrossRestaurants(
|
||||
search: string,
|
||||
opts: Pick<FindFoodsOpts, 'page' | 'limit'> = {},
|
||||
): Promise<PaginatedResult<Food>> {
|
||||
const { page = 1, limit = 10 } = opts;
|
||||
const offset = (page - 1) * limit;
|
||||
const pattern = `%${search}%`;
|
||||
|
||||
const where: FilterQuery<Food> = {
|
||||
isActive: true,
|
||||
restaurant: { isActive: true },
|
||||
$or: [{ title: { $ilike: pattern } }, { desc: { $ilike: pattern } }],
|
||||
};
|
||||
|
||||
const [data, total] = await this.findAndCount(where, {
|
||||
limit,
|
||||
offset,
|
||||
orderBy: { title: 'asc' },
|
||||
populate: ['restaurant'],
|
||||
});
|
||||
|
||||
return {
|
||||
data,
|
||||
meta: {
|
||||
total,
|
||||
page,
|
||||
limit,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user