Spaces:
Running
Running
Merge pull request #17 from Modarb-Ai-Trainer/update
Browse files- package-lock.json +3 -0
- src/modules/common/users/enums/roles.enum.ts +45 -0
- src/modules/common/users/models/user.model.ts +24 -46
- src/modules/common/users/validation/{user.baseValidation.ts → user-register.validation.ts} +16 -5
- src/modules/console/admins/validations/create-admin.validation.ts +9 -2
- src/modules/console/users/controllers/users.controller.ts +1 -1
- src/modules/console/users/validation/admin.userValidation.ts +0 -5
- src/modules/user/auth/controllers/auth.controller.ts +1 -1
- src/routes.ts +5 -1
package-lock.json
CHANGED
@@ -1143,6 +1143,7 @@
|
|
1143 |
"version": "3.0.0",
|
1144 |
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
|
1145 |
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
|
|
|
1146 |
"engines": {
|
1147 |
"node": ">=4"
|
1148 |
}
|
@@ -1777,6 +1778,7 @@
|
|
1777 |
"version": "1.0.10",
|
1778 |
"resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz",
|
1779 |
"integrity": "sha512-NWmpvLSqUrgrAC9HCuxEvb+PSloHpqVu+FqcO4eeF2h5qYRhA7ev6KvelyQAKtegUbC6RypJnlEOhd8vloNKYg==",
|
|
|
1780 |
"dependencies": {
|
1781 |
"abbrev": "1"
|
1782 |
},
|
@@ -5009,6 +5011,7 @@
|
|
5009 |
"version": "5.5.0",
|
5010 |
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
|
5011 |
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
|
|
|
5012 |
"dependencies": {
|
5013 |
"has-flag": "^3.0.0"
|
5014 |
},
|
|
|
1143 |
"version": "3.0.0",
|
1144 |
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
|
1145 |
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
|
1146 |
+
"dev": true,
|
1147 |
"engines": {
|
1148 |
"node": ">=4"
|
1149 |
}
|
|
|
1778 |
"version": "1.0.10",
|
1779 |
"resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz",
|
1780 |
"integrity": "sha512-NWmpvLSqUrgrAC9HCuxEvb+PSloHpqVu+FqcO4eeF2h5qYRhA7ev6KvelyQAKtegUbC6RypJnlEOhd8vloNKYg==",
|
1781 |
+
"dev": true,
|
1782 |
"dependencies": {
|
1783 |
"abbrev": "1"
|
1784 |
},
|
|
|
5011 |
"version": "5.5.0",
|
5012 |
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
|
5013 |
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
|
5014 |
+
"dev": true,
|
5015 |
"dependencies": {
|
5016 |
"has-flag": "^3.0.0"
|
5017 |
},
|
src/modules/common/users/enums/roles.enum.ts
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export enum Role {
|
2 |
+
USER = "user"
|
3 |
+
}
|
4 |
+
export enum Gender {
|
5 |
+
MALE = "male",
|
6 |
+
FEMALE = "female"
|
7 |
+
}
|
8 |
+
export enum FitnessLevel {
|
9 |
+
BEGINNER = "beginner",
|
10 |
+
INTERMEDIATE = "intermediate",
|
11 |
+
ADVANCED = "advanced"
|
12 |
+
}
|
13 |
+
export enum FitnessGoal {
|
14 |
+
LOSE_WEIGHT = "lose weight",
|
15 |
+
GAIN_MUSCLE = "gain muscle",
|
16 |
+
GET_FITTER = "get fitter"
|
17 |
+
}
|
18 |
+
export enum WorkoutPlace {
|
19 |
+
GYM = "gym",
|
20 |
+
HOME = "home",
|
21 |
+
BOTH = "both"
|
22 |
+
}
|
23 |
+
export enum PreferredDay {
|
24 |
+
SATURDAY = "saturday",
|
25 |
+
SUNDAY = "sunday",
|
26 |
+
MONDAY = "monday",
|
27 |
+
TUESDAY = "tuesday",
|
28 |
+
WEDNESDAY = "wednesday",
|
29 |
+
THURSDAY = "thursday",
|
30 |
+
FRIDAY = "friday"
|
31 |
+
}
|
32 |
+
export enum PreferredEquipment {
|
33 |
+
BARBELLS = "barbells",
|
34 |
+
DUMBBELLS = "dumbbells",
|
35 |
+
GYM_MACHINES = "gym machines",
|
36 |
+
RESISTANCE_BAND = "resistance band",
|
37 |
+
BODYWEIGHT = "bodyweight"
|
38 |
+
}
|
39 |
+
export enum Injurie {
|
40 |
+
NECK = "neck",
|
41 |
+
SHOULDERS = "shoulders",
|
42 |
+
BACK = "back",
|
43 |
+
ARMS = "arms",
|
44 |
+
KNEES = "knees"
|
45 |
+
}
|
src/modules/common/users/models/user.model.ts
CHANGED
@@ -1,53 +1,31 @@
|
|
1 |
import mongoose from "mongoose";
|
2 |
import bcrypt from "bcrypt";
|
3 |
export const saltrounds = 5;
|
|
|
4 |
const { Schema } = mongoose;
|
5 |
-
enum Role {
|
6 |
-
USER = "user"
|
7 |
-
}
|
8 |
-
enum Gender {
|
9 |
-
MALE = "male",
|
10 |
-
FEMALE = "female"
|
11 |
-
}
|
12 |
-
enum FitnessLevel {
|
13 |
-
BEGINNER = "beginner",
|
14 |
-
INTERMEDIATE = "intermediate",
|
15 |
-
ADVANCED = "advanced"
|
16 |
-
}
|
17 |
-
enum FitnessGoal {
|
18 |
-
LOSE_WEIGHT = "lose weight",
|
19 |
-
GAIN_MUSCLE = "gain muscle",
|
20 |
-
GET_FITTER = "get fitter"
|
21 |
-
}
|
22 |
-
enum WorkoutPlace {
|
23 |
-
GYM = "gym",
|
24 |
-
HOME = "home",
|
25 |
-
BOTH = "both"
|
26 |
-
}
|
27 |
-
enum PreferredDay {
|
28 |
-
SATURDAY = "saturday",
|
29 |
-
SUNDAY = "sunday",
|
30 |
-
MONDAY = "monday",
|
31 |
-
TUESDAY = "tuesday",
|
32 |
-
WEDNESDAY = "wednesday",
|
33 |
-
THURSDAY = "thursday",
|
34 |
-
FRIDAY = "friday"
|
35 |
-
}
|
36 |
-
enum PreferredEquipment {
|
37 |
-
BARBELLS = "barbells",
|
38 |
-
DUMBBELLS = "dumbbells",
|
39 |
-
GYM_MACHINES = "gym machines",
|
40 |
-
RESISTANCE_BAND = "resistance band",
|
41 |
-
BODYWEIGHT = "bodyweight"
|
42 |
-
}
|
43 |
-
enum Injurie {
|
44 |
-
NECK = "neck",
|
45 |
-
SHOULDERS = "shoulders",
|
46 |
-
BACK = "back",
|
47 |
-
ARMS = "arms",
|
48 |
-
KNEES = "knees"
|
49 |
-
}
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
const userSchema = new Schema({
|
52 |
name: { type: String, required: true },
|
53 |
email: { type: String, required: true, unique: true, dropDups: true },
|
@@ -107,4 +85,4 @@ userSchema.pre("save", async function (next) {
|
|
107 |
next();
|
108 |
});
|
109 |
|
110 |
-
export const userModel = mongoose.model("users", userSchema);
|
|
|
1 |
import mongoose from "mongoose";
|
2 |
import bcrypt from "bcrypt";
|
3 |
export const saltrounds = 5;
|
4 |
+
import { Role, Gender, FitnessLevel, FitnessGoal, WorkoutPlace, PreferredDay, PreferredEquipment, Injurie } from "../enums/roles.enum";
|
5 |
const { Schema } = mongoose;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
export interface IUser {
|
8 |
+
name: string;
|
9 |
+
email: string;
|
10 |
+
password: string;
|
11 |
+
image: object;
|
12 |
+
role: Role;
|
13 |
+
gender: string;
|
14 |
+
dob: Date;
|
15 |
+
height: number;
|
16 |
+
weight: number;
|
17 |
+
fitness_level: string;
|
18 |
+
preferences: {
|
19 |
+
fitness_goal: FitnessGoal;
|
20 |
+
target_weight: number;
|
21 |
+
workout_frequency: number;
|
22 |
+
preferred_days: [PreferredDay];
|
23 |
+
workout_place: WorkoutPlace;
|
24 |
+
preferred_equipment: [PreferredEquipment];
|
25 |
+
};
|
26 |
+
injuries: [Injurie];
|
27 |
+
}
|
28 |
+
|
29 |
const userSchema = new Schema({
|
30 |
name: { type: String, required: true },
|
31 |
email: { type: String, required: true, unique: true, dropDups: true },
|
|
|
85 |
next();
|
86 |
});
|
87 |
|
88 |
+
export const userModel = mongoose.model<IUser>("users", userSchema);
|
src/modules/common/users/validation/{user.baseValidation.ts → user-register.validation.ts}
RENAMED
@@ -1,4 +1,5 @@
|
|
1 |
-
import joi from "joi";
|
|
|
2 |
|
3 |
export const userRegisterValidation = joi
|
4 |
.object()
|
@@ -45,7 +46,7 @@ export const userRegisterValidation = joi
|
|
45 |
"string.base": "please enter a valid public_id",
|
46 |
}),
|
47 |
}),
|
48 |
-
gender: joi.string().empty().required().messages({
|
49 |
"string.base": "please enter a valid gender",
|
50 |
"any.required": "gender must be entered",
|
51 |
"string.empty": "gender cannot be empty",
|
@@ -60,7 +61,7 @@ export const userRegisterValidation = joi
|
|
60 |
"any.required": "weight must be entered",
|
61 |
"number.empty": "weight cannot be empty",
|
62 |
}),
|
63 |
-
fitness_level: joi.string().empty().required().messages({
|
64 |
"string.base": "please enter a valid fitness_level",
|
65 |
"any.required": "fitness_level must be entered",
|
66 |
"string.empty": "fitness_level cannot be empty",
|
@@ -69,7 +70,7 @@ export const userRegisterValidation = joi
|
|
69 |
.object()
|
70 |
.optional()
|
71 |
.keys({
|
72 |
-
fitness_goal: joi.string().empty().required().messages({
|
73 |
"string.base": "please enter a valid fitness_goal",
|
74 |
"any.required": "fitness_goal must be entered",
|
75 |
"string.empty": "fitness_goal cannot be empty",
|
@@ -86,6 +87,7 @@ export const userRegisterValidation = joi
|
|
86 |
}),
|
87 |
preferred_days: joi
|
88 |
.array()
|
|
|
89 |
.empty()
|
90 |
.required()
|
91 |
.items(
|
@@ -95,13 +97,14 @@ export const userRegisterValidation = joi
|
|
95 |
"string.empty": "preferred_days cannot be empty",
|
96 |
})
|
97 |
),
|
98 |
-
workout_place: joi.string().empty().required().messages({
|
99 |
"string.base": "please enter a valid workout_place",
|
100 |
"any.required": "workout_place must be entered",
|
101 |
"string.empty": "workout_place cannot be empty",
|
102 |
}),
|
103 |
preferred_equipment: joi
|
104 |
.array()
|
|
|
105 |
.empty()
|
106 |
.required()
|
107 |
.items(
|
@@ -114,6 +117,7 @@ export const userRegisterValidation = joi
|
|
114 |
}),
|
115 |
injuries: joi
|
116 |
.array()
|
|
|
117 |
.empty()
|
118 |
.required()
|
119 |
.items(
|
@@ -126,4 +130,11 @@ export const userRegisterValidation = joi
|
|
126 |
dob: joi.date().empty().optional().messages({
|
127 |
"date.base": "please enter a valid date",
|
128 |
}),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
});
|
|
|
1 |
+
import * as joi from "joi";
|
2 |
+
import { Role, Gender, FitnessLevel, FitnessGoal, WorkoutPlace, PreferredDay, PreferredEquipment, Injurie } from "../enums/roles.enum";
|
3 |
|
4 |
export const userRegisterValidation = joi
|
5 |
.object()
|
|
|
46 |
"string.base": "please enter a valid public_id",
|
47 |
}),
|
48 |
}),
|
49 |
+
gender: joi.string().valid(...Object.values(Gender)).empty().required().messages({
|
50 |
"string.base": "please enter a valid gender",
|
51 |
"any.required": "gender must be entered",
|
52 |
"string.empty": "gender cannot be empty",
|
|
|
61 |
"any.required": "weight must be entered",
|
62 |
"number.empty": "weight cannot be empty",
|
63 |
}),
|
64 |
+
fitness_level: joi.string().valid(...Object.values(FitnessLevel)).empty().required().messages({
|
65 |
"string.base": "please enter a valid fitness_level",
|
66 |
"any.required": "fitness_level must be entered",
|
67 |
"string.empty": "fitness_level cannot be empty",
|
|
|
70 |
.object()
|
71 |
.optional()
|
72 |
.keys({
|
73 |
+
fitness_goal: joi.string().valid(...Object.values(FitnessGoal)).empty().required().messages({
|
74 |
"string.base": "please enter a valid fitness_goal",
|
75 |
"any.required": "fitness_goal must be entered",
|
76 |
"string.empty": "fitness_goal cannot be empty",
|
|
|
87 |
}),
|
88 |
preferred_days: joi
|
89 |
.array()
|
90 |
+
.valid(...Object.values(PreferredDay))
|
91 |
.empty()
|
92 |
.required()
|
93 |
.items(
|
|
|
97 |
"string.empty": "preferred_days cannot be empty",
|
98 |
})
|
99 |
),
|
100 |
+
workout_place: joi.string().valid(...Object.values(WorkoutPlace)).empty().required().messages({
|
101 |
"string.base": "please enter a valid workout_place",
|
102 |
"any.required": "workout_place must be entered",
|
103 |
"string.empty": "workout_place cannot be empty",
|
104 |
}),
|
105 |
preferred_equipment: joi
|
106 |
.array()
|
107 |
+
.valid(...Object.values(PreferredEquipment))
|
108 |
.empty()
|
109 |
.required()
|
110 |
.items(
|
|
|
117 |
}),
|
118 |
injuries: joi
|
119 |
.array()
|
120 |
+
.valid(...Object.values(Injurie))
|
121 |
.empty()
|
122 |
.required()
|
123 |
.items(
|
|
|
130 |
dob: joi.date().empty().optional().messages({
|
131 |
"date.base": "please enter a valid date",
|
132 |
}),
|
133 |
+
role: joi
|
134 |
+
.string()
|
135 |
+
.valid(...Object.values(Role))
|
136 |
+
.optional().messages({
|
137 |
+
"string.base": "please enter a valid role",
|
138 |
+
"string.empty": "role cannot be empty"
|
139 |
+
}),
|
140 |
});
|
src/modules/console/admins/validations/create-admin.validation.ts
CHANGED
@@ -35,6 +35,13 @@ export const createAdminSchema = joi
|
|
35 |
role: joi
|
36 |
.string()
|
37 |
.valid(...Object.values(Role))
|
38 |
-
.
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
});
|
|
|
35 |
role: joi
|
36 |
.string()
|
37 |
.valid(...Object.values(Role))
|
38 |
+
.optional().messages({
|
39 |
+
"string.base": "please enter a valid role",
|
40 |
+
"string.empty": "role cannot be empty"
|
41 |
+
}),
|
42 |
+
gender: joi.string().empty().required().messages({
|
43 |
+
"string.base": "please enter a valid gender",
|
44 |
+
"any.required": "gender must be entered",
|
45 |
+
"string.empty": "gender cannot be empty"
|
46 |
+
})
|
47 |
});
|
src/modules/console/users/controllers/users.controller.ts
CHANGED
@@ -2,7 +2,7 @@ import { jwtHelper } from "../../../../helpers/jwt.helper";
|
|
2 |
import { bodyValidator } from "../../../../helpers/validation.helper";
|
3 |
import { BaseController } from "../../../../lib/controllers/controller.base";
|
4 |
import { Prefix } from "../../../common/decorators/prefix.decorator";
|
5 |
-
import { userRegisterValidation } from "../../../common/users/validation/user.
|
6 |
import { UsersService } from "../services/users.service";
|
7 |
|
8 |
const allowedRoles = ["superAdmin", "admin"];
|
|
|
2 |
import { bodyValidator } from "../../../../helpers/validation.helper";
|
3 |
import { BaseController } from "../../../../lib/controllers/controller.base";
|
4 |
import { Prefix } from "../../../common/decorators/prefix.decorator";
|
5 |
+
import { userRegisterValidation } from "../../../common/users/validation/user-register.validation";
|
6 |
import { UsersService } from "../services/users.service";
|
7 |
|
8 |
const allowedRoles = ["superAdmin", "admin"];
|
src/modules/console/users/validation/admin.userValidation.ts
DELETED
@@ -1,5 +0,0 @@
|
|
1 |
-
import { userBaseValidation } from '../../../common/users/validation/user.baseValidation';
|
2 |
-
|
3 |
-
export class adminUserValidation extends userBaseValidation {
|
4 |
-
|
5 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
src/modules/user/auth/controllers/auth.controller.ts
CHANGED
@@ -3,7 +3,7 @@ import { jwtHelper } from "../../../../helpers/jwt.helper";
|
|
3 |
import { BaseController } from "../../../../lib/controllers/controller.base";
|
4 |
import { Prefix } from "../../../common/decorators/prefix.decorator";
|
5 |
import { bodyValidator } from "../../../../helpers/validation.helper";
|
6 |
-
import { userRegisterValidation } from "../../../common/users/validation/user.
|
7 |
import { loginValidation } from "../validation/user.Validation";
|
8 |
|
9 |
@Prefix("/user/auth")
|
|
|
3 |
import { BaseController } from "../../../../lib/controllers/controller.base";
|
4 |
import { Prefix } from "../../../common/decorators/prefix.decorator";
|
5 |
import { bodyValidator } from "../../../../helpers/validation.helper";
|
6 |
+
import { userRegisterValidation } from "../../../common/users/validation/user-register.validation";
|
7 |
import { loginValidation } from "../validation/user.Validation";
|
8 |
|
9 |
@Prefix("/user/auth")
|
src/routes.ts
CHANGED
@@ -35,15 +35,19 @@ const setCustomRoutes = (router: Router) => {
|
|
35 |
/* importing all controllers */
|
36 |
|
37 |
const findControllerFiles = (): string[] => {
|
38 |
-
return glob.sync(
|
|
|
|
|
39 |
};
|
40 |
|
41 |
const importControllers = async (router: Router) => {
|
42 |
const files = findControllerFiles();
|
43 |
|
|
|
44 |
await Promise.all(
|
45 |
files.map(async (file) => {
|
46 |
const controllerClass = await importController(file);
|
|
|
47 |
if (!controllerClass) return;
|
48 |
const controller: BaseController = new (controllerClass as any)();
|
49 |
controller.setRoutes();
|
|
|
35 |
/* importing all controllers */
|
36 |
|
37 |
const findControllerFiles = (): string[] => {
|
38 |
+
return glob.sync("**/*.controller.ts", {}).map((file) => {
|
39 |
+
return path.resolve(file);
|
40 |
+
});
|
41 |
};
|
42 |
|
43 |
const importControllers = async (router: Router) => {
|
44 |
const files = findControllerFiles();
|
45 |
|
46 |
+
|
47 |
await Promise.all(
|
48 |
files.map(async (file) => {
|
49 |
const controllerClass = await importController(file);
|
50 |
+
|
51 |
if (!controllerClass) return;
|
52 |
const controller: BaseController = new (controllerClass as any)();
|
53 |
controller.setRoutes();
|