Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async handleGetExercise(
- user: UserDTO,
- queryOptions: ExerciseQueryOptionsDTO,
- ): Promise<any> {
- try {
- const businessEntry = user.business;
- if (!businessEntry) {
- return await handleSendNotFound('Business not found');
- }
- const limit = parseInt(queryOptions.limit?.toString() ?? '10');
- const page = parseInt(queryOptions.page?.toString() ?? '1');
- const types = queryOptions.type?.split(',') ?? '';
- const query = queryOptions.query ?? '';
- const skip = limit * page - limit;
- const [exercises, count] = await this.exerciseRepository
- .createQueryBuilder('exercise')
- .select()
- .where('LOWER(exercise.title) like :title', {
- title: `%${query.toLowerCase()}%`,
- })
- .andWhere(
- types.length > 0 && types[0] != ''
- ? 'exercise.muscleGroup && (:...types)'
- : '1=1',
- { types: [types] },
- )
- .andWhere('exercise.businessId = :bid', { bid: businessEntry.id })
- .orderBy('exercise.createdAt')
- .skip(skip)
- .take(limit)
- .getManyAndCount();
- return await handleSendData('Retrieved exercises', {
- exercises,
- count,
- hasMore: limit * page < count,
- });
- } catch (e) {
- return await handleSendFallbackError(
- e,
- 'Database: Failed to retrieve exercises!',
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement