Spaces:
Running
Running
Hozifa Elgharbawy
commited on
Commit
·
86f4808
1
Parent(s):
ec62c39
create myWorkout module
Browse files- src/common/models/workout.model.ts +8 -6
- src/common/serializers/{exercise.serializtion.ts → exercise.serialization.ts} +0 -0
- src/common/serializers/{workout.serializtion.ts → workout.serialization.ts} +3 -0
- src/lib/services/crud.service.ts +19 -7
- src/modules/console/modules/workouts/controllers/workouts.controller.ts +1 -1
- src/modules/console/modules/workouts/validations/create-workout.validation.ts +3 -3
- src/modules/console/modules/workouts/validations/update-workout.validation.ts +3 -3
- src/modules/users/common/models/user-registered-workout.model.ts +46 -0
- src/modules/users/common/serializers/user-registered-workout.serialization.ts +45 -0
- src/modules/users/modules/auth/controllers/auth.controller.ts +1 -1
- src/modules/users/modules/exercises/controllers/exercises.controller.ts +2 -2
- src/modules/users/modules/user-registered-workouts/controllers/user-registered-workouts.controller.ts +102 -0
- src/modules/users/modules/user-registered-workouts/services/user-registered-workouts.service.ts +4 -0
- src/modules/users/modules/user-registered-workouts/validations/create-user-registered-workouts.validation.ts +79 -0
- src/modules/users/modules/user-registered-workouts/validations/update-user-registered-workouts.validation.ts +71 -0
- src/modules/users/modules/workouts/controllers/workouts.controller.ts +2 -2
src/common/models/workout.model.ts
CHANGED
@@ -3,18 +3,19 @@ const { Schema } = mongoose;
|
|
3 |
|
4 |
export interface IWorkout {
|
5 |
name: string;
|
|
|
6 |
type: string;
|
7 |
created_by: mongoose.Types.ObjectId;
|
|
|
8 |
templateWeeks: [
|
9 |
{
|
|
|
|
|
|
|
10 |
days: [
|
11 |
{
|
12 |
-
|
13 |
-
exercises: [
|
14 |
-
{
|
15 |
-
exercise: mongoose.Types.ObjectId,
|
16 |
-
},
|
17 |
-
],
|
18 |
},
|
19 |
],
|
20 |
},
|
@@ -25,6 +26,7 @@ const workoutSchema = new Schema({
|
|
25 |
name: { type: String, required: true, unique: true, dropDups: true },
|
26 |
type: { type: String, required: true },
|
27 |
created_by: { type: mongoose.Types.ObjectId, ref: "admins" },
|
|
|
28 |
templateWeeks: [
|
29 |
{
|
30 |
days: [
|
|
|
3 |
|
4 |
export interface IWorkout {
|
5 |
name: string;
|
6 |
+
description: string;
|
7 |
type: string;
|
8 |
created_by: mongoose.Types.ObjectId;
|
9 |
+
image: object;
|
10 |
templateWeeks: [
|
11 |
{
|
12 |
+
weekNumber: number;
|
13 |
+
name: string,
|
14 |
+
description: string,
|
15 |
days: [
|
16 |
{
|
17 |
+
dayNumber: number,
|
18 |
+
exercises: [mongoose.Types.ObjectId],
|
|
|
|
|
|
|
|
|
19 |
},
|
20 |
],
|
21 |
},
|
|
|
26 |
name: { type: String, required: true, unique: true, dropDups: true },
|
27 |
type: { type: String, required: true },
|
28 |
created_by: { type: mongoose.Types.ObjectId, ref: "admins" },
|
29 |
+
image: { type: Object },
|
30 |
templateWeeks: [
|
31 |
{
|
32 |
days: [
|
src/common/serializers/{exercise.serializtion.ts → exercise.serialization.ts}
RENAMED
File without changes
|
src/common/serializers/{workout.serializtion.ts → workout.serialization.ts}
RENAMED
@@ -30,6 +30,9 @@ export class WorkoutSerialization {
|
|
30 |
@Expose()
|
31 |
type: string;
|
32 |
|
|
|
|
|
|
|
33 |
@Expose()
|
34 |
created_by: string;
|
35 |
|
|
|
30 |
@Expose()
|
31 |
type: string;
|
32 |
|
33 |
+
@Expose()
|
34 |
+
image: object;
|
35 |
+
|
36 |
@Expose()
|
37 |
created_by: string;
|
38 |
|
src/lib/services/crud.service.ts
CHANGED
@@ -45,7 +45,7 @@ export const CrudService = <ModelDoc extends Document>(
|
|
45 |
skip: 0,
|
46 |
},
|
47 |
options?: {
|
48 |
-
|
49 |
}
|
50 |
): Promise<{
|
51 |
docs: ModelDoc[];
|
@@ -59,7 +59,7 @@ export const CrudService = <ModelDoc extends Document>(
|
|
59 |
.find(filter)
|
60 |
.limit(paginationOptions.limit)
|
61 |
.skip(paginationOptions.skip)
|
62 |
-
if (options?.
|
63 |
|
64 |
const docs = await queryInstruction
|
65 |
const total = await this.model.countDocuments(filter);
|
@@ -72,14 +72,26 @@ export const CrudService = <ModelDoc extends Document>(
|
|
72 |
return { docs, paginationData };
|
73 |
}
|
74 |
|
75 |
-
async findOne(
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
}
|
78 |
|
79 |
-
async findOneOrFail(
|
|
|
|
|
|
|
|
|
|
|
80 |
await this.existsOrThrow(filter);
|
81 |
-
|
82 |
-
|
83 |
return document;
|
84 |
}
|
85 |
|
|
|
45 |
skip: 0,
|
46 |
},
|
47 |
options?: {
|
48 |
+
populateArray: any
|
49 |
}
|
50 |
): Promise<{
|
51 |
docs: ModelDoc[];
|
|
|
59 |
.find(filter)
|
60 |
.limit(paginationOptions.limit)
|
61 |
.skip(paginationOptions.skip)
|
62 |
+
if (options?.populateArray) queryInstruction.populate(options.populateArray);
|
63 |
|
64 |
const docs = await queryInstruction
|
65 |
const total = await this.model.countDocuments(filter);
|
|
|
72 |
return { docs, paginationData };
|
73 |
}
|
74 |
|
75 |
+
async findOne(
|
76 |
+
filter: FilterQuery<ModelDoc>,
|
77 |
+
options?: {
|
78 |
+
populateArray: any
|
79 |
+
}): Promise<ModelDoc | null> {
|
80 |
+
const queryInstruction = this.model.findOne(filter);
|
81 |
+
if (options?.populateArray) queryInstruction.populate(options.populateArray);
|
82 |
+
const document = await queryInstruction
|
83 |
+
return document;
|
84 |
}
|
85 |
|
86 |
+
async findOneOrFail(
|
87 |
+
filter: FilterQuery<ModelDoc>,
|
88 |
+
options?: {
|
89 |
+
populateArray: any
|
90 |
+
}
|
91 |
+
): Promise<ModelDoc> {
|
92 |
await this.existsOrThrow(filter);
|
93 |
+
let optionsObject = options ? options : { populateArray: [{}] }
|
94 |
+
const document = await this.findOne(filter, optionsObject);
|
95 |
return document;
|
96 |
}
|
97 |
|
src/modules/console/modules/workouts/controllers/workouts.controller.ts
CHANGED
@@ -9,7 +9,7 @@ import { updateWorkoutSchema } from "../validations/update-workout.validation";
|
|
9 |
import { BaseController } from "@lib/controllers/controller.base";
|
10 |
import { Prefix } from "@lib/decorators/prefix.decorator";
|
11 |
import { serialize } from "@helpers/serialize";
|
12 |
-
import { WorkoutSerialization } from "@common/serializers/workout.
|
13 |
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
14 |
import { AdminGuardMiddleware } from "modules/console/common/guards/admins.guard";
|
15 |
|
|
|
9 |
import { BaseController } from "@lib/controllers/controller.base";
|
10 |
import { Prefix } from "@lib/decorators/prefix.decorator";
|
11 |
import { serialize } from "@helpers/serialize";
|
12 |
+
import { WorkoutSerialization } from "@common/serializers/workout.serialization";
|
13 |
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
14 |
import { AdminGuardMiddleware } from "modules/console/common/guards/admins.guard";
|
15 |
|
src/modules/console/modules/workouts/validations/create-workout.validation.ts
CHANGED
@@ -5,7 +5,7 @@ export interface ICreateWorkout {
|
|
5 |
name: string;
|
6 |
type: string;
|
7 |
created_by: string;
|
8 |
-
templateWeeks:
|
9 |
};
|
10 |
|
11 |
|
@@ -26,8 +26,8 @@ export const createWorkoutSchema = createSchema<ICreateWorkout>({
|
|
26 |
"string.empty": "created_by can not be empty",
|
27 |
}),
|
28 |
templateWeeks: joi.array().empty().required().messages({
|
29 |
-
"
|
30 |
"any.required": "templateWeeks is required",
|
31 |
-
"
|
32 |
}),
|
33 |
});
|
|
|
5 |
name: string;
|
6 |
type: string;
|
7 |
created_by: string;
|
8 |
+
templateWeeks: object[];
|
9 |
};
|
10 |
|
11 |
|
|
|
26 |
"string.empty": "created_by can not be empty",
|
27 |
}),
|
28 |
templateWeeks: joi.array().empty().required().messages({
|
29 |
+
"array.base": "please enter a valid templateWeeks",
|
30 |
"any.required": "templateWeeks is required",
|
31 |
+
"array.empty": "templateWeeks can not be empty",
|
32 |
}),
|
33 |
});
|
src/modules/console/modules/workouts/validations/update-workout.validation.ts
CHANGED
@@ -5,7 +5,7 @@ export interface IUpdateWorkout {
|
|
5 |
name?: string;
|
6 |
type?: string;
|
7 |
created_by?: string;
|
8 |
-
templateWeeks?:
|
9 |
};
|
10 |
|
11 |
|
@@ -23,8 +23,8 @@ export const updateWorkoutSchema = createSchema<IUpdateWorkout>({
|
|
23 |
"string.empty": "created_by can not be empty",
|
24 |
}),
|
25 |
templateWeeks: joi.array().empty().optional().messages({
|
26 |
-
"
|
27 |
-
"
|
28 |
}),
|
29 |
|
30 |
});
|
|
|
5 |
name?: string;
|
6 |
type?: string;
|
7 |
created_by?: string;
|
8 |
+
templateWeeks?: object[];
|
9 |
};
|
10 |
|
11 |
|
|
|
23 |
"string.empty": "created_by can not be empty",
|
24 |
}),
|
25 |
templateWeeks: joi.array().empty().optional().messages({
|
26 |
+
"array.base": "please enter a valid templateWeeks",
|
27 |
+
"array.empty": "templateWeeks can not be empty",
|
28 |
}),
|
29 |
|
30 |
});
|
src/modules/users/common/models/user-registered-workout.model.ts
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import mongoose from "mongoose";
|
2 |
+
const { Schema } = mongoose;
|
3 |
+
|
4 |
+
export interface IUserRegisteredWorkout {
|
5 |
+
user: mongoose.Types.ObjectId,
|
6 |
+
workout: mongoose.Types.ObjectId,
|
7 |
+
isActive: Boolean,
|
8 |
+
weeks: [
|
9 |
+
{
|
10 |
+
weekNumber: number,
|
11 |
+
name: string,
|
12 |
+
description: string,
|
13 |
+
days: [
|
14 |
+
{
|
15 |
+
dayNumber: number,
|
16 |
+
exercises: [mongoose.Types.ObjectId],
|
17 |
+
isDone: Boolean
|
18 |
+
},
|
19 |
+
],
|
20 |
+
},
|
21 |
+
]
|
22 |
+
}
|
23 |
+
|
24 |
+
const userRegisteredWorkoutSchema = new Schema({
|
25 |
+
user: { type: mongoose.Types.ObjectId, ref: "users" },
|
26 |
+
workout: { type: mongoose.Types.ObjectId, ref: "workouts" },
|
27 |
+
isActive: { type: Boolean, default: false },
|
28 |
+
weeks: [
|
29 |
+
{
|
30 |
+
days: [
|
31 |
+
{
|
32 |
+
day: Number,
|
33 |
+
exercises: [
|
34 |
+
{ type: mongoose.Types.ObjectId, ref: "exercises" },
|
35 |
+
],
|
36 |
+
isDone: { type: Boolean, default: false }
|
37 |
+
},
|
38 |
+
],
|
39 |
+
},
|
40 |
+
]
|
41 |
+
});
|
42 |
+
|
43 |
+
|
44 |
+
export type UserRegisteredWorkoutDocument = IUserRegisteredWorkout & mongoose.Document;
|
45 |
+
|
46 |
+
export const UserRegisteredWorkout = mongoose.model<UserRegisteredWorkoutDocument>("UserRegisteredWorkouts", userRegisteredWorkoutSchema);
|
src/modules/users/common/serializers/user-registered-workout.serialization.ts
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Expose, Transform } from "class-transformer";
|
2 |
+
import { serialize } from "@helpers/serialize";
|
3 |
+
|
4 |
+
|
5 |
+
|
6 |
+
class Days {
|
7 |
+
@Expose()
|
8 |
+
day: number;
|
9 |
+
|
10 |
+
@Expose({ name: "exercises" })
|
11 |
+
exercises: any;
|
12 |
+
|
13 |
+
@Expose()
|
14 |
+
isDone: Boolean
|
15 |
+
}
|
16 |
+
|
17 |
+
|
18 |
+
class Weeks {
|
19 |
+
@Expose({ name: "days" })
|
20 |
+
@Transform(
|
21 |
+
({ value }) => serialize(value, Days)
|
22 |
+
)
|
23 |
+
days: any;
|
24 |
+
}
|
25 |
+
|
26 |
+
export class UserRegisteredWorkoutsSerialization {
|
27 |
+
@Expose({ name: "_id" })
|
28 |
+
id: string;
|
29 |
+
|
30 |
+
@Expose()
|
31 |
+
user: string;
|
32 |
+
|
33 |
+
@Expose()
|
34 |
+
workout: string;
|
35 |
+
|
36 |
+
@Expose()
|
37 |
+
isActive: Boolean;
|
38 |
+
|
39 |
+
@Expose({ name: "weeks" })
|
40 |
+
@Transform(
|
41 |
+
({ value }) => serialize(value, Weeks)
|
42 |
+
)
|
43 |
+
weeks: any;
|
44 |
+
|
45 |
+
}
|
src/modules/users/modules/auth/controllers/auth.controller.ts
CHANGED
@@ -13,7 +13,7 @@ import { serialize } from "@helpers/serialize";
|
|
13 |
import { UserSerialization } from "@common/serializers/user.serialization";
|
14 |
import { UsersAuthService } from "../services/users-auth.service";
|
15 |
|
16 |
-
@Prefix("/
|
17 |
export class UsersAuthController extends BaseController {
|
18 |
private authService = new UsersAuthService();
|
19 |
|
|
|
13 |
import { UserSerialization } from "@common/serializers/user.serialization";
|
14 |
import { UsersAuthService } from "../services/users-auth.service";
|
15 |
|
16 |
+
@Prefix("/user/auth")
|
17 |
export class UsersAuthController extends BaseController {
|
18 |
private authService = new UsersAuthService();
|
19 |
|
src/modules/users/modules/exercises/controllers/exercises.controller.ts
CHANGED
@@ -7,11 +7,11 @@ import { paramsValidator } from "@helpers/validation.helper";
|
|
7 |
import { BaseController } from "@lib/controllers/controller.base";
|
8 |
import { Prefix } from "@lib/decorators/prefix.decorator";
|
9 |
import { serialize } from "@helpers/serialize";
|
10 |
-
import { ExerciseSerialization } from "@common/serializers/exercise.
|
11 |
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
12 |
import { UsersGuardMiddleware } from "modules/users/common/guards/users.guard";
|
13 |
|
14 |
-
@Prefix("/
|
15 |
@ControllerMiddleware(UsersGuardMiddleware())
|
16 |
export class ExerciseController extends BaseController {
|
17 |
private exercisesService = new ExerciseService();
|
|
|
7 |
import { BaseController } from "@lib/controllers/controller.base";
|
8 |
import { Prefix } from "@lib/decorators/prefix.decorator";
|
9 |
import { serialize } from "@helpers/serialize";
|
10 |
+
import { ExerciseSerialization } from "@common/serializers/exercise.serialization";
|
11 |
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
12 |
import { UsersGuardMiddleware } from "modules/users/common/guards/users.guard";
|
13 |
|
14 |
+
@Prefix("/user/exercises")
|
15 |
@ControllerMiddleware(UsersGuardMiddleware())
|
16 |
export class ExerciseController extends BaseController {
|
17 |
private exercisesService = new ExerciseService();
|
src/modules/users/modules/user-registered-workouts/controllers/user-registered-workouts.controller.ts
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { UserRegisteredWorkoutsService } from "../services/user-registered-workouts.service";
|
2 |
+
import { Request, Response } from "express";
|
3 |
+
import { JsonResponse } from "@lib/responses/json-response";
|
4 |
+
import { parsePaginationQuery } from "@helpers/pagination";
|
5 |
+
import { paramsValidator, bodyValidator } from "@helpers/validation.helper";
|
6 |
+
import { asyncHandler } from "@helpers/async-handler";
|
7 |
+
import { BaseController } from "@lib/controllers/controller.base";
|
8 |
+
import { Prefix } from "@lib/decorators/prefix.decorator";
|
9 |
+
import { serialize } from "@helpers/serialize";
|
10 |
+
import { UserRegisteredWorkoutsSerialization } from "../../../common/serializers/user-registered-workout.serialization";
|
11 |
+
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
12 |
+
import { UsersGuardMiddleware } from "modules/users/common/guards/users.guard";
|
13 |
+
import { createUserRegisteredWorkoutsSchema } from "../validations/create-user-registered-workouts.validation";
|
14 |
+
import { updateUserRegisteredWorkoutsSchema } from "../validations/update-user-registered-workouts.validation";
|
15 |
+
|
16 |
+
interface userRequest extends Request {
|
17 |
+
jwtPayload?: any;
|
18 |
+
}
|
19 |
+
|
20 |
+
@Prefix("/user/myWorkouts")
|
21 |
+
@ControllerMiddleware(UsersGuardMiddleware())
|
22 |
+
export class userRegisteredWorkoutsController extends BaseController {
|
23 |
+
private userRegisteredWorkoutsService = new UserRegisteredWorkoutsService();
|
24 |
+
|
25 |
+
setRoutes(): void {
|
26 |
+
this.router.get("/get/:id", paramsValidator("id"), asyncHandler(this.get));
|
27 |
+
this.router.get("/list/:userId", paramsValidator("userId"), asyncHandler(this.list));
|
28 |
+
this.router.post("/",
|
29 |
+
bodyValidator(createUserRegisteredWorkoutsSchema),
|
30 |
+
asyncHandler(this.create));
|
31 |
+
|
32 |
+
this.router.patch("/",
|
33 |
+
bodyValidator(updateUserRegisteredWorkoutsSchema),
|
34 |
+
asyncHandler(this.update));
|
35 |
+
}
|
36 |
+
|
37 |
+
list = async (req: userRequest, res: Response) => {
|
38 |
+
const paginationQuery = parsePaginationQuery(req.query);
|
39 |
+
// if (req.jwtPayload.id != req.params.userId) console.log(req.jwtPayload);
|
40 |
+
|
41 |
+
const { docs, paginationData } = await this.userRegisteredWorkoutsService.list(
|
42 |
+
{ user: req.params.userId },
|
43 |
+
paginationQuery,
|
44 |
+
{
|
45 |
+
populateArray: [
|
46 |
+
{ path: "workout", select: "-templateWeeks -created_by" },
|
47 |
+
{ path: "weeks.days.exercises" },
|
48 |
+
]
|
49 |
+
}
|
50 |
+
);
|
51 |
+
|
52 |
+
return JsonResponse.success(
|
53 |
+
{
|
54 |
+
data: serialize(docs, UserRegisteredWorkoutsSerialization),
|
55 |
+
meta: paginationData,
|
56 |
+
},
|
57 |
+
res
|
58 |
+
);
|
59 |
+
};
|
60 |
+
|
61 |
+
get = async (req: userRequest, res: Response) => {
|
62 |
+
const data = await this.userRegisteredWorkoutsService.findOneOrFail(
|
63 |
+
{ _id: req.params.id },
|
64 |
+
{
|
65 |
+
populateArray: [
|
66 |
+
{ path: "workout", select: "-templateWeeks -created_by" },
|
67 |
+
{ path: "weeks.days.exercises" },
|
68 |
+
]
|
69 |
+
}
|
70 |
+
);
|
71 |
+
return JsonResponse.success(
|
72 |
+
{
|
73 |
+
data: serialize(data.toJSON(), UserRegisteredWorkoutsSerialization),
|
74 |
+
},
|
75 |
+
res
|
76 |
+
);
|
77 |
+
};
|
78 |
+
|
79 |
+
create = async (req: userRequest, res: Response) => {
|
80 |
+
const data = await this.userRegisteredWorkoutsService.create(req.body);
|
81 |
+
return JsonResponse.success(
|
82 |
+
{
|
83 |
+
status: 201,
|
84 |
+
data: serialize(data.toJSON(), UserRegisteredWorkoutsSerialization),
|
85 |
+
},
|
86 |
+
res
|
87 |
+
);
|
88 |
+
};
|
89 |
+
|
90 |
+
update = async (req: userRequest, res: Response) => {
|
91 |
+
const data = await this.userRegisteredWorkoutsService.updateOne(
|
92 |
+
{ _id: req.params.id },
|
93 |
+
req.body
|
94 |
+
);
|
95 |
+
return JsonResponse.success(
|
96 |
+
{
|
97 |
+
data: serialize(data.toJSON(), UserRegisteredWorkoutsSerialization),
|
98 |
+
},
|
99 |
+
res
|
100 |
+
);
|
101 |
+
};
|
102 |
+
}
|
src/modules/users/modules/user-registered-workouts/services/user-registered-workouts.service.ts
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { UserRegisteredWorkout } from "../../../common/models/user-registered-workout.model";
|
2 |
+
import { CrudService } from "@lib/services/crud.service";
|
3 |
+
|
4 |
+
export class UserRegisteredWorkoutsService extends CrudService(UserRegisteredWorkout) {}
|
src/modules/users/modules/user-registered-workouts/validations/create-user-registered-workouts.validation.ts
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import * as joi from "joi";
|
2 |
+
import { createSchema } from "@helpers/create-schema";
|
3 |
+
|
4 |
+
export interface IDays {
|
5 |
+
day: string;
|
6 |
+
exercises: string[];
|
7 |
+
isDone?: Boolean;
|
8 |
+
};
|
9 |
+
|
10 |
+
|
11 |
+
export interface IWeeks {
|
12 |
+
days: IDays[];
|
13 |
+
};
|
14 |
+
|
15 |
+
|
16 |
+
export interface ICreateUserRegisteredWorkouts {
|
17 |
+
user: string;
|
18 |
+
workout: string;
|
19 |
+
isActive: Boolean;
|
20 |
+
weeks: IWeeks[];
|
21 |
+
};
|
22 |
+
|
23 |
+
|
24 |
+
export const createUserRegisteredWorkoutsSchema = createSchema<ICreateUserRegisteredWorkouts>({
|
25 |
+
user: joi.string().empty().required().messages({
|
26 |
+
"string.base": "please enter a valid user id",
|
27 |
+
"any.required": "user id is required",
|
28 |
+
"string.empty": "user id can not be empty",
|
29 |
+
}),
|
30 |
+
isActive: joi.boolean().empty().optional().messages({
|
31 |
+
"boolean.base": "please enter a valid isActive",
|
32 |
+
"boolean.empty": "isActive can not be empty",
|
33 |
+
}),
|
34 |
+
workout: joi.string().empty().required().messages({
|
35 |
+
"string.base": "please enter a valid workout id",
|
36 |
+
"any.required": "workout id is required",
|
37 |
+
"string.empty": "workout id can not be empty",
|
38 |
+
}),
|
39 |
+
weeks: joi.array().empty().required().items(
|
40 |
+
joi.object({
|
41 |
+
days: joi.array().required().items(
|
42 |
+
joi.object({
|
43 |
+
day: joi.number().empty().required().messages({
|
44 |
+
"number.base": "please enter a valid day number",
|
45 |
+
"any.required": "day number is required",
|
46 |
+
"number.empty": "day number can not be empty",
|
47 |
+
}),
|
48 |
+
exercises: joi.array().empty().required().items(
|
49 |
+
joi.string().empty().required().messages({
|
50 |
+
"string.base": "please enter a valid exercise id",
|
51 |
+
"any.required": "exercise id is required",
|
52 |
+
"string.empty": "exercise id can not be empty",
|
53 |
+
}),).messages({
|
54 |
+
"array.base": "please enter a valid exercises array",
|
55 |
+
"any.required": "exercises array is required",
|
56 |
+
"array.empty": "exercises array can not be empty",
|
57 |
+
}),
|
58 |
+
isDone: joi.boolean().empty().optional().messages({
|
59 |
+
"boolean.base": "please enter a valid isDone",
|
60 |
+
"boolean.empty": "isDone can not be empty",
|
61 |
+
}),
|
62 |
+
}).empty().messages({
|
63 |
+
"object.base": "please enter a valid day object",
|
64 |
+
"any.required": "day object is required",
|
65 |
+
"object.empty": "day object can not be empty",
|
66 |
+
})
|
67 |
+
),
|
68 |
+
}).empty().messages({
|
69 |
+
"array.base": "please enter a valid days array",
|
70 |
+
"any.required": "days array is required",
|
71 |
+
"array.empty": "days array can not be empty",
|
72 |
+
|
73 |
+
})
|
74 |
+
).messages({
|
75 |
+
"array.base": "please enter a valid weeks array",
|
76 |
+
"any.required": "weeks array is required",
|
77 |
+
"array.empty": "weeks array can not be empty",
|
78 |
+
}),
|
79 |
+
});
|
src/modules/users/modules/user-registered-workouts/validations/update-user-registered-workouts.validation.ts
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import * as joi from "joi";
|
2 |
+
import { createSchema } from "@helpers/create-schema";
|
3 |
+
|
4 |
+
|
5 |
+
export interface IDays {
|
6 |
+
day?: string;
|
7 |
+
exercises?: string[];
|
8 |
+
isDone?: Boolean;
|
9 |
+
};
|
10 |
+
|
11 |
+
|
12 |
+
export interface IWeeks {
|
13 |
+
days?: IDays[];
|
14 |
+
};
|
15 |
+
|
16 |
+
export interface IUpdateUserRegisteredWorkouts {
|
17 |
+
user?: string;
|
18 |
+
workout?: string;
|
19 |
+
isActive?: Boolean;
|
20 |
+
weeks?: IWeeks[];
|
21 |
+
};
|
22 |
+
|
23 |
+
|
24 |
+
export const updateUserRegisteredWorkoutsSchema = createSchema<IUpdateUserRegisteredWorkouts>({
|
25 |
+
user: joi.string().empty().optional().messages({
|
26 |
+
"string.base": "please enter a valid user id",
|
27 |
+
"string.empty": "user id can not be empty",
|
28 |
+
}),
|
29 |
+
isActive: joi.boolean().empty().optional().messages({
|
30 |
+
"boolean.base": "please enter a valid isActive",
|
31 |
+
"boolean.empty": "isActive can not be empty",
|
32 |
+
}),
|
33 |
+
workout: joi.string().empty().optional().messages({
|
34 |
+
"string.base": "please enter a valid workout id",
|
35 |
+
"string.empty": "workout id can not be empty",
|
36 |
+
}),
|
37 |
+
weeks: joi.array().empty().optional().items(
|
38 |
+
joi.object({
|
39 |
+
days: joi.array().optional().items(
|
40 |
+
joi.object({
|
41 |
+
day: joi.number().empty().optional().messages({
|
42 |
+
"number.base": "please enter a valid day number",
|
43 |
+
"number.empty": "day number can not be empty",
|
44 |
+
}),
|
45 |
+
exercises: joi.array().empty().optional().items(
|
46 |
+
joi.string().empty().optional().messages({
|
47 |
+
"string.base": "please enter a valid exercise id",
|
48 |
+
"string.empty": "exercise id can not be empty",
|
49 |
+
}),).messages({
|
50 |
+
"array.base": "please enter a valid exercises array",
|
51 |
+
"array.empty": "exercises array can not be empty",
|
52 |
+
}),
|
53 |
+
isDone: joi.boolean().empty().optional().messages({
|
54 |
+
"boolean.base": "please enter a valid isDone",
|
55 |
+
"boolean.empty": "isDone can not be empty",
|
56 |
+
}),
|
57 |
+
}).empty().messages({
|
58 |
+
"object.base": "please enter a valid day object",
|
59 |
+
"object.empty": "day object can not be empty",
|
60 |
+
})
|
61 |
+
),
|
62 |
+
}).empty().messages({
|
63 |
+
"array.base": "please enter a valid days array",
|
64 |
+
"array.empty": "days array can not be empty",
|
65 |
+
|
66 |
+
})
|
67 |
+
).messages({
|
68 |
+
"array.base": "please enter a valid weeks array",
|
69 |
+
"array.empty": "weeks array can not be empty",
|
70 |
+
}),
|
71 |
+
});
|
src/modules/users/modules/workouts/controllers/workouts.controller.ts
CHANGED
@@ -7,11 +7,11 @@ import { paramsValidator } from "@helpers/validation.helper";
|
|
7 |
import { BaseController } from "@lib/controllers/controller.base";
|
8 |
import { Prefix } from "@lib/decorators/prefix.decorator";
|
9 |
import { serialize } from "@helpers/serialize";
|
10 |
-
import { WorkoutSerialization } from "@common/serializers/workout.
|
11 |
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
12 |
import { UsersGuardMiddleware } from "modules/users/common/guards/users.guard";
|
13 |
|
14 |
-
@Prefix("/
|
15 |
@ControllerMiddleware(UsersGuardMiddleware())
|
16 |
export class WorkoutController extends BaseController {
|
17 |
private workoutsService = new WorkoutService();
|
|
|
7 |
import { BaseController } from "@lib/controllers/controller.base";
|
8 |
import { Prefix } from "@lib/decorators/prefix.decorator";
|
9 |
import { serialize } from "@helpers/serialize";
|
10 |
+
import { WorkoutSerialization } from "@common/serializers/workout.serialization";
|
11 |
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
12 |
import { UsersGuardMiddleware } from "modules/users/common/guards/users.guard";
|
13 |
|
14 |
+
@Prefix("/user/workouts")
|
15 |
@ControllerMiddleware(UsersGuardMiddleware())
|
16 |
export class WorkoutController extends BaseController {
|
17 |
private workoutsService = new WorkoutService();
|