Spaces:
Running
Running
Commit
·
2b34119
1
Parent(s):
d7afbe6
feat(user-home): daily goals
Browse files
src/modules/users/modules/home/controllers/home.controller.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { homeStreakQueryValidation } from "../validations/home-streak.query.vali
|
|
| 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")
|
|
@@ -33,6 +34,7 @@ export class homePageController extends BaseController {
|
|
| 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')
|
|
@@ -83,6 +85,22 @@ export class homePageController extends BaseController {
|
|
| 83 |
);
|
| 84 |
};
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
@SwaggerGet()
|
| 87 |
@SwaggerResponse(HomeSerialization)
|
| 88 |
@SwaggerSummary("Home")
|
|
|
|
| 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")
|
|
|
|
| 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')
|
|
|
|
| 85 |
);
|
| 86 |
};
|
| 87 |
|
| 88 |
+
@SwaggerGet('/daily-goals')
|
| 89 |
+
@SwaggerResponse(UserHomeDailyGoalsSerialization)
|
| 90 |
+
@SwaggerSummary("Home Daily Goals")
|
| 91 |
+
@SwaggerDescription("Get daily goals for user home")
|
| 92 |
+
getHomePageDailyGoals = async (req: IUserRequest, res: Response) => {
|
| 93 |
+
const dailyGoals = await this.userHomeService.getDailyGoals(req.jwtPayload.id)
|
| 94 |
+
|
| 95 |
+
return JsonResponse.success(
|
| 96 |
+
{
|
| 97 |
+
data: serialize(dailyGoals, UserHomeDailyGoalsSerialization)
|
| 98 |
+
},
|
| 99 |
+
res
|
| 100 |
+
);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
|
| 104 |
@SwaggerGet()
|
| 105 |
@SwaggerResponse(HomeSerialization)
|
| 106 |
@SwaggerSummary("Home")
|
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/services/user-home.service.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 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,6 +12,26 @@ export class UserHomeService {
|
|
| 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});
|
|
|
|
| 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 |
|
| 6 |
export class UserHomeService {
|
| 7 |
private getDaysArray(startDate: Date, endDate: Date): string[] {
|
|
|
|
| 12 |
return days;
|
| 13 |
}
|
| 14 |
|
| 15 |
+
async getDailyGoals(_userId: string): Promise<UserHomeDailyGoalsSerialization> {
|
| 16 |
+
const waterGoal = faker.number.int({ min: 29, max: 100 });
|
| 17 |
+
const waterConsumed = faker.number.int({ min: 0, max: waterGoal });
|
| 18 |
+
|
| 19 |
+
const stepsGoal = faker.number.int({ min: 29, max: 100 });
|
| 20 |
+
const stepsDone = faker.number.int({ min: 0, max: stepsGoal });
|
| 21 |
+
|
| 22 |
+
const exercisesCals = faker.number.int({ min: 29, max: 100 });
|
| 23 |
+
const exercisesHours = faker.number.int({ min: 29, max: 100 });
|
| 24 |
+
|
| 25 |
+
return {
|
| 26 |
+
waterGoal,
|
| 27 |
+
waterConsumed,
|
| 28 |
+
stepsGoal,
|
| 29 |
+
stepsDone,
|
| 30 |
+
exercisesCals,
|
| 31 |
+
exercisesHours
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
async getHomePageYourDailyIntake(_userId: string): Promise<UserHomeYourDailyIntakeSerialization>{
|
| 36 |
const caloriesGoal = faker.number.int({ min: 29, max: 100 });
|
| 37 |
const caloriesLeft = faker.number.int({ min: 0, max: caloriesGoal});
|