moahmedwafy commited on
Commit
d7afbe6
·
1 Parent(s): fa68931

feat(user-home): daily intake endpoint

Browse files
src/modules/users/modules/home/controllers/home.controller.ts CHANGED
@@ -19,6 +19,7 @@ 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
 
23
 
24
  @Controller("/user/homePage")
@@ -31,6 +32,7 @@ export class homePageController extends BaseController {
31
  setRoutes(): void {
32
  this.router.get("/", asyncHandler(this.getHomePage));
33
  this.router.get("/streak", queryValidator(homeStreakQueryValidation), asyncHandler(this.getHomePageStreak));
 
34
  }
35
 
36
  @SwaggerGet('/streak')
@@ -64,6 +66,23 @@ export class homePageController extends BaseController {
64
  );
65
  };
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  @SwaggerGet()
68
  @SwaggerResponse(HomeSerialization)
69
  @SwaggerSummary("Home")
 
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
 
24
 
25
  @Controller("/user/homePage")
 
32
  setRoutes(): void {
33
  this.router.get("/", asyncHandler(this.getHomePage));
34
  this.router.get("/streak", queryValidator(homeStreakQueryValidation), asyncHandler(this.getHomePageStreak));
35
+ this.router.get("/your-daily-intake", asyncHandler(this.getHomePageYourDailyIntake));
36
  }
37
 
38
  @SwaggerGet('/streak')
 
66
  );
67
  };
68
 
69
+ @SwaggerGet('/your-daily-intake')
70
+ @SwaggerResponse(UserHomeYourDailyIntakeSerialization)
71
+ @SwaggerSummary("Home Your Daily Intake")
72
+ @SwaggerDescription("Get home page your daily intake")
73
+ getHomePageYourDailyIntake = async (req: IUserRequest, res: Response) => {
74
+ // getting the daily intake
75
+ const dailyIntake = await this.userHomeService.getHomePageYourDailyIntake(req.jwtPayload.id);
76
+
77
+ // return response
78
+ return JsonResponse.success(
79
+ {
80
+ data: serialize(dailyIntake, UserHomeYourDailyIntakeSerialization)
81
+ },
82
+ res
83
+ );
84
+ };
85
+
86
  @SwaggerGet()
87
  @SwaggerResponse(HomeSerialization)
88
  @SwaggerSummary("Home")
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/services/user-home.service.ts CHANGED
@@ -1,5 +1,6 @@
1
  import { HomeStreakSerialization } from "../responses/home-streak.serialization";
2
  import { faker } from '@faker-js/faker';
 
3
 
4
  export class UserHomeService {
5
  private getDaysArray(startDate: Date, endDate: Date): string[] {
@@ -10,6 +11,33 @@ export class UserHomeService {
10
  return days;
11
  }
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  async getHomePageStreak(_userId: string, startDate: Date, endDate: Date): Promise<HomeStreakSerialization> {
14
  // list day names in between the start and end date
15
  const days = this.getDaysArray(startDate, endDate);
 
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
 
5
  export class UserHomeService {
6
  private getDaysArray(startDate: Date, endDate: Date): string[] {
 
11
  return days;
12
  }
13
 
14
+ async getHomePageYourDailyIntake(_userId: string): Promise<UserHomeYourDailyIntakeSerialization>{
15
+ const caloriesGoal = faker.number.int({ min: 29, max: 100 });
16
+ const caloriesLeft = faker.number.int({ min: 0, max: caloriesGoal});
17
+ const caloriesBurned = caloriesGoal - caloriesLeft;
18
+
19
+ const carbsGoal = faker.number.int({ min: 29, max: 100 });
20
+ const carbsConsumed = faker.number.int({ min: 0, max: carbsGoal });
21
+
22
+ const proteinGoal = faker.number.int({ min: 29, max: 100 });
23
+ const proteinConsumed = faker.number.int({ min: 0, max: proteinGoal });
24
+
25
+ const fatGoal = faker.number.int({ min: 29, max: 100 });
26
+ const fatConsumed = faker.number.int({ min: 0, max: fatGoal });
27
+
28
+ return {
29
+ caloriesGoal,
30
+ caloriesLeft,
31
+ caloriesBurned,
32
+ carbsGoal,
33
+ carbsConsumed,
34
+ proteinGoal,
35
+ proteinConsumed,
36
+ fatGoal,
37
+ fatConsumed,
38
+ }
39
+ }
40
+
41
  async getHomePageStreak(_userId: string, startDate: Date, endDate: Date): Promise<HomeStreakSerialization> {
42
  // list day names in between the start and end date
43
  const days = this.getDaysArray(startDate, endDate);