Hozifa Elgharbawy commited on
Commit
66780ff
·
1 Parent(s): bb3dc70

refactor: Update serializers for meal plans and user-registered meal plans

Browse files
src/common/serializers/meal-planPopulate.serialization.ts CHANGED
@@ -97,4 +97,15 @@ export class ListMealPlanSerialization {
97
  )
98
  key_features: any;
99
 
 
 
 
 
 
 
 
 
 
 
 
100
  }
 
97
  )
98
  key_features: any;
99
 
100
+ }
101
+
102
+
103
+ export class MSerialization {
104
+ @Expose({ name: "_id" })
105
+ @SwaggerResponseProperty({ type: "string" })
106
+ id: string;
107
+
108
+ @Expose()
109
+ @SwaggerResponseProperty({ type: "string" })
110
+ image: string;
111
  }
src/common/serializers/user-registered-meal-planPopulate.serialization.ts CHANGED
@@ -1,8 +1,8 @@
1
  import { Expose, Transform } from "class-transformer";
2
  import { serialize } from "@helpers/serialize";
3
  import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
4
- import { ListMealPlanSerialization } from "./meal-planPopulate.serialization";
5
- import { MealSerialization } from "./meal.serialization";
6
  import { MealPlanSerialization } from "./meal-plan.serialization";
7
 
8
 
@@ -13,9 +13,9 @@ class MealDaysPopulate {
13
  day_number: number;
14
 
15
  @Expose({ name: "meals" })
16
- @SwaggerResponseProperty({ type: [MealSerialization] })
17
  @Transform(
18
- ({ value }) => serialize(value, MealSerialization)
19
  )
20
  meals: any;
21
 
@@ -65,7 +65,7 @@ export class GetMyMealPlanSerialization {
65
 
66
  @Expose()
67
  @SwaggerResponseProperty({ type: ListMealPlanSerialization })
68
- meal_plan: string;
69
 
70
  @Expose()
71
  @SwaggerResponseProperty({ type: "boolean" })
 
1
  import { Expose, Transform } from "class-transformer";
2
  import { serialize } from "@helpers/serialize";
3
  import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
4
+ import { ListMealPlanSerialization } from "@common/serializers/meal-planPopulate.serialization";
5
+ import { MealPopulateSerialization } from "./mealPopulate.serialization";
6
  import { MealPlanSerialization } from "./meal-plan.serialization";
7
 
8
 
 
13
  day_number: number;
14
 
15
  @Expose({ name: "meals" })
16
+ @SwaggerResponseProperty({ type: [MealPopulateSerialization] })
17
  @Transform(
18
+ ({ value }) => serialize(value, MealPopulateSerialization)
19
  )
20
  meals: any;
21
 
 
65
 
66
  @Expose()
67
  @SwaggerResponseProperty({ type: ListMealPlanSerialization })
68
+ meal_plan: any;
69
 
70
  @Expose()
71
  @SwaggerResponseProperty({ type: "boolean" })
src/modules/users/modules/home/controllers/home-nutriguide.controller.ts CHANGED
@@ -15,7 +15,7 @@ import { UserHomeService } from "../services/user-home.service";
15
  import { IUserRequest } from "@common/interfaces/user-request.interface";
16
  import { UserHomeYourDailyIntakeSerialization } from "../responses/user-home-your-daily-intake.serialization";
17
  import { UserNutriHomeDailyGoalsSerialization } from "../responses/user-nutri-home-daily-goals.serialization";
18
- import { UserRegisteredMealPlansPopulateSerialization } from "@common/serializers/user-registered-meal-planPopulate.serialization";
19
  import { UserRegisteredMealPlansService } from "../../user-registered-meal-plans/services/user-registered-meal-plans.service";
20
  import { SwaggerRequest } from "@lib/decorators/swagger-request.decorator";
21
 
@@ -37,7 +37,7 @@ export class homeNutriGuideController extends BaseController {
37
  }
38
 
39
  @SwaggerGet("/today-meals")
40
- @SwaggerResponse(UserRegisteredMealPlansPopulateSerialization)
41
  @SwaggerSummary("Get today's meals")
42
  @SwaggerDescription("Get today's meals for the user.")
43
  getTodayMeals = async (req: IUserRequest, res: Response): Promise<Response> => {
@@ -48,11 +48,13 @@ export class homeNutriGuideController extends BaseController {
48
  {
49
  populateArray: [
50
  { path: "meal_plan", select: "-days" },
51
- { path: "days.meals" }
 
 
 
52
  ],
53
  }
54
  );
55
- console.log(data);
56
 
57
 
58
  const dayToEat = data.days.find(day => day.is_eaten === false);
@@ -61,7 +63,7 @@ export class homeNutriGuideController extends BaseController {
61
  data.days = [dayToEat];
62
  return JsonResponse.success(
63
  {
64
- data: serialize(data, UserRegisteredMealPlansPopulateSerialization),
65
  },
66
  res
67
  );
 
15
  import { IUserRequest } from "@common/interfaces/user-request.interface";
16
  import { UserHomeYourDailyIntakeSerialization } from "../responses/user-home-your-daily-intake.serialization";
17
  import { UserNutriHomeDailyGoalsSerialization } from "../responses/user-nutri-home-daily-goals.serialization";
18
+ import { GetMyMealPlanSerialization } from "@common/serializers/user-registered-meal-planPopulate.serialization";
19
  import { UserRegisteredMealPlansService } from "../../user-registered-meal-plans/services/user-registered-meal-plans.service";
20
  import { SwaggerRequest } from "@lib/decorators/swagger-request.decorator";
21
 
 
37
  }
38
 
39
  @SwaggerGet("/today-meals")
40
+ @SwaggerResponse(GetMyMealPlanSerialization)
41
  @SwaggerSummary("Get today's meals")
42
  @SwaggerDescription("Get today's meals for the user.")
43
  getTodayMeals = async (req: IUserRequest, res: Response): Promise<Response> => {
 
48
  {
49
  populateArray: [
50
  { path: "meal_plan", select: "-days" },
51
+ {
52
+ path: "days.meals",
53
+ populate: { path: "ingredients" }
54
+ }
55
  ],
56
  }
57
  );
 
58
 
59
 
60
  const dayToEat = data.days.find(day => day.is_eaten === false);
 
63
  data.days = [dayToEat];
64
  return JsonResponse.success(
65
  {
66
+ data: serialize(data, GetMyMealPlanSerialization),
67
  },
68
  res
69
  );
src/modules/users/modules/user-registered-meal-plans/controller/user-registered-meal-plans.controller.ts CHANGED
@@ -34,8 +34,8 @@ export class UsersRegisteredMealPlansController extends BaseController {
34
  { user: req.jwtPayload.id, isActive: true },
35
  {
36
  populateArray: [
37
- { path: "meal_plan", select: "-days"},
38
- { path: "days.meals"}
39
  ],
40
  });
41
 
 
34
  { user: req.jwtPayload.id, isActive: true },
35
  {
36
  populateArray: [
37
+ { path: "meal_plan", select: "-days" },
38
+ { path: "days.meals", populate: { path: "ingredients" } }
39
  ],
40
  });
41