youssef Qatry commited on
Commit
2f11d6d
·
unverified ·
2 Parent(s): 0dbb68c 163e3e0

Merge pull request #84 from Modarb-Ai-Trainer/docs

Browse files

Edit filters in search & list (exercises, ingredients, workouts,...etc)

src/modules/users/modules/exercises/controllers/exercises.controller.ts CHANGED
@@ -34,11 +34,21 @@ export class UsersExerciseController extends BaseController {
34
  @SwaggerQuery({
35
  limit: "number",
36
  skip: "number",
 
 
37
  })
38
  list = async (req: Request, res: Response): Promise<Response> => {
39
  const paginationQuery = parsePaginationQuery(req.query);
 
 
 
 
 
 
 
 
40
  const { docs, paginationData } = await this.exercisesService.list(
41
- {},
42
  paginationQuery,
43
  {
44
  populateArray: [
@@ -47,7 +57,7 @@ export class UsersExerciseController extends BaseController {
47
  { path: "equipments" }
48
  ]
49
  }
50
- );
51
 
52
  return JsonResponse.success(
53
  {
@@ -86,8 +96,12 @@ export class UsersExerciseController extends BaseController {
86
 
87
  @SwaggerGet('/search')
88
  @SwaggerResponse([ExercisePopulateSerialization])
89
- @SwaggerSummary("Search")
90
- @SwaggerDescription("Search for exercises")
 
 
 
 
91
  search = async (req: Request, res: Response): Promise<Response> => {
92
  const paginationQuery = parsePaginationQuery(req.query);
93
  let query = {};
 
34
  @SwaggerQuery({
35
  limit: "number",
36
  skip: "number",
37
+ filterName: "string",
38
+ filterVal: "string"
39
  })
40
  list = async (req: Request, res: Response): Promise<Response> => {
41
  const paginationQuery = parsePaginationQuery(req.query);
42
+
43
+ let filterName = req.query.filterName, filterVal = req.query.filterVal;
44
+ let filter = {};
45
+
46
+ if (filterName && filterVal) {
47
+ filter[`${filterName}`] = filterVal;
48
+ }
49
+
50
  const { docs, paginationData } = await this.exercisesService.list(
51
+ filter,
52
  paginationQuery,
53
  {
54
  populateArray: [
 
57
  { path: "equipments" }
58
  ]
59
  }
60
+ );
61
 
62
  return JsonResponse.success(
63
  {
 
96
 
97
  @SwaggerGet('/search')
98
  @SwaggerResponse([ExercisePopulateSerialization])
99
+ @SwaggerSummary("Search for exercises")
100
+ @SwaggerDescription("You can use filters in search like category")
101
+ @SwaggerQuery({
102
+ searchTerm: "string",
103
+ filter: "string"
104
+ })
105
  search = async (req: Request, res: Response): Promise<Response> => {
106
  const paginationQuery = parsePaginationQuery(req.query);
107
  let query = {};
src/modules/users/modules/ingredients/controller/ingredients.controller.ts CHANGED
@@ -33,11 +33,21 @@ export class UsersIngredientsController extends BaseController {
33
  @SwaggerQuery({
34
  limit: "number",
35
  skip: "number",
 
 
36
  })
37
  list = async (req: Request, res: Response) => {
38
  const paginationQuery = parsePaginationQuery(req.query);
 
 
 
 
 
 
 
 
39
  const { docs, paginationData } = await this.ingredientsService.list(
40
- {},
41
  paginationQuery
42
  );
43
 
 
33
  @SwaggerQuery({
34
  limit: "number",
35
  skip: "number",
36
+ filterName: "string",
37
+ filterVal: "string"
38
  })
39
  list = async (req: Request, res: Response) => {
40
  const paginationQuery = parsePaginationQuery(req.query);
41
+
42
+ let filterName = req.query.filterName, filterVal = req.query.filterVal;
43
+ let filter = {};
44
+
45
+ if (filterName && filterVal) {
46
+ filter[`${filterName}`] = filterVal;
47
+ }
48
+
49
  const { docs, paginationData } = await this.ingredientsService.list(
50
+ filter,
51
  paginationQuery
52
  );
53
 
src/modules/users/modules/workouts/controllers/workouts.controller.ts CHANGED
@@ -34,11 +34,21 @@ export class UsersWorkoutController extends BaseController {
34
  @SwaggerQuery({
35
  limit: "number",
36
  skip: "number",
 
 
37
  })
38
  list = async (req: Request, res: Response): Promise<Response> => {
39
  const paginationQuery = parsePaginationQuery(req.query);
 
 
 
 
 
 
 
 
40
  const { docs, paginationData } = await this.workoutsService.list(
41
- {},
42
  paginationQuery
43
  );
44
 
 
34
  @SwaggerQuery({
35
  limit: "number",
36
  skip: "number",
37
+ filterName: "string",
38
+ filterVal: "string",
39
  })
40
  list = async (req: Request, res: Response): Promise<Response> => {
41
  const paginationQuery = parsePaginationQuery(req.query);
42
+
43
+ let filterName = req.query.filterName, filterVal = req.query.filterVal;
44
+ let filter = {};
45
+
46
+ if (filterName && filterVal) {
47
+ filter[`${filterName}`] = filterVal;
48
+ }
49
+
50
  const { docs, paginationData } = await this.workoutsService.list(
51
+ filter,
52
  paginationQuery
53
  );
54