all food endponit

This commit is contained in:
2026-06-21 16:54:42 +03:30
parent 449cd89287
commit 73c7e55bf3
9 changed files with 159 additions and 11 deletions
@@ -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),
},
};
}
}