Spaces:
Running
Running
Merge pull request #65 from Modarb-Ai-Trainer:mealFlow
Browse filesAdd new services and controller for meals, meal plans, and ingredients
- src/common/serializers/exercise.serialization.ts +2 -2
- src/common/serializers/meal-plan.serialization.ts +9 -9
- src/common/serializers/meal.serialization.ts +3 -2
- src/common/serializers/user-registered-meal-plan.serialization.ts +4 -4
- src/common/serializers/user-registered-workout.serialization.ts +6 -6
- src/common/serializers/workout.serialization.ts +6 -6
- src/lib/swagger/swagger.ts +1 -1
- src/modules/console/modules/ingredients/controller/ingredients.controller.ts +116 -0
- src/modules/console/modules/ingredients/services/ingredients.service.ts +4 -0
- src/modules/console/modules/meal-plans/controller/meal-plans.controller.ts +116 -0
- src/modules/console/modules/meal-plans/services/meal-plans.service.ts +4 -0
- src/modules/console/modules/meals/controller/meals.controller.ts +116 -0
- src/modules/console/modules/meals/services/meals.service.ts +4 -0
- src/modules/users/modules/ingredients/controller/ingredients.controller.ts +47 -0
- src/modules/users/modules/ingredients/services/ingredients.service.ts +4 -0
- src/modules/users/modules/meal-plans/controller/meals.controller.ts +51 -0
- src/modules/users/modules/meal-plans/services/meal-plans.service.ts +4 -0
- src/modules/users/modules/meals/controller/meals.controller.ts +50 -0
- src/modules/users/modules/meals/services/meals.service.ts +4 -0
- src/modules/users/modules/user-registered-meal-plans/controller/user-registered-meal-plans.controller.ts +51 -0
- src/modules/users/modules/user-registered-meal-plans/services/user-registered-meal-plans.service.ts +4 -0
src/common/serializers/exercise.serialization.ts
CHANGED
@@ -40,7 +40,7 @@ export class ExerciseSerialization {
|
|
40 |
duration: number | null;
|
41 |
|
42 |
@Expose({ name: "expectedDurationRange" })
|
43 |
-
@SwaggerResponseProperty({ type:
|
44 |
@Transform(({ value }) => serialize(value, ExpectedDurationRange))
|
45 |
expectedDurationRange: object;
|
46 |
|
@@ -69,7 +69,7 @@ export class ExerciseSerialization {
|
|
69 |
equipments: any;
|
70 |
|
71 |
@Expose({ name: "media" })
|
72 |
-
@SwaggerResponseProperty({ type:
|
73 |
@Transform(({ value }) => serialize(value, Media))
|
74 |
media: object;
|
75 |
}
|
|
|
40 |
duration: number | null;
|
41 |
|
42 |
@Expose({ name: "expectedDurationRange" })
|
43 |
+
@SwaggerResponseProperty({ type: ExpectedDurationRange })
|
44 |
@Transform(({ value }) => serialize(value, ExpectedDurationRange))
|
45 |
expectedDurationRange: object;
|
46 |
|
|
|
69 |
equipments: any;
|
70 |
|
71 |
@Expose({ name: "media" })
|
72 |
+
@SwaggerResponseProperty({ type: Media })
|
73 |
@Transform(({ value }) => serialize(value, Media))
|
74 |
media: object;
|
75 |
}
|
src/common/serializers/meal-plan.serialization.ts
CHANGED
@@ -3,17 +3,17 @@ import { serialize } from "@helpers/serialize";
|
|
3 |
import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
|
4 |
|
5 |
|
6 |
-
class
|
7 |
@Expose()
|
8 |
@SwaggerResponseProperty({ type: "string" })
|
9 |
title: string;
|
10 |
|
11 |
@Expose({ name: "meals" })
|
12 |
-
@SwaggerResponseProperty({ type:
|
13 |
-
meals:
|
14 |
}
|
15 |
|
16 |
-
class
|
17 |
@Expose()
|
18 |
@SwaggerResponseProperty({ type: "number" })
|
19 |
day_number: number;
|
@@ -23,7 +23,7 @@ class KeyFeatures {
|
|
23 |
description: any;
|
24 |
}
|
25 |
|
26 |
-
export class
|
27 |
@Expose({ name: "_id" })
|
28 |
@SwaggerResponseProperty({ type: "string" })
|
29 |
id: string;
|
@@ -49,16 +49,16 @@ export class WorkoutSerialization {
|
|
49 |
your_Journey: string;
|
50 |
|
51 |
@Expose({ name: "key_Features" })
|
52 |
-
@SwaggerResponseProperty({ type: [
|
53 |
@Transform(
|
54 |
-
({ value }) => serialize(value,
|
55 |
)
|
56 |
key_Features: any;
|
57 |
|
58 |
@Expose({ name: "days" })
|
59 |
-
@SwaggerResponseProperty({ type: [
|
60 |
@Transform(
|
61 |
-
({ value }) => serialize(value,
|
62 |
)
|
63 |
days: any;
|
64 |
|
|
|
3 |
import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
|
4 |
|
5 |
|
6 |
+
class MealPlanDays {
|
7 |
@Expose()
|
8 |
@SwaggerResponseProperty({ type: "string" })
|
9 |
title: string;
|
10 |
|
11 |
@Expose({ name: "meals" })
|
12 |
+
@SwaggerResponseProperty({ type: {} })
|
13 |
+
meals: any;
|
14 |
}
|
15 |
|
16 |
+
class MealPlanKeyFeatures {
|
17 |
@Expose()
|
18 |
@SwaggerResponseProperty({ type: "number" })
|
19 |
day_number: number;
|
|
|
23 |
description: any;
|
24 |
}
|
25 |
|
26 |
+
export class MealPlanSerialization {
|
27 |
@Expose({ name: "_id" })
|
28 |
@SwaggerResponseProperty({ type: "string" })
|
29 |
id: string;
|
|
|
49 |
your_Journey: string;
|
50 |
|
51 |
@Expose({ name: "key_Features" })
|
52 |
+
@SwaggerResponseProperty({ type: [MealPlanKeyFeatures] })
|
53 |
@Transform(
|
54 |
+
({ value }) => serialize(value, MealPlanKeyFeatures)
|
55 |
)
|
56 |
key_Features: any;
|
57 |
|
58 |
@Expose({ name: "days" })
|
59 |
+
@SwaggerResponseProperty({ type: [MealPlanDays] })
|
60 |
@Transform(
|
61 |
+
({ value }) => serialize(value, MealPlanDays)
|
62 |
)
|
63 |
days: any;
|
64 |
|
src/common/serializers/meal.serialization.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import { Expose } from "class-transformer";
|
2 |
import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
|
|
|
3 |
|
4 |
|
5 |
export class MealSerialization {
|
@@ -12,8 +13,8 @@ export class MealSerialization {
|
|
12 |
created_at: Date;
|
13 |
|
14 |
@Expose()
|
15 |
-
@SwaggerResponseProperty({ type:
|
16 |
-
ingredients:
|
17 |
|
18 |
@Expose()
|
19 |
@SwaggerResponseProperty({ type: "number" })
|
|
|
1 |
import { Expose } from "class-transformer";
|
2 |
import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
|
3 |
+
import { IngredientSerialization } from "./ingredient.serialization";
|
4 |
|
5 |
|
6 |
export class MealSerialization {
|
|
|
13 |
created_at: Date;
|
14 |
|
15 |
@Expose()
|
16 |
+
@SwaggerResponseProperty({ type: [IngredientSerialization] })
|
17 |
+
ingredients: any;
|
18 |
|
19 |
@Expose()
|
20 |
@SwaggerResponseProperty({ type: "number" })
|
src/common/serializers/user-registered-meal-plan.serialization.ts
CHANGED
@@ -4,7 +4,7 @@ import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-proper
|
|
4 |
|
5 |
|
6 |
|
7 |
-
class
|
8 |
@Expose()
|
9 |
@SwaggerResponseProperty({ type: "number" })
|
10 |
day_number: number;
|
@@ -19,7 +19,7 @@ class Days {
|
|
19 |
|
20 |
}
|
21 |
|
22 |
-
export class
|
23 |
@Expose({ name: "_id" })
|
24 |
@SwaggerResponseProperty({ type: "string" })
|
25 |
id: string;
|
@@ -37,9 +37,9 @@ export class WorkoutSerialization {
|
|
37 |
isActive: boolean;
|
38 |
|
39 |
@Expose({ name: "days" })
|
40 |
-
@SwaggerResponseProperty({ type: [
|
41 |
@Transform(
|
42 |
-
({ value }) => serialize(value,
|
43 |
)
|
44 |
days: any;
|
45 |
|
|
|
4 |
|
5 |
|
6 |
|
7 |
+
class MealDays {
|
8 |
@Expose()
|
9 |
@SwaggerResponseProperty({ type: "number" })
|
10 |
day_number: number;
|
|
|
19 |
|
20 |
}
|
21 |
|
22 |
+
export class UserRegisteredMealPlansSerialization {
|
23 |
@Expose({ name: "_id" })
|
24 |
@SwaggerResponseProperty({ type: "string" })
|
25 |
id: string;
|
|
|
37 |
isActive: boolean;
|
38 |
|
39 |
@Expose({ name: "days" })
|
40 |
+
@SwaggerResponseProperty({ type: [MealDays] })
|
41 |
@Transform(
|
42 |
+
({ value }) => serialize(value, MealDays)
|
43 |
)
|
44 |
days: any;
|
45 |
|
src/common/serializers/user-registered-workout.serialization.ts
CHANGED
@@ -3,7 +3,7 @@ import { serialize } from "@helpers/serialize";
|
|
3 |
import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
|
4 |
import { ExerciseSerialization } from "./exercise.serialization";
|
5 |
|
6 |
-
class
|
7 |
@Expose()
|
8 |
@SwaggerResponseProperty({ type: "number" })
|
9 |
day_number: number;
|
@@ -25,7 +25,7 @@ class Days {
|
|
25 |
is_done: Boolean;
|
26 |
}
|
27 |
|
28 |
-
class
|
29 |
@Expose()
|
30 |
@SwaggerResponseProperty({ type: "number" })
|
31 |
week_number: number;
|
@@ -39,8 +39,8 @@ class Weeks {
|
|
39 |
week_description: string;
|
40 |
|
41 |
@Expose({ name: "days" })
|
42 |
-
@SwaggerResponseProperty({ type: [
|
43 |
-
@Transform(({ value }) => serialize(value,
|
44 |
days: any;
|
45 |
|
46 |
@Expose()
|
@@ -66,7 +66,7 @@ export class UserRegisteredWorkoutsSerialization {
|
|
66 |
is_active: Boolean;
|
67 |
|
68 |
@Expose({ name: "weeks" })
|
69 |
-
@SwaggerResponseProperty({ type: [
|
70 |
-
@Transform(({ value }) => serialize(value,
|
71 |
weeks: any;
|
72 |
}
|
|
|
3 |
import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
|
4 |
import { ExerciseSerialization } from "./exercise.serialization";
|
5 |
|
6 |
+
class MyWorkoutDays {
|
7 |
@Expose()
|
8 |
@SwaggerResponseProperty({ type: "number" })
|
9 |
day_number: number;
|
|
|
25 |
is_done: Boolean;
|
26 |
}
|
27 |
|
28 |
+
class MyWorkoutWeeks {
|
29 |
@Expose()
|
30 |
@SwaggerResponseProperty({ type: "number" })
|
31 |
week_number: number;
|
|
|
39 |
week_description: string;
|
40 |
|
41 |
@Expose({ name: "days" })
|
42 |
+
@SwaggerResponseProperty({ type: [MyWorkoutDays] })
|
43 |
+
@Transform(({ value }) => serialize(value, MyWorkoutDays))
|
44 |
days: any;
|
45 |
|
46 |
@Expose()
|
|
|
66 |
is_active: Boolean;
|
67 |
|
68 |
@Expose({ name: "weeks" })
|
69 |
+
@SwaggerResponseProperty({ type: [MyWorkoutWeeks] })
|
70 |
+
@Transform(({ value }) => serialize(value, MyWorkoutWeeks))
|
71 |
weeks: any;
|
72 |
}
|
src/common/serializers/workout.serialization.ts
CHANGED
@@ -4,7 +4,7 @@ import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-proper
|
|
4 |
|
5 |
|
6 |
|
7 |
-
class
|
8 |
@Expose()
|
9 |
@SwaggerResponseProperty({ type: "number" })
|
10 |
day_number: number;
|
@@ -22,7 +22,7 @@ class Days {
|
|
22 |
exercises: any;
|
23 |
}
|
24 |
|
25 |
-
class
|
26 |
@Expose()
|
27 |
@SwaggerResponseProperty({ type: "number" })
|
28 |
week_number: number;
|
@@ -36,9 +36,9 @@ class TemplateWeeks {
|
|
36 |
week_description: string;
|
37 |
|
38 |
@Expose({ name: "days" })
|
39 |
-
@SwaggerResponseProperty({ type: [
|
40 |
@Transform(
|
41 |
-
({ value }) => serialize(value,
|
42 |
)
|
43 |
days: any;
|
44 |
}
|
@@ -89,9 +89,9 @@ export class WorkoutSerialization {
|
|
89 |
total_number_days: number;
|
90 |
|
91 |
@Expose({ name: "template_weeks" })
|
92 |
-
@SwaggerResponseProperty({ type: [
|
93 |
@Transform(
|
94 |
-
({ value }) => serialize(value,
|
95 |
)
|
96 |
template_weeks: any;
|
97 |
|
|
|
4 |
|
5 |
|
6 |
|
7 |
+
class WorkoutDays {
|
8 |
@Expose()
|
9 |
@SwaggerResponseProperty({ type: "number" })
|
10 |
day_number: number;
|
|
|
22 |
exercises: any;
|
23 |
}
|
24 |
|
25 |
+
class WorkoutTemplateWeeks {
|
26 |
@Expose()
|
27 |
@SwaggerResponseProperty({ type: "number" })
|
28 |
week_number: number;
|
|
|
36 |
week_description: string;
|
37 |
|
38 |
@Expose({ name: "days" })
|
39 |
+
@SwaggerResponseProperty({ type: [WorkoutDays] })
|
40 |
@Transform(
|
41 |
+
({ value }) => serialize(value, WorkoutDays)
|
42 |
)
|
43 |
days: any;
|
44 |
}
|
|
|
89 |
total_number_days: number;
|
90 |
|
91 |
@Expose({ name: "template_weeks" })
|
92 |
+
@SwaggerResponseProperty({ type: [WorkoutTemplateWeeks] })
|
93 |
@Transform(
|
94 |
+
({ value }) => serialize(value, WorkoutTemplateWeeks)
|
95 |
)
|
96 |
template_weeks: any;
|
97 |
|
src/lib/swagger/swagger.ts
CHANGED
@@ -204,7 +204,7 @@ class SwaggerRegistry {
|
|
204 |
},
|
205 |
};
|
206 |
|
207 |
-
console.log(JSON.stringify(document, null, 2));
|
208 |
return document;
|
209 |
}
|
210 |
}
|
|
|
204 |
},
|
205 |
};
|
206 |
|
207 |
+
// console.log(JSON.stringify(document, null, 2));
|
208 |
return document;
|
209 |
}
|
210 |
}
|
src/modules/console/modules/ingredients/controller/ingredients.controller.ts
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Request, Response } from "express";
|
2 |
+
import { JsonResponse } from "@lib/responses/json-response";
|
3 |
+
import { parsePaginationQuery } from "@helpers/pagination";
|
4 |
+
import { asyncHandler } from "@helpers/async-handler";
|
5 |
+
import { paramsValidator, bodyValidator } from "@helpers/validation.helper";
|
6 |
+
import { BaseController } from "@lib/controllers/controller.base";
|
7 |
+
import { Controller } from "@lib/decorators/controller.decorator";
|
8 |
+
import { serialize } from "@helpers/serialize";
|
9 |
+
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
10 |
+
import { AdminGuardMiddleware } from "modules/console/common/guards/admins.guard";
|
11 |
+
import { IngredientsService } from "../services/ingredients.service";
|
12 |
+
import { createIngredientsSchema } from "../validations/create-ingredient.validation";
|
13 |
+
import { updateIngredientsSchema } from "../validations/update-ingredient.validation";
|
14 |
+
import { IngredientSerialization } from "@common/serializers/ingredient.serialization";
|
15 |
+
import { SwaggerRequest } from "@lib/decorators/swagger-request.decorator";
|
16 |
+
import { SwaggerResponse } from "@lib/decorators/swagger-response.decorator";
|
17 |
+
import { SwaggerGet, SwaggerPost, SwaggerPatch, SwaggerDelete } from "@lib/decorators/swagger-routes.decorator";
|
18 |
+
|
19 |
+
@Controller("/console/ingredients")
|
20 |
+
@ControllerMiddleware(AdminGuardMiddleware({}))
|
21 |
+
export class AdminsIngredientsController extends BaseController {
|
22 |
+
private ingredientsService = new IngredientsService();
|
23 |
+
|
24 |
+
setRoutes() {
|
25 |
+
this.router.get("/", asyncHandler(this.list));
|
26 |
+
this.router.get("/:id", paramsValidator("id"), asyncHandler(this.get));
|
27 |
+
this.router.post("/",
|
28 |
+
bodyValidator(createIngredientsSchema),
|
29 |
+
asyncHandler(this.create));
|
30 |
+
this.router.patch(
|
31 |
+
"/:id",
|
32 |
+
paramsValidator("id"),
|
33 |
+
bodyValidator(updateIngredientsSchema),
|
34 |
+
asyncHandler(this.update)
|
35 |
+
);
|
36 |
+
this.router.delete(
|
37 |
+
"/:id",
|
38 |
+
paramsValidator("id"),
|
39 |
+
asyncHandler(this.delete)
|
40 |
+
);
|
41 |
+
}
|
42 |
+
|
43 |
+
@SwaggerGet()
|
44 |
+
@SwaggerResponse([IngredientSerialization])
|
45 |
+
list = async (req: Request, res: Response) => {
|
46 |
+
const paginationQuery = parsePaginationQuery(req.query);
|
47 |
+
const { docs, paginationData } = await this.ingredientsService.list(
|
48 |
+
{},
|
49 |
+
paginationQuery
|
50 |
+
);
|
51 |
+
|
52 |
+
return JsonResponse.success(
|
53 |
+
{
|
54 |
+
data: serialize(docs, IngredientSerialization),
|
55 |
+
meta: paginationData,
|
56 |
+
},
|
57 |
+
res
|
58 |
+
);
|
59 |
+
};
|
60 |
+
|
61 |
+
@SwaggerGet('/:id')
|
62 |
+
@SwaggerResponse(IngredientSerialization)
|
63 |
+
get = async (req: Request, res: Response) => {
|
64 |
+
const data = await this.ingredientsService.findOneOrFail({
|
65 |
+
_id: req.params.id,
|
66 |
+
});
|
67 |
+
return JsonResponse.success(
|
68 |
+
{
|
69 |
+
data: serialize(data.toJSON(), IngredientSerialization),
|
70 |
+
},
|
71 |
+
res
|
72 |
+
);
|
73 |
+
};
|
74 |
+
|
75 |
+
@SwaggerPost()
|
76 |
+
@SwaggerRequest(createIngredientsSchema)
|
77 |
+
@SwaggerResponse(IngredientSerialization)
|
78 |
+
create = async (req: Request, res: Response) => {
|
79 |
+
const data = await this.ingredientsService.create(req.body);
|
80 |
+
return JsonResponse.success(
|
81 |
+
{
|
82 |
+
status: 201,
|
83 |
+
data: serialize(data.toJSON(), IngredientSerialization),
|
84 |
+
},
|
85 |
+
res
|
86 |
+
);
|
87 |
+
};
|
88 |
+
|
89 |
+
@SwaggerPatch('/:id')
|
90 |
+
@SwaggerRequest(updateIngredientsSchema)
|
91 |
+
@SwaggerResponse(IngredientSerialization)
|
92 |
+
update = async (req: Request, res: Response) => {
|
93 |
+
const data = await this.ingredientsService.updateOne(
|
94 |
+
{ _id: req.params.id },
|
95 |
+
req.body
|
96 |
+
);
|
97 |
+
return JsonResponse.success(
|
98 |
+
{
|
99 |
+
data: serialize(data.toJSON(), IngredientSerialization),
|
100 |
+
},
|
101 |
+
res
|
102 |
+
);
|
103 |
+
};
|
104 |
+
|
105 |
+
@SwaggerDelete('/:id')
|
106 |
+
@SwaggerResponse(IngredientSerialization)
|
107 |
+
delete = async (req: Request, res: Response) => {
|
108 |
+
const data = await this.ingredientsService.deleteOne({ _id: req.params.id });
|
109 |
+
return JsonResponse.success(
|
110 |
+
{
|
111 |
+
data: serialize(data.toJSON(), IngredientSerialization),
|
112 |
+
},
|
113 |
+
res
|
114 |
+
);
|
115 |
+
};
|
116 |
+
};
|
src/modules/console/modules/ingredients/services/ingredients.service.ts
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Ingredient } from "@common/models/ingredient.model";
|
2 |
+
import { CrudService } from "@lib/services/crud.service";
|
3 |
+
|
4 |
+
export class IngredientsService extends CrudService(Ingredient) {}
|
src/modules/console/modules/meal-plans/controller/meal-plans.controller.ts
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Request, Response } from "express";
|
2 |
+
import { JsonResponse } from "@lib/responses/json-response";
|
3 |
+
import { parsePaginationQuery } from "@helpers/pagination";
|
4 |
+
import { asyncHandler } from "@helpers/async-handler";
|
5 |
+
import { paramsValidator, bodyValidator } from "@helpers/validation.helper";
|
6 |
+
import { BaseController } from "@lib/controllers/controller.base";
|
7 |
+
import { Controller } from "@lib/decorators/controller.decorator";
|
8 |
+
import { serialize } from "@helpers/serialize";
|
9 |
+
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
10 |
+
import { AdminGuardMiddleware } from "modules/console/common/guards/admins.guard";
|
11 |
+
import { MealPlansService } from "../services/meal-plans.service";
|
12 |
+
import { CreateMealPlan } from "../validations/create-meal-plan.validation";
|
13 |
+
import { UpdateMealPlan } from "../validations/update-meal-plan.validation";
|
14 |
+
import { MealPlanSerialization } from "@common/serializers/meal-plan.serialization";
|
15 |
+
import { SwaggerRequest } from "@lib/decorators/swagger-request.decorator";
|
16 |
+
import { SwaggerResponse } from "@lib/decorators/swagger-response.decorator";
|
17 |
+
import { SwaggerGet, SwaggerPost, SwaggerPatch, SwaggerDelete } from "@lib/decorators/swagger-routes.decorator";
|
18 |
+
|
19 |
+
@Controller("/console/mealPlans")
|
20 |
+
@ControllerMiddleware(AdminGuardMiddleware({}))
|
21 |
+
export class AdminsMealPlansController extends BaseController {
|
22 |
+
private mealPlansService = new MealPlansService();
|
23 |
+
|
24 |
+
setRoutes() {
|
25 |
+
this.router.get("/", asyncHandler(this.list));
|
26 |
+
this.router.get("/:id", paramsValidator("id"), asyncHandler(this.get));
|
27 |
+
this.router.post("/",
|
28 |
+
bodyValidator(CreateMealPlan),
|
29 |
+
asyncHandler(this.create));
|
30 |
+
this.router.patch(
|
31 |
+
"/:id",
|
32 |
+
paramsValidator("id"),
|
33 |
+
bodyValidator(UpdateMealPlan),
|
34 |
+
asyncHandler(this.update)
|
35 |
+
);
|
36 |
+
this.router.delete(
|
37 |
+
"/:id",
|
38 |
+
paramsValidator("id"),
|
39 |
+
asyncHandler(this.delete)
|
40 |
+
);
|
41 |
+
}
|
42 |
+
|
43 |
+
@SwaggerGet()
|
44 |
+
@SwaggerResponse([MealPlanSerialization])
|
45 |
+
list = async (req: Request, res: Response) => {
|
46 |
+
const paginationQuery = parsePaginationQuery(req.query);
|
47 |
+
const { docs, paginationData } = await this.mealPlansService.list(
|
48 |
+
{},
|
49 |
+
paginationQuery
|
50 |
+
);
|
51 |
+
|
52 |
+
return JsonResponse.success(
|
53 |
+
{
|
54 |
+
data: serialize(docs, MealPlanSerialization),
|
55 |
+
meta: paginationData,
|
56 |
+
},
|
57 |
+
res
|
58 |
+
);
|
59 |
+
};
|
60 |
+
|
61 |
+
@SwaggerGet('/:id')
|
62 |
+
@SwaggerResponse(MealPlanSerialization)
|
63 |
+
get = async (req: Request, res: Response) => {
|
64 |
+
const data = await this.mealPlansService.findOneOrFail({
|
65 |
+
_id: req.params.id,
|
66 |
+
});
|
67 |
+
return JsonResponse.success(
|
68 |
+
{
|
69 |
+
data: serialize(data.toJSON(), MealPlanSerialization),
|
70 |
+
},
|
71 |
+
res
|
72 |
+
);
|
73 |
+
};
|
74 |
+
|
75 |
+
@SwaggerPost()
|
76 |
+
@SwaggerRequest(CreateMealPlan)
|
77 |
+
@SwaggerResponse(MealPlanSerialization)
|
78 |
+
create = async (req: Request, res: Response) => {
|
79 |
+
const data = await this.mealPlansService.create(req.body);
|
80 |
+
return JsonResponse.success(
|
81 |
+
{
|
82 |
+
status: 201,
|
83 |
+
data: serialize(data.toJSON(), MealPlanSerialization),
|
84 |
+
},
|
85 |
+
res
|
86 |
+
);
|
87 |
+
};
|
88 |
+
|
89 |
+
@SwaggerPatch('/:id')
|
90 |
+
@SwaggerRequest(UpdateMealPlan)
|
91 |
+
@SwaggerResponse(MealPlanSerialization)
|
92 |
+
update = async (req: Request, res: Response) => {
|
93 |
+
const data = await this.mealPlansService.updateOne(
|
94 |
+
{ _id: req.params.id },
|
95 |
+
req.body
|
96 |
+
);
|
97 |
+
return JsonResponse.success(
|
98 |
+
{
|
99 |
+
data: serialize(data.toJSON(), MealPlanSerialization),
|
100 |
+
},
|
101 |
+
res
|
102 |
+
);
|
103 |
+
};
|
104 |
+
|
105 |
+
@SwaggerDelete('/:id')
|
106 |
+
@SwaggerResponse(MealPlanSerialization)
|
107 |
+
delete = async (req: Request, res: Response) => {
|
108 |
+
const data = await this.mealPlansService.deleteOne({ _id: req.params.id });
|
109 |
+
return JsonResponse.success(
|
110 |
+
{
|
111 |
+
data: serialize(data.toJSON(), MealPlanSerialization),
|
112 |
+
},
|
113 |
+
res
|
114 |
+
);
|
115 |
+
};
|
116 |
+
};
|
src/modules/console/modules/meal-plans/services/meal-plans.service.ts
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { MealPlan } from "@common/models/meal-plan.model";
|
2 |
+
import { CrudService } from "@lib/services/crud.service";
|
3 |
+
|
4 |
+
export class MealPlansService extends CrudService(MealPlan) {}
|
src/modules/console/modules/meals/controller/meals.controller.ts
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Request, Response } from "express";
|
2 |
+
import { JsonResponse } from "@lib/responses/json-response";
|
3 |
+
import { parsePaginationQuery } from "@helpers/pagination";
|
4 |
+
import { asyncHandler } from "@helpers/async-handler";
|
5 |
+
import { paramsValidator, bodyValidator } from "@helpers/validation.helper";
|
6 |
+
import { BaseController } from "@lib/controllers/controller.base";
|
7 |
+
import { Controller } from "@lib/decorators/controller.decorator";
|
8 |
+
import { serialize } from "@helpers/serialize";
|
9 |
+
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
10 |
+
import { AdminGuardMiddleware } from "modules/console/common/guards/admins.guard";
|
11 |
+
import { MealsService } from "../services/meals.service";
|
12 |
+
import { createMealSchema } from "../validations/create-meals.validation";
|
13 |
+
import { updateMealSchema } from "../validations/update-meals.validation";
|
14 |
+
import { MealSerialization } from "@common/serializers/meal.serialization";
|
15 |
+
import { SwaggerRequest } from "@lib/decorators/swagger-request.decorator";
|
16 |
+
import { SwaggerResponse } from "@lib/decorators/swagger-response.decorator";
|
17 |
+
import { SwaggerGet, SwaggerPost, SwaggerPatch, SwaggerDelete } from "@lib/decorators/swagger-routes.decorator";
|
18 |
+
|
19 |
+
@Controller("/console/meals")
|
20 |
+
@ControllerMiddleware(AdminGuardMiddleware({}))
|
21 |
+
export class AdminsMealsController extends BaseController {
|
22 |
+
private mealsService = new MealsService();
|
23 |
+
|
24 |
+
setRoutes() {
|
25 |
+
this.router.get("/", asyncHandler(this.list));
|
26 |
+
this.router.get("/:id", paramsValidator("id"), asyncHandler(this.get));
|
27 |
+
this.router.post("/",
|
28 |
+
bodyValidator(createMealSchema),
|
29 |
+
asyncHandler(this.create));
|
30 |
+
this.router.patch(
|
31 |
+
"/:id",
|
32 |
+
paramsValidator("id"),
|
33 |
+
bodyValidator(updateMealSchema),
|
34 |
+
asyncHandler(this.update)
|
35 |
+
);
|
36 |
+
this.router.delete(
|
37 |
+
"/:id",
|
38 |
+
paramsValidator("id"),
|
39 |
+
asyncHandler(this.delete)
|
40 |
+
);
|
41 |
+
}
|
42 |
+
|
43 |
+
@SwaggerGet()
|
44 |
+
@SwaggerResponse([MealSerialization])
|
45 |
+
list = async (req: Request, res: Response) => {
|
46 |
+
const paginationQuery = parsePaginationQuery(req.query);
|
47 |
+
const { docs, paginationData } = await this.mealsService.list(
|
48 |
+
{},
|
49 |
+
paginationQuery
|
50 |
+
);
|
51 |
+
|
52 |
+
return JsonResponse.success(
|
53 |
+
{
|
54 |
+
data: serialize(docs, MealSerialization),
|
55 |
+
meta: paginationData,
|
56 |
+
},
|
57 |
+
res
|
58 |
+
);
|
59 |
+
};
|
60 |
+
|
61 |
+
@SwaggerGet('/:id')
|
62 |
+
@SwaggerResponse(MealSerialization)
|
63 |
+
get = async (req: Request, res: Response) => {
|
64 |
+
const data = await this.mealsService.findOneOrFail({
|
65 |
+
_id: req.params.id,
|
66 |
+
});
|
67 |
+
return JsonResponse.success(
|
68 |
+
{
|
69 |
+
data: serialize(data.toJSON(), MealSerialization),
|
70 |
+
},
|
71 |
+
res
|
72 |
+
);
|
73 |
+
};
|
74 |
+
|
75 |
+
@SwaggerPost()
|
76 |
+
@SwaggerRequest(createMealSchema)
|
77 |
+
@SwaggerResponse(MealSerialization)
|
78 |
+
create = async (req: Request, res: Response) => {
|
79 |
+
const data = await this.mealsService.create(req.body);
|
80 |
+
return JsonResponse.success(
|
81 |
+
{
|
82 |
+
status: 201,
|
83 |
+
data: serialize(data.toJSON(), MealSerialization),
|
84 |
+
},
|
85 |
+
res
|
86 |
+
);
|
87 |
+
};
|
88 |
+
|
89 |
+
@SwaggerPatch('/:id')
|
90 |
+
@SwaggerRequest(updateMealSchema)
|
91 |
+
@SwaggerResponse(MealSerialization)
|
92 |
+
update = async (req: Request, res: Response) => {
|
93 |
+
const data = await this.mealsService.updateOne(
|
94 |
+
{ _id: req.params.id },
|
95 |
+
req.body
|
96 |
+
);
|
97 |
+
return JsonResponse.success(
|
98 |
+
{
|
99 |
+
data: serialize(data.toJSON(), MealSerialization),
|
100 |
+
},
|
101 |
+
res
|
102 |
+
);
|
103 |
+
};
|
104 |
+
|
105 |
+
@SwaggerDelete('/:id')
|
106 |
+
@SwaggerResponse(MealSerialization)
|
107 |
+
delete = async (req: Request, res: Response) => {
|
108 |
+
const data = await this.mealsService.deleteOne({ _id: req.params.id });
|
109 |
+
return JsonResponse.success(
|
110 |
+
{
|
111 |
+
data: serialize(data.toJSON(), MealSerialization),
|
112 |
+
},
|
113 |
+
res
|
114 |
+
);
|
115 |
+
};
|
116 |
+
};
|
src/modules/console/modules/meals/services/meals.service.ts
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Meal } from "@common/models/meal.model";
|
2 |
+
import { CrudService } from "@lib/services/crud.service";
|
3 |
+
|
4 |
+
export class MealsService extends CrudService(Meal) {}
|
src/modules/users/modules/ingredients/controller/ingredients.controller.ts
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { IngredientsService } from "../services/ingredients.service";
|
2 |
+
import { IngredientSerialization } from "@common/serializers/ingredient.serialization";
|
3 |
+
import { Request, Response } from "express";
|
4 |
+
import { JsonResponse } from "@lib/responses/json-response";
|
5 |
+
import { parsePaginationQuery } from "@helpers/pagination";
|
6 |
+
import { asyncHandler } from "@helpers/async-handler";
|
7 |
+
import { paramsValidator } from "@helpers/validation.helper";
|
8 |
+
import { BaseController } from "@lib/controllers/controller.base";
|
9 |
+
import { Controller } from "@lib/decorators/controller.decorator";
|
10 |
+
import { serialize } from "@helpers/serialize";
|
11 |
+
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
12 |
+
import { UsersGuardMiddleware } from "modules/users/common/guards/users.guard";
|
13 |
+
import { SwaggerGet } from "@lib/decorators/swagger-routes.decorator";
|
14 |
+
import { SwaggerResponse } from "@lib/decorators/swagger-response.decorator";
|
15 |
+
import { SwaggerSummary } from "@lib/decorators/swagger-summary.decorator";
|
16 |
+
import { SwaggerDescription } from "@lib/decorators/swagger-description.decorator";
|
17 |
+
|
18 |
+
|
19 |
+
@Controller("/user/ingredients")
|
20 |
+
@ControllerMiddleware(UsersGuardMiddleware())
|
21 |
+
export class UsersIngredientsController extends BaseController {
|
22 |
+
private ingredientsService = new IngredientsService();
|
23 |
+
|
24 |
+
setRoutes(): void {
|
25 |
+
this.router.get("/", asyncHandler(this.list));
|
26 |
+
}
|
27 |
+
|
28 |
+
@SwaggerGet()
|
29 |
+
@SwaggerResponse([IngredientSerialization])
|
30 |
+
@SwaggerSummary("list ingredients")
|
31 |
+
@SwaggerDescription("list ingredients")
|
32 |
+
list = async (req: Request, res: Response) => {
|
33 |
+
const paginationQuery = parsePaginationQuery(req.query);
|
34 |
+
const { docs, paginationData } = await this.ingredientsService.list(
|
35 |
+
{},
|
36 |
+
paginationQuery
|
37 |
+
);
|
38 |
+
|
39 |
+
return JsonResponse.success(
|
40 |
+
{
|
41 |
+
data: serialize(docs, IngredientSerialization),
|
42 |
+
meta: paginationData,
|
43 |
+
},
|
44 |
+
res
|
45 |
+
);
|
46 |
+
};
|
47 |
+
}
|
src/modules/users/modules/ingredients/services/ingredients.service.ts
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Ingredient } from "@common/models/ingredient.model";
|
2 |
+
import { CrudService } from "@lib/services/crud.service";
|
3 |
+
|
4 |
+
export class IngredientsService extends CrudService(Ingredient) {}
|
src/modules/users/modules/meal-plans/controller/meals.controller.ts
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { MealPlansService } from "../services/meal-plans.service";
|
2 |
+
import { MealPlanSerialization } from "@common/serializers/meal-plan.serialization";
|
3 |
+
import { Request, Response } from "express";
|
4 |
+
import { JsonResponse } from "@lib/responses/json-response";
|
5 |
+
import { parsePaginationQuery } from "@helpers/pagination";
|
6 |
+
import { asyncHandler } from "@helpers/async-handler";
|
7 |
+
import { BaseController } from "@lib/controllers/controller.base";
|
8 |
+
import { Controller } from "@lib/decorators/controller.decorator";
|
9 |
+
import { serialize } from "@helpers/serialize";
|
10 |
+
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
11 |
+
import { UsersGuardMiddleware } from "modules/users/common/guards/users.guard";
|
12 |
+
import { SwaggerGet } from "@lib/decorators/swagger-routes.decorator";
|
13 |
+
import { SwaggerResponse } from "@lib/decorators/swagger-response.decorator";
|
14 |
+
import { SwaggerSummary } from "@lib/decorators/swagger-summary.decorator";
|
15 |
+
import { SwaggerDescription } from "@lib/decorators/swagger-description.decorator";
|
16 |
+
|
17 |
+
|
18 |
+
@Controller("/user/mealPlans")
|
19 |
+
@ControllerMiddleware(UsersGuardMiddleware())
|
20 |
+
export class UsersMealPlansController extends BaseController {
|
21 |
+
private mealPlansService = new MealPlansService();
|
22 |
+
|
23 |
+
setRoutes(): void {
|
24 |
+
this.router.get("/", asyncHandler(this.list));
|
25 |
+
}
|
26 |
+
|
27 |
+
@SwaggerGet()
|
28 |
+
@SwaggerResponse([MealPlanSerialization])
|
29 |
+
@SwaggerSummary("list meal plans")
|
30 |
+
@SwaggerDescription("list meal plans")
|
31 |
+
list = async (req: Request, res: Response) => {
|
32 |
+
const paginationQuery = parsePaginationQuery(req.query);
|
33 |
+
const { docs, paginationData } = await this.mealPlansService.list(
|
34 |
+
{},
|
35 |
+
paginationQuery,
|
36 |
+
{
|
37 |
+
populateArray: [
|
38 |
+
{ path: "days.meals", select: "name ingredients calories carbs proteins fats type" }
|
39 |
+
],
|
40 |
+
}
|
41 |
+
);
|
42 |
+
|
43 |
+
return JsonResponse.success(
|
44 |
+
{
|
45 |
+
data: serialize(docs, MealPlanSerialization),
|
46 |
+
meta: paginationData,
|
47 |
+
},
|
48 |
+
res
|
49 |
+
);
|
50 |
+
};
|
51 |
+
}
|
src/modules/users/modules/meal-plans/services/meal-plans.service.ts
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { MealPlan } from "@common/models/meal-plan.model";
|
2 |
+
import { CrudService } from "@lib/services/crud.service";
|
3 |
+
|
4 |
+
export class MealPlansService extends CrudService(MealPlan) {}
|
src/modules/users/modules/meals/controller/meals.controller.ts
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { MealsService } from "../services/meals.service";
|
2 |
+
import { MealSerialization } from "@common/serializers/meal.serialization";
|
3 |
+
import { Request, Response } from "express";
|
4 |
+
import { JsonResponse } from "@lib/responses/json-response";
|
5 |
+
import { parsePaginationQuery } from "@helpers/pagination";
|
6 |
+
import { asyncHandler } from "@helpers/async-handler";
|
7 |
+
import { BaseController } from "@lib/controllers/controller.base";
|
8 |
+
import { Controller } from "@lib/decorators/controller.decorator";
|
9 |
+
import { serialize } from "@helpers/serialize";
|
10 |
+
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
11 |
+
import { UsersGuardMiddleware } from "modules/users/common/guards/users.guard";
|
12 |
+
import { SwaggerGet } from "@lib/decorators/swagger-routes.decorator";
|
13 |
+
import { SwaggerResponse } from "@lib/decorators/swagger-response.decorator";
|
14 |
+
import { SwaggerSummary } from "@lib/decorators/swagger-summary.decorator";
|
15 |
+
import { SwaggerDescription } from "@lib/decorators/swagger-description.decorator";
|
16 |
+
|
17 |
+
|
18 |
+
@Controller("/user/meals")
|
19 |
+
@ControllerMiddleware(UsersGuardMiddleware())
|
20 |
+
export class UsersMealsController extends BaseController {
|
21 |
+
private mealsService = new MealsService();
|
22 |
+
|
23 |
+
setRoutes(): void {
|
24 |
+
this.router.get("/", asyncHandler(this.list));
|
25 |
+
}
|
26 |
+
|
27 |
+
@SwaggerGet()
|
28 |
+
@SwaggerResponse([MealSerialization])
|
29 |
+
@SwaggerSummary("list meals")
|
30 |
+
@SwaggerDescription("list meals")
|
31 |
+
list = async (req: Request, res: Response) => {
|
32 |
+
const paginationQuery = parsePaginationQuery(req.query);
|
33 |
+
const { docs, paginationData } = await this.mealsService.list(
|
34 |
+
{},
|
35 |
+
paginationQuery,
|
36 |
+
{
|
37 |
+
populateArray: [
|
38 |
+
{ path: "ingredients" }]
|
39 |
+
}
|
40 |
+
);
|
41 |
+
|
42 |
+
return JsonResponse.success(
|
43 |
+
{
|
44 |
+
data: serialize(docs, MealSerialization),
|
45 |
+
meta: paginationData,
|
46 |
+
},
|
47 |
+
res
|
48 |
+
);
|
49 |
+
};
|
50 |
+
}
|
src/modules/users/modules/meals/services/meals.service.ts
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Meal } from "@common/models/meal.model";
|
2 |
+
import { CrudService } from "@lib/services/crud.service";
|
3 |
+
|
4 |
+
export class MealsService extends CrudService(Meal) {}
|
src/modules/users/modules/user-registered-meal-plans/controller/user-registered-meal-plans.controller.ts
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { UserRegisteredMealPlansService } from "../services/user-registered-meal-plans.service";
|
2 |
+
import { Request, Response } from "express";
|
3 |
+
import { JsonResponse } from "@lib/responses/json-response";
|
4 |
+
import { parsePaginationQuery } from "@helpers/pagination";
|
5 |
+
import { asyncHandler } from "@helpers/async-handler";
|
6 |
+
import { paramsValidator } from "@helpers/validation.helper";
|
7 |
+
import { BaseController } from "@lib/controllers/controller.base";
|
8 |
+
import { Controller } from "@lib/decorators/controller.decorator";
|
9 |
+
import { serialize } from "@helpers/serialize";
|
10 |
+
import { UserRegisteredMealPlansSerialization } from "@common/serializers/user-registered-meal-plan.serialization";
|
11 |
+
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
12 |
+
import { UsersGuardMiddleware } from "modules/users/common/guards/users.guard";
|
13 |
+
import { SwaggerGet } from "@lib/decorators/swagger-routes.decorator";
|
14 |
+
import { SwaggerResponse } from "@lib/decorators/swagger-response.decorator";
|
15 |
+
import { SwaggerSummary } from "@lib/decorators/swagger-summary.decorator";
|
16 |
+
import { SwaggerDescription } from "@lib/decorators/swagger-description.decorator";
|
17 |
+
interface userRequest extends Request {
|
18 |
+
jwtPayload?: any;
|
19 |
+
}
|
20 |
+
|
21 |
+
@Controller("/user/myMealPlan")
|
22 |
+
@ControllerMiddleware(UsersGuardMiddleware())
|
23 |
+
export class UsersRegisteredMealPlansController extends BaseController {
|
24 |
+
private userRegisteredMealPlansService = new UserRegisteredMealPlansService();
|
25 |
+
|
26 |
+
setRoutes(): void {
|
27 |
+
this.router.get("/", asyncHandler(this.get));
|
28 |
+
}
|
29 |
+
|
30 |
+
@SwaggerGet()
|
31 |
+
@SwaggerResponse(UserRegisteredMealPlansSerialization)
|
32 |
+
@SwaggerSummary("my meal plan")
|
33 |
+
@SwaggerDescription("Get the meal plan that the user is currently registered to")
|
34 |
+
get = async (req: userRequest, res: Response): Promise<Response> => {
|
35 |
+
const data = await this.userRegisteredMealPlansService.findOneOrFail(
|
36 |
+
{ user: req.jwtPayload._id, isActive: true },
|
37 |
+
{
|
38 |
+
populateArray: [
|
39 |
+
{ path: "mealPlan", select: "image description Duration Level your_Journey key_Features" },
|
40 |
+
{ path: "days.meals", select: "name ingredients calories carbs proteins fats type" }
|
41 |
+
],
|
42 |
+
});
|
43 |
+
|
44 |
+
return JsonResponse.success(
|
45 |
+
{
|
46 |
+
data: serialize(data, UserRegisteredMealPlansSerialization),
|
47 |
+
},
|
48 |
+
res
|
49 |
+
);
|
50 |
+
};
|
51 |
+
}
|
src/modules/users/modules/user-registered-meal-plans/services/user-registered-meal-plans.service.ts
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { UserRegisteredMealPlan } from "@common/models/user-registered-meal-plan.model";
|
2 |
+
import { CrudService } from "@lib/services/crud.service";
|
3 |
+
|
4 |
+
export class UserRegisteredMealPlansService extends CrudService(UserRegisteredMealPlan) {}
|