Spaces:
Running
Running
Commit
·
184c241
1
Parent(s):
2b34119
feat(nutri-home): stats
Browse files- src/modules/users/modules/home/controllers/home-nutriguide.controller.ts +62 -0
- src/modules/users/modules/home/controllers/home.controller.ts +2 -2
- src/modules/users/modules/home/responses/user-nutri-home-daily-goals.serialization.ts +37 -0
- src/modules/users/modules/home/services/user-home.service.ts +12 -0
src/modules/users/modules/home/controllers/home-nutriguide.controller.ts
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Response } from "express";
|
2 |
+
import { JsonResponse } from "@lib/responses/json-response";
|
3 |
+
import { asyncHandler } from "@helpers/async-handler";
|
4 |
+
import { BaseController } from "@lib/controllers/controller.base";
|
5 |
+
import { Controller } from "@lib/decorators/controller.decorator";
|
6 |
+
import { serialize } from "@helpers/serialize";
|
7 |
+
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
8 |
+
import { UsersGuardMiddleware } from "modules/users/common/guards/users.guard";
|
9 |
+
import { SwaggerGet } from "@lib/decorators/swagger-routes.decorator";
|
10 |
+
import { SwaggerSummary } from "@lib/decorators/swagger-summary.decorator";
|
11 |
+
import { SwaggerDescription } from "@lib/decorators/swagger-description.decorator";
|
12 |
+
import { SwaggerResponse } from "@lib/decorators/swagger-response.decorator";
|
13 |
+
import { UserHomeService } from "../services/user-home.service";
|
14 |
+
import { IUserRequest } from "@common/interfaces/user-request.interface";
|
15 |
+
import { UserHomeYourDailyIntakeSerialization } from "../responses/user-home-your-daily-intake.serialization";
|
16 |
+
import { UserNutriHomeDailyGoalsSerialization } from "../responses/user-nutri-home-daily-goals.serialization";
|
17 |
+
|
18 |
+
|
19 |
+
@Controller("/user/nutri-guide")
|
20 |
+
@ControllerMiddleware(UsersGuardMiddleware())
|
21 |
+
export class homeNutriGuideController extends BaseController {
|
22 |
+
private userHomeService = new UserHomeService();
|
23 |
+
|
24 |
+
setRoutes(): void {
|
25 |
+
this.router.get("/todays-intake", asyncHandler(this.getHomePageYourDailyIntake));
|
26 |
+
this.router.get("/daily-goals", asyncHandler(this.getHomePageDailyGoals));
|
27 |
+
}
|
28 |
+
|
29 |
+
|
30 |
+
@SwaggerGet('/todays-intake')
|
31 |
+
@SwaggerResponse(UserHomeYourDailyIntakeSerialization)
|
32 |
+
@SwaggerSummary("Nutri home today's Intake")
|
33 |
+
@SwaggerDescription("Get Nutriy page today's intake")
|
34 |
+
getHomePageYourDailyIntake = async (req: IUserRequest, res: Response) => {
|
35 |
+
// getting the daily intake
|
36 |
+
const dailyIntake = await this.userHomeService.getHomePageYourDailyIntake(req.jwtPayload.id);
|
37 |
+
|
38 |
+
// return response
|
39 |
+
return JsonResponse.success(
|
40 |
+
{
|
41 |
+
data: serialize(dailyIntake, UserHomeYourDailyIntakeSerialization)
|
42 |
+
},
|
43 |
+
res
|
44 |
+
);
|
45 |
+
};
|
46 |
+
|
47 |
+
|
48 |
+
@SwaggerGet('/daily-goals')
|
49 |
+
@SwaggerResponse(UserNutriHomeDailyGoalsSerialization)
|
50 |
+
@SwaggerSummary("Nutri Home Daily Goals")
|
51 |
+
@SwaggerDescription("Get Nutri daily goals for user home")
|
52 |
+
getHomePageDailyGoals = async (req: IUserRequest, res: Response) => {
|
53 |
+
const dailyGoals = await this.userHomeService.getNutriHomeDailyGoals(req.jwtPayload.id)
|
54 |
+
|
55 |
+
return JsonResponse.success(
|
56 |
+
{
|
57 |
+
data: serialize(dailyGoals, UserNutriHomeDailyGoalsSerialization)
|
58 |
+
},
|
59 |
+
res
|
60 |
+
);
|
61 |
+
}
|
62 |
+
}
|
src/modules/users/modules/home/controllers/home.controller.ts
CHANGED
@@ -68,6 +68,7 @@ export class homePageController extends BaseController {
|
|
68 |
);
|
69 |
};
|
70 |
|
|
|
71 |
@SwaggerGet('/your-daily-intake')
|
72 |
@SwaggerResponse(UserHomeYourDailyIntakeSerialization)
|
73 |
@SwaggerSummary("Home Your Daily Intake")
|
@@ -85,6 +86,7 @@ export class homePageController extends BaseController {
|
|
85 |
);
|
86 |
};
|
87 |
|
|
|
88 |
@SwaggerGet('/daily-goals')
|
89 |
@SwaggerResponse(UserHomeDailyGoalsSerialization)
|
90 |
@SwaggerSummary("Home Daily Goals")
|
@@ -106,7 +108,6 @@ export class homePageController extends BaseController {
|
|
106 |
@SwaggerSummary("Home")
|
107 |
@SwaggerDescription("Get home page")
|
108 |
getHomePage = async (req: IUserRequest, res: Response) => {
|
109 |
-
|
110 |
const user = await this.userService.findOneOrFail(
|
111 |
{ _id: req.jwtPayload.id },
|
112 |
{ selectArray: ["preferences", "name", "fitness_level", "injuries"] }
|
@@ -134,5 +135,4 @@ export class homePageController extends BaseController {
|
|
134 |
res
|
135 |
);
|
136 |
};
|
137 |
-
|
138 |
}
|
|
|
68 |
);
|
69 |
};
|
70 |
|
71 |
+
|
72 |
@SwaggerGet('/your-daily-intake')
|
73 |
@SwaggerResponse(UserHomeYourDailyIntakeSerialization)
|
74 |
@SwaggerSummary("Home Your Daily Intake")
|
|
|
86 |
);
|
87 |
};
|
88 |
|
89 |
+
|
90 |
@SwaggerGet('/daily-goals')
|
91 |
@SwaggerResponse(UserHomeDailyGoalsSerialization)
|
92 |
@SwaggerSummary("Home Daily Goals")
|
|
|
108 |
@SwaggerSummary("Home")
|
109 |
@SwaggerDescription("Get home page")
|
110 |
getHomePage = async (req: IUserRequest, res: Response) => {
|
|
|
111 |
const user = await this.userService.findOneOrFail(
|
112 |
{ _id: req.jwtPayload.id },
|
113 |
{ selectArray: ["preferences", "name", "fitness_level", "injuries"] }
|
|
|
135 |
res
|
136 |
);
|
137 |
};
|
|
|
138 |
}
|
src/modules/users/modules/home/responses/user-nutri-home-daily-goals.serialization.ts
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
|
2 |
+
import { Expose } from "class-transformer";
|
3 |
+
|
4 |
+
|
5 |
+
export class UserNutriHomeDailyGoalsSerialization {
|
6 |
+
@Expose()
|
7 |
+
@SwaggerResponseProperty('number')
|
8 |
+
waterGoal: number;
|
9 |
+
|
10 |
+
@Expose()
|
11 |
+
@SwaggerResponseProperty('number')
|
12 |
+
waterConsumed: number;
|
13 |
+
|
14 |
+
@Expose()
|
15 |
+
@SwaggerResponseProperty('number')
|
16 |
+
stepsGoal: number;
|
17 |
+
|
18 |
+
@Expose()
|
19 |
+
@SwaggerResponseProperty('number')
|
20 |
+
stepsDone: number;
|
21 |
+
|
22 |
+
@Expose()
|
23 |
+
@SwaggerResponseProperty('number')
|
24 |
+
exercisesCals: number;
|
25 |
+
|
26 |
+
@Expose()
|
27 |
+
@SwaggerResponseProperty('number')
|
28 |
+
exercisesHours: number;
|
29 |
+
|
30 |
+
@Expose()
|
31 |
+
@SwaggerResponseProperty('number')
|
32 |
+
sleepGoal: number;
|
33 |
+
|
34 |
+
@Expose()
|
35 |
+
@SwaggerResponseProperty('number')
|
36 |
+
sleepDone: number;
|
37 |
+
}
|
src/modules/users/modules/home/services/user-home.service.ts
CHANGED
@@ -2,6 +2,7 @@ import { HomeStreakSerialization } from "../responses/home-streak.serialization"
|
|
2 |
import { faker } from '@faker-js/faker';
|
3 |
import { UserHomeYourDailyIntakeSerialization } from "../responses/user-home-your-daily-intake.serialization";
|
4 |
import { UserHomeDailyGoalsSerialization } from "../responses/user-home-daily-goals.serialization";
|
|
|
5 |
|
6 |
export class UserHomeService {
|
7 |
private getDaysArray(startDate: Date, endDate: Date): string[] {
|
@@ -70,4 +71,15 @@ export class UserHomeService {
|
|
70 |
})),
|
71 |
}
|
72 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
}
|
|
|
2 |
import { faker } from '@faker-js/faker';
|
3 |
import { UserHomeYourDailyIntakeSerialization } from "../responses/user-home-your-daily-intake.serialization";
|
4 |
import { UserHomeDailyGoalsSerialization } from "../responses/user-home-daily-goals.serialization";
|
5 |
+
import { UserNutriHomeDailyGoalsSerialization } from "../responses/user-nutri-home-daily-goals.serialization";
|
6 |
|
7 |
export class UserHomeService {
|
8 |
private getDaysArray(startDate: Date, endDate: Date): string[] {
|
|
|
71 |
})),
|
72 |
}
|
73 |
}
|
74 |
+
|
75 |
+
async getNutriHomeDailyGoals(userId: string): Promise<UserNutriHomeDailyGoalsSerialization> {
|
76 |
+
const sleepGoal = faker.number.int({ min:29, max: 100 })
|
77 |
+
const sleepDone = faker.number.int({ min:0, max: sleepGoal })
|
78 |
+
|
79 |
+
return {
|
80 |
+
...(await this.getDailyGoals(userId)),
|
81 |
+
sleepGoal,
|
82 |
+
sleepDone,
|
83 |
+
}
|
84 |
+
}
|
85 |
}
|