moahmedwafy commited on
Commit
11378b9
·
unverified ·
2 Parent(s): 19cd995 184c241

Merge pull request #86 from Modarb-Ai-Trainer/activities

Browse files
:w ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { serialize } from "@helpers/serialize";
2
+ import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
3
+ import { Expose, Transform } from "class-transformer";
4
+
5
+ class HSDaysSerialization {
6
+ @Expose()
7
+ @SwaggerResponseProperty('string')
8
+ day: string;
9
+
10
+ @Expose()
11
+ @SwaggerResponseProperty('number')
12
+ points: number;
13
+ }
14
+
15
+ export class HomeStreakSerialization {
16
+ @Expose()
17
+ @Transform((value) => (value as any).map((day) => serialize(day, HSDaysSerialization)))
18
+ @SwaggerResponseProperty({ type: [HSDaysSerialization]})
19
+ days: HSDaysSerialization[];
20
+ }
package-lock.json CHANGED
@@ -30,6 +30,7 @@
30
  "tsc-alias": "^1.8.8"
31
  },
32
  "devDependencies": {
 
33
  "@types/express": "^4.17.21",
34
  "@types/swagger-ui-express": "^4.1.6",
35
  "nodemon": "^3.0.2",
@@ -51,6 +52,22 @@
51
  "node": ">=12"
52
  }
53
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  "node_modules/@hapi/address": {
55
  "version": "4.1.0",
56
  "resolved": "https://registry.npmjs.org/@hapi/address/-/address-4.1.0.tgz",
 
30
  "tsc-alias": "^1.8.8"
31
  },
32
  "devDependencies": {
33
+ "@faker-js/faker": "^8.4.1",
34
  "@types/express": "^4.17.21",
35
  "@types/swagger-ui-express": "^4.1.6",
36
  "nodemon": "^3.0.2",
 
52
  "node": ">=12"
53
  }
54
  },
