Hozifa Elgharbawy commited on
Commit
b9af431
·
1 Parent(s): f081a42

chore: Update serializers and controllers for user-registered-meal-plan and user-registered-workoutPopulate

Browse files
src/common/serializers/user-registered-meal-planPopulate.serialization.ts CHANGED
@@ -3,7 +3,6 @@ import { serialize } from "@helpers/serialize";
3
  import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
4
  import { MealSerialization } from "./meal.serialization";
5
  import { MealPlanSerialization } from "./meal-plan.serialization";
6
- import { UserSerialization } from "./user.serialization";
7
 
8
 
9
 
@@ -46,31 +45,4 @@ export class UserRegisteredMealPlansPopulateSerialization {
46
  )
47
  days: any;
48
 
49
- }
50
-
51
-
52
- export class UserRegisteredMealPlansPopulateUserSerialization {
53
- @Expose({ name: "_id" })
54
- @SwaggerResponseProperty({ type: "string" })
55
- id: string;
56
-
57
- @Expose()
58
- @SwaggerResponseProperty({ type: UserSerialization })
59
- user: string;
60
-
61
- @Expose()
62
- @SwaggerResponseProperty({ type: MealPlanSerialization })
63
- meal_plan: string;
64
-
65
- @Expose()
66
- @SwaggerResponseProperty({ type: "boolean" })
67
- isActive: boolean;
68
-
69
- @Expose({ name: "days" })
70
- @SwaggerResponseProperty({ type: [MealDaysPopulate] })
71
- @Transform(
72
- ({ value }) => serialize(value, MealDaysPopulate)
73
- )
74
- days: any;
75
-
76
  }
 
3
  import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
4
  import { MealSerialization } from "./meal.serialization";
5
  import { MealPlanSerialization } from "./meal-plan.serialization";
 
6
 
7
 
8
 
 
45
  )
46
  days: any;
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  }
src/common/serializers/user-registered-workoutPopulate.serialization.ts CHANGED
@@ -3,6 +3,7 @@ import { serialize } from "@helpers/serialize";
3
  import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
4
  import { ExerciseSerialization } from "./exercise.serialization";
5
  import { WorkoutSerialization } from "./workout.serialization";
 
6
 
7
 
