Spaces:
Sleeping
Sleeping
Hozifa Elgharbawy
commited on
Commit
·
733f745
1
Parent(s):
8a41979
chore: Update controllers and serializers for user-registered-workout and user-registered-meal-plan
Browse files- src/common/serializers/home.serialization.ts +135 -0
- src/common/serializers/user-registered-workoutPopulate.serialization.ts +39 -18
- src/lib/services/crud.service.ts +3 -1
- src/modules/users/modules/exercises/controllers/exercises.controller.ts +1 -2
- src/modules/users/modules/home/controllers/home.controller.ts +69 -0
- src/modules/users/modules/templates/controllers/templates.controller.ts +1 -1
- src/modules/users/modules/user-registered-workouts/controllers/user-registered-workouts.controller.ts +51 -79
src/common/serializers/home.serialization.ts
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Expose, Transform } from "class-transformer";
|
2 |
+
import { serialize } from "@helpers/serialize";
|
3 |
+
import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
|
4 |
+
|
5 |
+
|
6 |
+
class DaysInHome {
|
7 |
+
@Expose()
|
8 |
+
@SwaggerResponseProperty({ type: "number" })
|
9 |
+
day_number: number;
|
10 |
+
|
11 |
+
@Expose()
|
12 |
+
@SwaggerResponseProperty({ type: "number" })
|
13 |
+
total_number_exercises: number;
|
14 |
+
|
15 |
+
@Expose()
|
16 |
+
@SwaggerResponseProperty({ type: "string" })
|
17 |
+
day_type: string;
|
18 |
+
|
19 |
+
@Expose()
|
20 |
+
@SwaggerResponseProperty({ type: "boolean" })
|
21 |
+
is_done: Boolean;
|
22 |
+
|
23 |
+
|
24 |
+
}
|
25 |
+
|
26 |
+
class weeksInHome {
|
27 |
+
@Expose()
|
28 |
+
@SwaggerResponseProperty({ type: "number" })
|
29 |
+
week_number: number;
|
30 |
+
|
31 |
+
@Expose()
|
32 |
+
@SwaggerResponseProperty({ type: "boolean" })
|
33 |
+
is_done: Boolean;
|
34 |
+
|
35 |
+
@Expose({ name: "days" })
|
36 |
+
@SwaggerResponseProperty({ type: [DaysInHome] })
|
37 |
+
@Transform(({ value }) => serialize(value, DaysInHome))
|
38 |
+
days: any;
|
39 |
+
}
|
40 |
+
|
41 |
+
class WorkoutInHome {
|
42 |
+
@Expose({ name: "_id" })
|
43 |
+
@SwaggerResponseProperty({ type: "string" })
|
44 |
+
id: string;
|
45 |
+
|
46 |
+
@Expose()
|
47 |
+
@SwaggerResponseProperty({ type: "string" })
|
48 |
+
name: string;
|
49 |
+
|
50 |
+
@Expose()
|
51 |
+
@SwaggerResponseProperty({ type: "number" })
|
52 |
+
min_per_day: number;
|
53 |
+
}
|
54 |
+
|
55 |
+
class MyWorkoutHome {
|
56 |
+
@Expose({ name: "_id" })
|
57 |
+
@SwaggerResponseProperty({ type: "string" })
|
58 |
+
id: string;
|
59 |
+
|
60 |
+
@Expose()
|
61 |
+
@SwaggerResponseProperty({ type: WorkoutInHome })
|
62 |
+
@Transform(({ value }) => serialize(value, WorkoutInHome))
|
63 |
+
workout: any;
|
64 |
+
|
65 |
+
@Expose()
|
66 |
+
@SwaggerResponseProperty({ type: "boolean" })
|
67 |
+
is_active: boolean;
|
68 |
+
|
69 |
+
@Expose()
|
70 |
+
@SwaggerResponseProperty({ type: weeksInHome })
|
71 |
+
@Transform(({ value }) => serialize(value, weeksInHome))
|
72 |
+
weeks: any;
|
73 |
+
}
|
74 |
+
|
75 |
+
class PreferencesUserHome {
|
76 |
+
@Expose()
|
77 |
+
@SwaggerResponseProperty({ type: "string" })
|
78 |
+
fitness_goal: string;
|
79 |
+
|
80 |
+
@Expose()
|
81 |
+
@SwaggerResponseProperty({ type: "number" })
|
82 |
+
target_weight: number;
|
83 |
+
|
84 |
+
@Expose()
|
85 |
+
@SwaggerResponseProperty({ type: "number" })
|
86 |
+
workout_frequency: number;
|
87 |
+
|
88 |
+
@Expose({ name: "preferred_days" })
|
89 |
+
@SwaggerResponseProperty({ type: ["string"] })
|
90 |
+
preferred_days: any;
|
91 |
+
|
92 |
+
@Expose()
|
93 |
+
@SwaggerResponseProperty({ type: "string" })
|
94 |
+
workout_place: string;
|
95 |
+
|
96 |
+
@Expose()
|
97 |
+
@SwaggerResponseProperty({ type: ["string"] })
|
98 |
+
preferred_equipment: any;
|
99 |
+
}
|
100 |
+
|
101 |
+
class UserHome {
|
102 |
+
@Expose({ name: "_id" })
|
103 |
+
@SwaggerResponseProperty({ type: "string" })
|
104 |
+
id: string;
|
105 |
+
|
106 |
+
@Expose()
|
107 |
+
@SwaggerResponseProperty({ type: "string" })
|
108 |
+
name: string;
|
109 |
+
|
110 |
+
@Expose({ name: "preferences" })
|
111 |
+
@SwaggerResponseProperty({ type: PreferencesUserHome })
|
112 |
+
@Transform(({ value }) => serialize(value, PreferencesUserHome))
|
113 |
+
preferences: any;
|
114 |
+
|
115 |
+
@Expose()
|
116 |
+
@SwaggerResponseProperty({ type: ["string"] })
|
117 |
+
injuries: any;
|
118 |
+
}
|
119 |
+
|
120 |
+
export class HomeSerialization {
|
121 |
+
|
122 |
+
@Expose()
|
123 |
+
@SwaggerResponseProperty({ type: UserHome })
|
124 |
+
@Transform(({ value }) => serialize(value, UserHome))
|
125 |
+
user: any;
|
126 |
+
|
127 |
+
@Expose()
|
128 |
+
@SwaggerResponseProperty({ type: MyWorkoutHome })
|
129 |
+
@Transform(({ value }) => serialize(value, MyWorkoutHome))
|
130 |
+
myWorkout: any;
|
131 |
+
|
132 |
+
@Expose({ name: "myMealPlan" })
|
133 |
+
@SwaggerResponseProperty({ type: {} })
|
134 |
+
myMealPlan: any;
|
135 |
+
}
|
src/common/serializers/user-registered-workoutPopulate.serialization.ts
CHANGED
@@ -2,8 +2,6 @@ import { Expose, Transform } from "class-transformer";
|
|
2 |
import { serialize } from "@helpers/serialize";
|
3 |
import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
|
4 |
import { ExerciseSerialization } from "./exercise.serialization";
|
5 |
-
import { WorkoutSerialization } from "./workout.serialization";
|
6 |
-
import { UserSerialization } from "./user.serialization";
|
7 |
|
8 |
|
9 |
class MyWorkoutDaysPopulate {
|
@@ -51,42 +49,65 @@ class MyWorkoutWeeksPopulate {
|
|
51 |
is_done: Boolean;
|
52 |
}
|
53 |
|
54 |
-
|
55 |
@Expose({ name: "_id" })
|
56 |
@SwaggerResponseProperty({ type: "string" })
|
57 |
id: string;
|
58 |
|
59 |
@Expose()
|
60 |
@SwaggerResponseProperty({ type: "string" })
|
61 |
-
|
62 |
|
63 |
@Expose()
|
64 |
-
@SwaggerResponseProperty({ type:
|
65 |
-
|
66 |
|
67 |
@Expose()
|
68 |
-
@SwaggerResponseProperty({ type: "
|
69 |
-
|
70 |
|
71 |
-
@Expose(
|
72 |
-
@SwaggerResponseProperty({ type:
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
|
|
|
|
|
|
77 |
|
|
|
78 |
|
79 |
-
export class
|
80 |
@Expose({ name: "_id" })
|
81 |
@SwaggerResponseProperty({ type: "string" })
|
82 |
id: string;
|
83 |
|
84 |
@Expose()
|
85 |
-
@SwaggerResponseProperty({ type:
|
86 |
-
user:
|
87 |
|
88 |
@Expose()
|
89 |
-
@SwaggerResponseProperty({ type:
|
|
|
90 |
workout: string;
|
91 |
|
92 |
@Expose()
|
@@ -97,4 +118,4 @@ export class UserRegisteredWorkoutsPopulateUserSerialization {
|
|
97 |
@SwaggerResponseProperty({ type: [MyWorkoutWeeksPopulate] })
|
98 |
@Transform(({ value }) => serialize(value, MyWorkoutWeeksPopulate))
|
99 |
weeks: any;
|
100 |
-
}
|
|
|
2 |
import { serialize } from "@helpers/serialize";
|
3 |
import { SwaggerResponseProperty } from "@lib/decorators/swagger-response-property.decorator";
|
4 |
import { ExerciseSerialization } from "./exercise.serialization";
|
|
|
|
|
5 |
|
6 |
|
7 |
class MyWorkoutDaysPopulate {
|
|
|
49 |
is_done: Boolean;
|
50 |
}
|
51 |
|
52 |
+
class Workout {
|
53 |
@Expose({ name: "_id" })
|
54 |
@SwaggerResponseProperty({ type: "string" })
|
55 |
id: string;
|
56 |
|
57 |
@Expose()
|
58 |
@SwaggerResponseProperty({ type: "string" })
|
59 |
+
name: string;
|
60 |
|
61 |
@Expose()
|
62 |
+
@SwaggerResponseProperty({ type: "string" })
|
63 |
+
description: string;
|
64 |
|
65 |
@Expose()
|
66 |
+
@SwaggerResponseProperty({ type: "string" })
|
67 |
+
type: string;
|
68 |
|
69 |
+
@Expose()
|
70 |
+
@SwaggerResponseProperty({ type: "string" })
|
71 |
+
image: string;
|
72 |
+
|
73 |
+
@Expose()
|
74 |
+
@SwaggerResponseProperty({ type: "string" })
|
75 |
+
created_by: string;
|
76 |
+
|
77 |
+
@Expose()
|
78 |
+
@SwaggerResponseProperty({ type: "string" })
|
79 |
+
fitness_level: string;
|
80 |
+
|
81 |
+
@Expose()
|
82 |
+
@SwaggerResponseProperty({ type: "string" })
|
83 |
+
fitness_goal: string;
|
84 |
+
|
85 |
+
@Expose()
|
86 |
+
@SwaggerResponseProperty({ type: "string" })
|
87 |
+
place: any;
|
88 |
+
|
89 |
+
@Expose()
|
90 |
+
@SwaggerResponseProperty({ type: "number" })
|
91 |
+
min_per_day: number;
|
92 |
|
93 |
+
@Expose()
|
94 |
+
@SwaggerResponseProperty({ type: "number" })
|
95 |
+
total_number_days: number;
|
96 |
|
97 |
+
}
|
98 |
|
99 |
+
export class UserRegisteredWorkoutsPopulateSerialization {
|
100 |
@Expose({ name: "_id" })
|
101 |
@SwaggerResponseProperty({ type: "string" })
|
102 |
id: string;
|
103 |
|
104 |
@Expose()
|
105 |
+
@SwaggerResponseProperty({ type: "string" })
|
106 |
+
user: string;
|
107 |
|
108 |
@Expose()
|
109 |
+
@SwaggerResponseProperty({ type: Workout })
|
110 |
+
@Transform(({ value }) => serialize(value, Workout))
|
111 |
workout: string;
|
112 |
|
113 |
@Expose()
|
|
|
118 |
@SwaggerResponseProperty({ type: [MyWorkoutWeeksPopulate] })
|
119 |
@Transform(({ value }) => serialize(value, MyWorkoutWeeksPopulate))
|
120 |
weeks: any;
|
121 |
+
}
|
src/lib/services/crud.service.ts
CHANGED
@@ -123,12 +123,14 @@ export const CrudService = <ModelDoc extends Document>(
|
|
123 |
async findOneOrFail(
|
124 |
filter: FilterQuery<ModelDoc>,
|
125 |
options?: {
|
126 |
-
populateArray
|
|
|
127 |
}
|
128 |
): Promise<ModelDoc> {
|
129 |
await this.existsOrThrow(filter);
|
130 |
const queryInstruction = this.model.findOne(filter);
|
131 |
if (options?.populateArray) queryInstruction.populate(options.populateArray);
|
|
|
132 |
const document = await queryInstruction;
|
133 |
return document;
|
134 |
}
|
|
|
123 |
async findOneOrFail(
|
124 |
filter: FilterQuery<ModelDoc>,
|
125 |
options?: {
|
126 |
+
populateArray?: any,
|
127 |
+
selectArray?: any
|
128 |
}
|
129 |
): Promise<ModelDoc> {
|
130 |
await this.existsOrThrow(filter);
|
131 |
const queryInstruction = this.model.findOne(filter);
|
132 |
if (options?.populateArray) queryInstruction.populate(options.populateArray);
|
133 |
+
if (options?.selectArray) queryInstruction.select(options.selectArray);
|
134 |
const document = await queryInstruction;
|
135 |
return document;
|
136 |
}
|
src/modules/users/modules/exercises/controllers/exercises.controller.ts
CHANGED
@@ -33,7 +33,6 @@ export class UsersExerciseController extends BaseController {
|
|
33 |
@SwaggerDescription("List all exercises")
|
34 |
@SwaggerQuery({
|
35 |
limit: "number",
|
36 |
-
|
37 |
})
|
38 |
list = async (req: Request, res: Response): Promise<Response> => {
|
39 |
const paginationQuery = parsePaginationQuery(req.query);
|
@@ -60,7 +59,7 @@ export class UsersExerciseController extends BaseController {
|
|
60 |
|
61 |
@SwaggerGet("/:id")
|
62 |
@SwaggerResponse(ExercisePopulateSerialization)
|
63 |
-
@SwaggerSummary("
|
64 |
@SwaggerDescription("Get a single exercise")
|
65 |
get = async (req: Request, res: Response): Promise<Response> => {
|
66 |
const data = await this.exercisesService.findOneOrFail(
|
|
|
33 |
@SwaggerDescription("List all exercises")
|
34 |
@SwaggerQuery({
|
35 |
limit: "number",
|
|
|
36 |
})
|
37 |
list = async (req: Request, res: Response): Promise<Response> => {
|
38 |
const paginationQuery = parsePaginationQuery(req.query);
|
|
|
59 |
|
60 |
@SwaggerGet("/:id")
|
61 |
@SwaggerResponse(ExercisePopulateSerialization)
|
62 |
+
@SwaggerSummary("instructions-workout && target muscle-workout")
|
63 |
@SwaggerDescription("Get a single exercise")
|
64 |
get = async (req: Request, res: Response): Promise<Response> => {
|
65 |
const data = await this.exercisesService.findOneOrFail(
|
src/modules/users/modules/home/controllers/home.controller.ts
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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";
|
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 { 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"] }
|
44 |
+
)
|
45 |
+
|
46 |
+
const myWorkout = await this.userRegisteredWorkoutsService.findOneOrFail(
|
47 |
+
{ user: req.jwtPayload.id, is_active: true },
|
48 |
+
{
|
49 |
+
populateArray: [
|
50 |
+
{ path: "workout", select: ["name", "min_per_day"] },
|
51 |
+
],
|
52 |
+
selectArray: ["-weeks.week_description", "-weeks.week_name", "-weeks.days.exercises", "-user"],
|
53 |
+
},
|
54 |
+
)
|
55 |
+
const data = {
|
56 |
+
user: user,
|
57 |
+
myWorkout: myWorkout,
|
58 |
+
myMealPlan: {}
|
59 |
+
}
|
60 |
+
|
61 |
+
return JsonResponse.success(
|
62 |
+
{
|
63 |
+
data: serialize(data, HomeSerialization)
|
64 |
+
},
|
65 |
+
res
|
66 |
+
);
|
67 |
+
};
|
68 |
+
|
69 |
+
}
|
src/modules/users/modules/templates/controllers/templates.controller.ts
CHANGED
@@ -43,7 +43,7 @@ export class templateController extends BaseController {
|
|
43 |
|
44 |
@SwaggerGet()
|
45 |
@SwaggerResponse([TemplatePopulateSerialization])
|
46 |
-
@SwaggerSummary("
|
47 |
@SwaggerDescription("List all custom plans created by the user logged in")
|
48 |
list = async (req: userRequest, res: Response): Promise<Response> => {
|
49 |
const paginationQuery = parsePaginationQuery(req.query);
|
|
|
43 |
|
44 |
@SwaggerGet()
|
45 |
@SwaggerResponse([TemplatePopulateSerialization])
|
46 |
+
@SwaggerSummary("my trainer --> custom workout")
|
47 |
@SwaggerDescription("List all custom plans created by the user logged in")
|
48 |
list = async (req: userRequest, res: Response): Promise<Response> => {
|
49 |
const paginationQuery = parsePaginationQuery(req.query);
|
src/modules/users/modules/user-registered-workouts/controllers/user-registered-workouts.controller.ts
CHANGED
@@ -8,7 +8,7 @@ import { BaseController } from "@lib/controllers/controller.base";
|
|
8 |
import { Controller } from "@lib/decorators/controller.decorator";
|
9 |
import { serialize } from "@helpers/serialize";
|
10 |
import { UserRegisteredWorkoutsSerialization } from "@common/serializers/user-registered-workout.serialization";
|
11 |
-
import { UserRegisteredWorkoutsPopulateSerialization
|
12 |
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
13 |
import { UsersGuardMiddleware } from "modules/users/common/guards/users.guard";
|
14 |
import { createUserRegisteredWorkoutsSchema } from "../validations/create-user-registered-workouts.validation";
|
@@ -19,7 +19,7 @@ import {
|
|
19 |
import { SwaggerSummary } from "@lib/decorators/swagger-summary.decorator";
|
20 |
import { SwaggerDescription } from "@lib/decorators/swagger-description.decorator";
|
21 |
import { SwaggerResponse } from "@lib/decorators/swagger-response.decorator";
|
22 |
-
import { SwaggerRequest } from "@lib/decorators/swagger-request.decorator";4
|
23 |
|
24 |
|
25 |
interface userRequest extends Request {
|
@@ -32,57 +32,52 @@ export class userRegisteredWorkoutsController extends BaseController {
|
|
32 |
private userRegisteredWorkoutsService = new UserRegisteredWorkoutsService();
|
33 |
|
34 |
setRoutes(): void {
|
35 |
-
this.router.get("/:id",
|
36 |
-
this.router.get(
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
)
|
41 |
-
|
42 |
-
this.router.post(
|
43 |
-
"/",
|
44 |
-
bodyValidator(createUserRegisteredWorkoutsSchema),
|
45 |
-
asyncHandler(this.create)
|
46 |
-
);
|
47 |
}
|
48 |
|
49 |
-
@SwaggerGet()
|
50 |
-
@SwaggerResponse([UserRegisteredWorkoutsPopulateSerialization])
|
51 |
-
@SwaggerSummary("List my workouts")
|
52 |
-
@SwaggerDescription("List all user registered workouts (workouts that the user had started)")
|
53 |
-
list = async (req: userRequest, res: Response) => {
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
};
|
75 |
|
76 |
@SwaggerGet("/:id")
|
77 |
@SwaggerResponse(UserRegisteredWorkoutsPopulateSerialization)
|
78 |
-
@SwaggerSummary("
|
79 |
@SwaggerDescription("Get a single workout from user registered workouts (workouts that the user had started)")
|
80 |
get = async (req: userRequest, res: Response) => {
|
81 |
const data = await this.userRegisteredWorkoutsService.findOneOrFail(
|
82 |
{ _id: req.params.id },
|
83 |
{
|
84 |
populateArray: [
|
85 |
-
{ path: "workout" },
|
86 |
{ path: "weeks.days.exercises" },
|
87 |
],
|
88 |
}
|
@@ -95,43 +90,20 @@ export class userRegisteredWorkoutsController extends BaseController {
|
|
95 |
);
|
96 |
};
|
97 |
|
98 |
-
@SwaggerGet("/home/:userId")
|
99 |
-
@SwaggerResponse(UserRegisteredWorkoutsPopulateUserSerialization)
|
100 |
-
@SwaggerSummary("Get home page")
|
101 |
-
@SwaggerDescription("Get the home page for the user")
|
102 |
-
getHomePage = async (req: userRequest, res: Response) => {
|
103 |
-
|
104 |
-
const data = await this.userRegisteredWorkoutsService.findOneOrFail(
|
105 |
-
{ user: req.params.userId },
|
106 |
-
{
|
107 |
-
populateArray: [
|
108 |
-
{ path: "workout" },
|
109 |
-
{ path: "weeks.days.exercises" },
|
110 |
-
{ path: "user" },
|
111 |
-
],
|
112 |
-
}
|
113 |
-
);
|
114 |
-
return JsonResponse.success(
|
115 |
-
{
|
116 |
-
data: serialize(data.toJSON(), UserRegisteredWorkoutsPopulateUserSerialization),
|
117 |
-
},
|
118 |
-
res
|
119 |
-
);
|
120 |
-
};
|
121 |
|
122 |
-
@SwaggerPost()
|
123 |
-
@SwaggerResponse(UserRegisteredWorkoutsSerialization)
|
124 |
-
@SwaggerRequest(createUserRegisteredWorkoutsSchema)
|
125 |
-
@SwaggerSummary("Create workout")
|
126 |
-
@SwaggerDescription("Create a new workout for the user")
|
127 |
-
create = async (req: userRequest, res: Response) => {
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
};
|
137 |
}
|
|
|
8 |
import { Controller } from "@lib/decorators/controller.decorator";
|
9 |
import { serialize } from "@helpers/serialize";
|
10 |
import { UserRegisteredWorkoutsSerialization } from "@common/serializers/user-registered-workout.serialization";
|
11 |
+
import { UserRegisteredWorkoutsPopulateSerialization } from "@common/serializers/user-registered-workoutPopulate.serialization";
|
12 |
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
13 |
import { UsersGuardMiddleware } from "modules/users/common/guards/users.guard";
|
14 |
import { createUserRegisteredWorkoutsSchema } from "../validations/create-user-registered-workouts.validation";
|
|
|
19 |
import { SwaggerSummary } from "@lib/decorators/swagger-summary.decorator";
|
20 |
import { SwaggerDescription } from "@lib/decorators/swagger-description.decorator";
|
21 |
import { SwaggerResponse } from "@lib/decorators/swagger-response.decorator";
|
22 |
+
import { SwaggerRequest } from "@lib/decorators/swagger-request.decorator"; 4
|
23 |
|
24 |
|
25 |
interface userRequest extends Request {
|
|
|
32 |
private userRegisteredWorkoutsService = new UserRegisteredWorkoutsService();
|
33 |
|
34 |
setRoutes(): void {
|
35 |
+
this.router.get("/:id", asyncHandler(this.get));
|
36 |
+
// this.router.get("/", asyncHandler(this.list));
|
37 |
+
// this.router.post(
|
38 |
+
// "/",
|
39 |
+
// bodyValidator(createUserRegisteredWorkoutsSchema),
|
40 |
+
// asyncHandler(this.create)
|
41 |
+
// );
|
|
|
|
|
|
|
|
|
|
|
42 |
}
|
43 |
|
44 |
+
// @SwaggerGet()
|
45 |
+
// @SwaggerResponse([UserRegisteredWorkoutsPopulateSerialization])
|
46 |
+
// @SwaggerSummary("List my workouts")
|
47 |
+
// @SwaggerDescription("List all user registered workouts (workouts that the user had started)")
|
48 |
+
// list = async (req: userRequest, res: Response) => {
|
49 |
+
// const paginationQuery = parsePaginationQuery(req.query);
|
50 |
+
// const { docs, paginationData } =
|
51 |
+
// await this.userRegisteredWorkoutsService.list(
|
52 |
+
// { user: req.jwtPayload.id, is_active: true },
|
53 |
+
// paginationQuery,
|
54 |
+
// {
|
55 |
+
// populateArray: [
|
56 |
+
// { path: "workout" },
|
57 |
+
// { path: "weeks.days.exercises" },
|
58 |
+
// ],
|
59 |
+
// }
|
60 |
+
// );
|
61 |
|
62 |
+
// return JsonResponse.success(
|
63 |
+
// {
|
64 |
+
// data: serialize(docs, UserRegisteredWorkoutsPopulateSerialization),
|
65 |
+
// meta: paginationData,
|
66 |
+
// },
|
67 |
+
// res
|
68 |
+
// );
|
69 |
+
// };
|
70 |
|
71 |
@SwaggerGet("/:id")
|
72 |
@SwaggerResponse(UserRegisteredWorkoutsPopulateSerialization)
|
73 |
+
@SwaggerSummary("today's workout && my trainer --> my plan && weekly")
|
74 |
@SwaggerDescription("Get a single workout from user registered workouts (workouts that the user had started)")
|
75 |
get = async (req: userRequest, res: Response) => {
|
76 |
const data = await this.userRegisteredWorkoutsService.findOneOrFail(
|
77 |
{ _id: req.params.id },
|
78 |
{
|
79 |
populateArray: [
|
80 |
+
{ path: "workout", select: ["-weeks"] },
|
81 |
{ path: "weeks.days.exercises" },
|
82 |
],
|
83 |
}
|
|
|
90 |
);
|
91 |
};
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
+
// @SwaggerPost()
|
95 |
+
// @SwaggerResponse(UserRegisteredWorkoutsSerialization)
|
96 |
+
// @SwaggerRequest(createUserRegisteredWorkoutsSchema)
|
97 |
+
// @SwaggerSummary("Create workout")
|
98 |
+
// @SwaggerDescription("Create a new workout for the user")
|
99 |
+
// create = async (req: userRequest, res: Response) => {
|
100 |
+
// const data = await this.userRegisteredWorkoutsService.create(req.body);
|
101 |
+
// return JsonResponse.success(
|
102 |
+
// {
|
103 |
+
// status: 201,
|
104 |
+
// data: serialize(data.toJSON(), UserRegisteredWorkoutsSerialization),
|
105 |
+
// },
|
106 |
+
// res
|
107 |
+
// );
|
108 |
+
// };
|
109 |
}
|