55
+ "node_modules/@faker-js/faker": {
56
+ "version": "8.4.1",
57
+ "resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-8.4.1.tgz",
58
+ "integrity": "sha512-XQ3cU+Q8Uqmrbf2e0cIC/QN43sTBSC8KF12u29Mb47tWrt2hAgBXSgpZMj4Ao8Uk0iJcU99QsOCaIL8934obCg==",
59
+ "dev": true,
60
+ "funding": [
61
+ {
62
+ "type": "opencollective",
63
+ "url": "https://opencollective.com/fakerjs"
64
+ }
65
+ ],
66
+ "engines": {
67
+ "node": "^14.17.0 || ^16.13.0 || >=18.0.0",
68
+ "npm": ">=6.14.13"
69
+ }
70
+ },
71
  "node_modules/@hapi/address": {
72
  "version": "4.1.0",
73
  "resolved": "https://registry.npmjs.org/@hapi/address/-/address-4.1.0.tgz",
package.json CHANGED
@@ -14,6 +14,7 @@
14
  "author": "",
15
  "license": "ISC",
16
  "devDependencies": {
 
17
  "@types/express": "^4.17.21",
18
  "@types/swagger-ui-express": "^4.1.6",
19
  "nodemon": "^3.0.2",
 
14
  "author": "",
15
  "license": "ISC",
16
  "devDependencies": {
17
+ "@faker-js/faker": "^8.4.1",
18
  "@types/express": "^4.17.21",
19
  "@types/swagger-ui-express": "^4.1.6",
20
  "nodemon": "^3.0.2",
src/common/interfaces/user-request.interface.ts ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import { Request } from "express";
2
+ import { IJwtLoginPayload } from "./jwt-payload.interface";
3
+
4
+ export interface IUserRequest extends Request {
5
+ jwtPayload?: IJwtLoginPayload;
6
+ }
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
@@ -1,7 +1,6 @@
1
  import { UserRegisteredWorkoutsService } from "../../user-registered-workouts/services/user-registered-workouts.service";
2
- import { UserRegisteredMealPlansService } from "../../user-registered-meal-plans/services/user-registered-meal-plans.service";
3
  import { UserService } from "../../users/services/users.service";
4
- import { Request, Response } from "express";
5
  import { JsonResponse } from "@lib/responses/json-response";
6
  import { asyncHandler } from "@helpers/async-handler";
7
  import { BaseController } from "@lib/controllers/controller.base";
@@ -13,31 +12,102 @@ import { SwaggerGet } from "@lib/decorators/swagger-routes.decorator";
13
  import { SwaggerSummary } from "@lib/decorators/swagger-summary.decorator";
14
  import { SwaggerDescription } from "@lib/decorators/swagger-description.decorator";
15
  import { SwaggerResponse } from "@lib/decorators/swagger-response.decorator";
16
- import { HomeSerialization } from "common/serializers/home.serialization";
 
 
 
 
 
 
 
 
17
 
18
 
19
- interface userRequest extends Request {
20
- jwtPayload?: any;
21
- }
22
-
23
  @Controller("/user/homePage")
24
  @ControllerMiddleware(UsersGuardMiddleware())
25
  export class homePageController extends BaseController {
26
  private userRegisteredWorkoutsService = new UserRegisteredWorkoutsService();
27
- private userRegisteredMealPlansService = new UserRegisteredMealPlansService();
28
  private userService = new UserService();
 
29
 
30
  setRoutes(): void {
31
  this.router.get("/", asyncHandler(this.getHomePage));
 
 
 
32
  }
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  @SwaggerGet()
36
  @SwaggerResponse(HomeSerialization)
37
  @SwaggerSummary("Home")
38
  @SwaggerDescription("Get home page")
39
- getHomePage = async (req: userRequest, res: Response) => {
40
-
41
  const user = await this.userService.findOneOrFail(
42
  { _id: req.jwtPayload.id },
43
  { selectArray: ["preferences", "name", "fitness_level", "injuries"] }
@@ -65,5 +135,4 @@ export class homePageController extends BaseController {
65
  res
66
  );
67
  };
68
-
69
  }
 
1
  import { UserRegisteredWorkoutsService } from "../../user-registered-workouts/services/user-registered-workouts.service";
 
2
  import { UserService } from "../../users/services/users.service";
3
+ import { Response } from "express";
4
  import { JsonResponse } from "@lib/responses/json-response";
5
  import { asyncHandler } from "@helpers/async-handler";
6
  import { BaseController } from "@lib/controllers/controller.base";
 
12
  import { SwaggerSummary } from "@lib/decorators/swagger-summary.decorator";
13
  import { SwaggerDescription } from "@lib/decorators/swagger-description.decorator";
14
  import { SwaggerResponse } from "@lib/decorators/swagger-response.decorator";
15
+ import { HomeSerialization } from "../responses/home.serialization";
16
+ import { HomeStreakSerialization } from "../responses/home-streak.serialization";
17
+ import { SwaggerQuery } from "@lib/decorators/swagger-query.decorator";
18
+ import { queryValidator } from "@helpers/validation.helper";
19
+ import { homeStreakQueryValidation } from "../validations/home-streak.query.validation";
20
+ import { UserHomeService } from "../services/user-home.service";
21
+ import { IUserRequest } from "@common/interfaces/user-request.interface";
22
+ import { UserHomeYourDailyIntakeSerialization } from "../responses/user-home-your-daily-intake.serialization";
23
+ import { UserHomeDailyGoalsSerialization } from "../responses/user-home-daily-goals.serialization";
24
 
25
 
 
 
 
 
26
  @Controller("/user/homePage")
27
  @ControllerMiddleware(UsersGuardMiddleware())
28
  export class homePageController extends BaseController {
29
  private userRegisteredWorkoutsService = new UserRegisteredWorkoutsService();
 
30
  private userService = new UserService();
31
+ private userHomeService = new UserHomeService();
32
 
33
  setRoutes(): void {
34
  this.router.get("/", asyncHandler(this.getHomePage));
35
+ this.router.get("/streak", queryValidator(homeStreakQueryValidation), asyncHandler(this.getHomePageStreak));
36
+ this.router.get("/your-daily-intake", asyncHandler(this.getHomePageYourDailyIntake));
37
+ this.router.get("/daily-goals", asyncHandler(this.getHomePageDailyGoals));
38
  }
39
 
40
+ @SwaggerGet('/streak')
41
+ @SwaggerResponse(HomeStreakSerialization)
42
+ @SwaggerQuery({
43
+ startDate: {
44
+ type: "string",
45
+ required: true,
46
+ },
47
+ endDate: {
48
+ type: "string",
49
+ required: true,
50
+ },
51
+ })
52
+ @SwaggerSummary("Home Streak Weeks")
53
+ @SwaggerDescription("Get home page streak weeks")
54
+ getHomePageStreak = async (req: IUserRequest, res: Response) => {
55
+ // getting the query params
56
+ const startDate = new Date(req.query.startDate as string);
57
+ const endDate = new Date(req.query.endDate as string);
58
+
59
+ // getting the streak weeks
60
+ const streak = await this.userHomeService.getHomePageStreak(req.jwtPayload.id, startDate, endDate);
61
+
62
+ // return response
63
+ return JsonResponse.success(
64
+ {
65
+ data: serialize(streak, HomeStreakSerialization)
66
+ },
67
+ res
68
+ );
69
+ };
70
+
71
+
72
+ @SwaggerGet('/your-daily-intake')
73
+ @SwaggerResponse(UserHomeYourDailyIntakeSerialization)
74
+ @SwaggerSummary("Home Your Daily Intake")
75
+ @SwaggerDescription("Get home page your daily intake")
76
+ getHomePageYourDailyIntake = async (req: IUserRequest, res: Response) => {
77
+ // getting the daily intake
78
+ const dailyIntake = await this.userHomeService.getHomePageYourDailyIntake(req.jwtPayload.id);
79
+
80
+ // return response
81
+ return JsonResponse.success(
82
+ {
83
+ data: serialize(dailyIntake, UserHomeYourDailyIntakeSerialization)
84
+ },
85
+ res
86
+ );
87
+ };
88
+
89
+
90
+ @SwaggerGet('/daily-goals')
91
+ @SwaggerResponse(UserHomeDailyGoalsSerialization)
92
+ @SwaggerSummary("Home Daily Goals")
93
+ @SwaggerDescription("Get daily goals for user home")
94
+ getHomePageDailyGoals = async (req: IUserRequest, res: Response) => {
95
+ const dailyGoals = await this.userHomeService.getDailyGoals(req.jwtPayload.id)
96
+
97
+ return JsonResponse.success(
98
+ {
99
+ data: serialize(dailyGoals, UserHomeDailyGoalsSerialization)
100
+ },
101
+ res
102
+ );
103
+ }
104
+
105
 
106
  @SwaggerGet()
107
  @SwaggerResponse(HomeSerialization)
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/home-streak.serialization.ts ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
2
+ import { Expose } from "class-transformer";
3
+
4
+ class HSDaysSerialization {
5
+ @Expose()
6
+ @SwaggerResponseProperty('string')
7
+ day: string;
8
+
9
+ @Expose()
10
+ @SwaggerResponseProperty('number')
11
+ points: number;
12
+ }
13
+
14
+ export class HomeStreakSerialization {
15
+ @Expose()
16
+ @SwaggerResponseProperty({ type: [HSDaysSerialization]})
17
+ days: HSDaysSerialization[];
18
+ }
src/{common/serializers → modules/users/modules/home/responses}/home.serialization.ts RENAMED
@@ -118,7 +118,6 @@ class UserHome {
118
  }
119
 
120
  export class HomeSerialization {
121
-
122
  @Expose()
123
  @SwaggerResponseProperty({ type: UserHome })
124
  @Transform(({ value }) => serialize(value, UserHome))
@@ -132,4 +131,4 @@ export class HomeSerialization {
132
  @Expose({ name: "myMealPlan" })
133
  @SwaggerResponseProperty({ type: {} })
134
  myMealPlan: any;
135
- }
 
118
  }
119
 
120
  export class HomeSerialization {
 
121
  @Expose()
122
  @SwaggerResponseProperty({ type: UserHome })
123
  @Transform(({ value }) => serialize(value, UserHome))
 
131
  @Expose({ name: "myMealPlan" })
132
  @SwaggerResponseProperty({ type: {} })
133
  myMealPlan: any;
134
+ }
src/modules/users/modules/home/responses/user-home-daily-goals.serialization.ts ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
2
+ import { Expose } from "class-transformer";
3
+
4
+
5
+ export class UserHomeDailyGoalsSerialization {
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
+ }
src/modules/users/modules/home/responses/user-home-your-daily-intake.serialization.ts ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
2
+ import { Expose } from "class-transformer";
3
+
4
+
5
+ export class UserHomeYourDailyIntakeSerialization {
6
+ @Expose()
7
+ @SwaggerResponseProperty('number')
8
+ caloriesGoal: number;
9
+
10
+ @Expose()
11
+ @SwaggerResponseProperty('number')
12
+ caloriesLeft: number;
13
+
14
+ @Expose()
15
+ @SwaggerResponseProperty('number')
16
+ caloriesBurned: number;
17
+
18
+ @Expose()
19
+ @SwaggerResponseProperty('number')
20
+ carbsGoal: number;
21
+
22
+ @Expose()
23
+ @SwaggerResponseProperty('number')
24
+ carbsConsumed: number;
25
+
26
+ @Expose()
27
+ @SwaggerResponseProperty('number')
28
+ proteinGoal: number;
29
+
30
+ @Expose()
31
+ @SwaggerResponseProperty('number')
32
+ proteinConsumed: number;
33
+
34
+ @Expose()
35
+ @SwaggerResponseProperty('number')
36
+ fatGoal: number;
37
+
38
+ @Expose()
39
+ @SwaggerResponseProperty('number')
40
+ fatConsumed: number;
41
+ }
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 ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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
+ import { UserNutriHomeDailyGoalsSerialization } from "../responses/user-nutri-home-daily-goals.serialization";
6
+
7
+ export class UserHomeService {
8
+ private getDaysArray(startDate: Date, endDate: Date): string[] {
9
+ const days = [];
10
+ for (let day = startDate; day <= endDate; day.setDate(day.getDate() + 1)) {
11
+ days.push(day.toLocaleString('en-US', { weekday: 'long' }).toLowerCase());
12
+ }
13
+ return days;
14
+ }
15
+
16
+ async getDailyGoals(_userId: string): Promise<UserHomeDailyGoalsSerialization> {
17
+ const waterGoal = faker.number.int({ min: 29, max: 100 });
18
+ const waterConsumed = faker.number.int({ min: 0, max: waterGoal });
19
+
20
+ const stepsGoal = faker.number.int({ min: 29, max: 100 });
21
+ const stepsDone = faker.number.int({ min: 0, max: stepsGoal });
22
+
23
+ const exercisesCals = faker.number.int({ min: 29, max: 100 });
24
+ const exercisesHours = faker.number.int({ min: 29, max: 100 });
25
+
26
+ return {
27
+ waterGoal,
28
+ waterConsumed,
29
+ stepsGoal,
30
+ stepsDone,
31
+ exercisesCals,
32
+ exercisesHours
33
+ }
34
+ }
35
+
36
+ async getHomePageYourDailyIntake(_userId: string): Promise<UserHomeYourDailyIntakeSerialization>{
37
+ const caloriesGoal = faker.number.int({ min: 29, max: 100 });
38
+ const caloriesLeft = faker.number.int({ min: 0, max: caloriesGoal});
39
+ const caloriesBurned = caloriesGoal - caloriesLeft;
40
+
41
+ const carbsGoal = faker.number.int({ min: 29, max: 100 });
42
+ const carbsConsumed = faker.number.int({ min: 0, max: carbsGoal });
43
+
44
+ const proteinGoal = faker.number.int({ min: 29, max: 100 });
45
+ const proteinConsumed = faker.number.int({ min: 0, max: proteinGoal });
46
+
47
+ const fatGoal = faker.number.int({ min: 29, max: 100 });
48
+ const fatConsumed = faker.number.int({ min: 0, max: fatGoal });
49
+
50
+ return {
51
+ caloriesGoal,
52
+ caloriesLeft,
53
+ caloriesBurned,
54
+ carbsGoal,
55
+ carbsConsumed,
56
+ proteinGoal,
57
+ proteinConsumed,
58
+ fatGoal,
59
+ fatConsumed,
60
+ }
61
+ }
62
+
63
+ async getHomePageStreak(_userId: string, startDate: Date, endDate: Date): Promise<HomeStreakSerialization> {
64
+ // list day names in between the start and end date
65
+ const days = this.getDaysArray(startDate, endDate);
66
+
67
+ return {
68
+ days: days.map(day => ({
69
+ day: day,
70
+ points: faker.number.int({ min: 0, max: 100 }),
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
+ }
src/modules/users/modules/home/validations/home-streak.query.validation.ts ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import * as joi from "joi";
2
+ import { createSchema } from "@helpers/create-schema";
3
+
4
+ export interface IHomeStreakQuery {
5
+ startDate: string;
6
+ endDate: string;
7
+ }
8
+
9
+ export const homeStreakQueryKeys = {
10
+ startDate: joi.string().pattern(new RegExp("^[0-9]{4}-[0-9]{2}-[0-9]{2}$")).required().messages({
11
+ "string.base": "startDate must be a string",
12
+ "string.pattern.base": "startDate must be a valid date",
13
+ "any.required": "startDate is required",
14
+ }),
15
+ endDate: joi.string().pattern(new RegExp("^[0-9]{4}-[0-9]{2}-[0-9]{2}$")).required().messages({
16
+ "string.base": "endDate must be a string",
17
+ "string.pattern.base": "endDate must be a valid date",
18
+ "any.required": "endDate is required",
19
+ })
20
+ };
21
+
22
+ export const homeStreakQueryValidation = createSchema<IHomeStreakQuery>(homeStreakQueryKeys);