8
  class MyWorkoutDaysPopulate {
@@ -72,3 +73,28 @@ export class UserRegisteredWorkoutsPopulateSerialization {
72
  @Transform(({ value }) => serialize(value, MyWorkoutWeeksPopulate))
73
  weeks: any;
74
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
4
  import { ExerciseSerialization } from "./exercise.serialization";
5
  import { WorkoutSerialization } from "./workout.serialization";
6
+ import { UserSerialization } from "./user.serialization";
7
 
8
 
9
  class MyWorkoutDaysPopulate {
 
73
  @Transform(({ value }) => serialize(value, MyWorkoutWeeksPopulate))
74
  weeks: any;
75
  }
76
+
77
+
78
+
79
+ export class UserRegisteredWorkoutsPopulateUserSerialization {
80
+ @Expose({ name: "_id" })
81
+ @SwaggerResponseProperty({ type: "string" })
82
+ id: string;
83
+
84
+ @Expose()
85
+ @SwaggerResponseProperty({ type: UserSerialization })
86
+ user: any;
87
+
88
+ @Expose()
89
+ @SwaggerResponseProperty({ type: WorkoutSerialization })
90
+ workout: string;
91
+
92
+ @Expose()
93
+ @SwaggerResponseProperty({ type: "boolean" })
94
+ is_active: Boolean;
95
+
96
+ @Expose({ name: "weeks" })
97
+ @SwaggerResponseProperty({ type: [MyWorkoutWeeksPopulate] })
98
+ @Transform(({ value }) => serialize(value, MyWorkoutWeeksPopulate))
99
+ weeks: any;
100
+ }
src/modules/users/modules/user-registered-workouts/controllers/user-registered-workouts.controller.ts CHANGED
@@ -8,7 +8,7 @@ import { BaseController } from "@lib/controllers/controller.base";
8
  import { Controller } from "@lib/decorators/controller.decorator";
9
  import { serialize } from "@helpers/serialize";
10
  import { UserRegisteredWorkoutsSerialization } from "@common/serializers/user-registered-workout.serialization";
11
- import { UserRegisteredMealPlansPopulateSerialization, UserRegisteredMealPlansPopulateUserSerialization } from "@common/serializers/user-registered-meal-planPopulate.serialization";
12
  import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
13
  import { UsersGuardMiddleware } from "modules/users/common/guards/users.guard";
14
  import { createUserRegisteredWorkoutsSchema } from "../validations/create-user-registered-workouts.validation";
@@ -47,7 +47,7 @@ export class userRegisteredWorkoutsController extends BaseController {
47
  }
48
 
49
  @SwaggerGet()
50
- @SwaggerResponse([UserRegisteredMealPlansPopulateSerialization])
51
  @SwaggerSummary("List my workouts")
52
  @SwaggerDescription("List all user registered workouts (workouts that the user had started)")
53
  list = async (req: userRequest, res: Response) => {
@@ -66,7 +66,7 @@ export class userRegisteredWorkoutsController extends BaseController {
66
 
67
  return JsonResponse.success(
68
  {
69
- data: serialize(docs, UserRegisteredMealPlansPopulateSerialization),
70
  meta: paginationData,
71
  },
72
  res
@@ -74,7 +74,7 @@ export class userRegisteredWorkoutsController extends BaseController {
74
  };
75
 
76
  @SwaggerGet("/:id")
77
- @SwaggerResponse(UserRegisteredMealPlansPopulateSerialization)
78
  @SwaggerSummary("Get a workout")
79
  @SwaggerDescription("Get a single workout from user registered workouts (workouts that the user had started)")
80
  get = async (req: userRequest, res: Response) => {
@@ -89,18 +89,17 @@ export class userRegisteredWorkoutsController extends BaseController {
89
  );
90
  return JsonResponse.success(
91
  {
92
- data: serialize(data.toJSON(), UserRegisteredMealPlansPopulateSerialization),
93
  },
94
  res
95
  );
96
  };
97
 
98
  @SwaggerGet("/home/:userId")
99
- @SwaggerResponse(UserRegisteredMealPlansPopulateUserSerialization)
100
  @SwaggerSummary("Get home page")
101
  @SwaggerDescription("Get the home page for the user")
102
  getHomePage = async (req: userRequest, res: Response) => {
103
- console.log(req.params);
104
 
105
  const data = await this.userRegisteredWorkoutsService.findOneOrFail(
106
  { user: req.params.userId },
@@ -114,7 +113,7 @@ export class userRegisteredWorkoutsController extends BaseController {
114
  );
115
  return JsonResponse.success(
116
  {
117
- data: serialize(data.toJSON(), UserRegisteredMealPlansPopulateUserSerialization),
118
  },
119
  res
120
  );
 
8
  import { Controller } from "@lib/decorators/controller.decorator";
9
  import { serialize } from "@helpers/serialize";
10
  import { UserRegisteredWorkoutsSerialization } from "@common/serializers/user-registered-workout.serialization";
11
+ import { UserRegisteredWorkoutsPopulateSerialization, UserRegisteredWorkoutsPopulateUserSerialization } from "@common/serializers/user-registered-workoutPopulate.serialization";
12
  import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
13
  import { UsersGuardMiddleware } from "modules/users/common/guards/users.guard";
14
  import { createUserRegisteredWorkoutsSchema } from "../validations/create-user-registered-workouts.validation";
 
47
  }
48
 
49
  @SwaggerGet()
50
+ @SwaggerResponse([UserRegisteredWorkoutsPopulateSerialization])
51
  @SwaggerSummary("List my workouts")
52
  @SwaggerDescription("List all user registered workouts (workouts that the user had started)")
53
  list = async (req: userRequest, res: Response) => {
 
66
 
67
  return JsonResponse.success(
68
  {
69
+ data: serialize(docs, UserRegisteredWorkoutsPopulateSerialization),
70
  meta: paginationData,
71
  },
72
  res
 
74
  };
75
 
76
  @SwaggerGet("/:id")
77
+ @SwaggerResponse(UserRegisteredWorkoutsPopulateSerialization)
78
  @SwaggerSummary("Get a workout")
79
  @SwaggerDescription("Get a single workout from user registered workouts (workouts that the user had started)")
80
  get = async (req: userRequest, res: Response) => {
 
89
  );
90
  return JsonResponse.success(
91
  {
92
+ data: serialize(data.toJSON(), UserRegisteredWorkoutsPopulateSerialization),
93
  },
94
  res
95
  );
96
  };
97
 
98
  @SwaggerGet("/home/:userId")
99
+ @SwaggerResponse(UserRegisteredWorkoutsPopulateUserSerialization)
100
  @SwaggerSummary("Get home page")
101
  @SwaggerDescription("Get the home page for the user")
102
  getHomePage = async (req: userRequest, res: Response) => {
 
103
 
104
  const data = await this.userRegisteredWorkoutsService.findOneOrFail(
105
  { user: req.params.userId },
 
113
  );
114
  return JsonResponse.success(
115
  {
116
+ data: serialize(data.toJSON(), UserRegisteredWorkoutsPopulateUserSerialization),
117
  },
118
  res
119
  );