Spaces:
Running
Running
Hozifaelgharbawy
commited on
Commit
·
260547f
1
Parent(s):
8b3449a
update
Browse files- src/modules/common/users/models/user.model.ts +24 -46
- src/modules/common/users/validation/user.baseValidation.ts +0 -129
- 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/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
DELETED
|
@@ -1,129 +0,0 @@
|
|
| 1 |
-
import joi from "joi";
|
| 2 |
-
|
| 3 |
-
export const userRegisterValidation = joi
|
| 4 |
-
.object()
|
| 5 |
-
.required()
|
| 6 |
-
.keys({
|
| 7 |
-
name: joi.string().empty().required().messages({
|
| 8 |
-
"string.base": "please enter a valid name",
|
| 9 |
-
"any.required": "name is required",
|
| 10 |
-
"string.empty": "name can not be empty",
|
| 11 |
-
}),
|
| 12 |
-
email: joi
|
| 13 |
-
.string()
|
| 14 |
-
.required()
|
| 15 |
-
.email({
|
| 16 |
-
minDomainSegments: 2,
|
| 17 |
-
tlds: { allow: ["com", "net", "org", "eg", "io"] },
|
| 18 |
-
})
|
| 19 |
-
.empty()
|
| 20 |
-
.messages({
|
| 21 |
-
"string.email": "please enter a valid email",
|
| 22 |
-
"any.required": "email must be entered",
|
| 23 |
-
"string.empty": "email can not be empty",
|
| 24 |
-
}),
|
| 25 |
-
password: joi.string().empty().min(8).required().messages({
|
| 26 |
-
"string.base": "please enter a valid password",
|
| 27 |
-
"any.required": "password must be entered",
|
| 28 |
-
"string.empty": "password cannot be empty",
|
| 29 |
-
"string.min": "password must be at least 8 characters",
|
| 30 |
-
}),
|
| 31 |
-
confirmPassword: joi.string().empty().min(8).required().messages({
|
| 32 |
-
"string.base": "please enter a valid password",
|
| 33 |
-
"any.required": "password must be entered",
|
| 34 |
-
"string.empty": "password cannot be empty",
|
| 35 |
-
"string.min": "password must be at least 8 characters",
|
| 36 |
-
}),
|
| 37 |
-
image: joi
|
| 38 |
-
.object()
|
| 39 |
-
.optional()
|
| 40 |
-
.keys({
|
| 41 |
-
url: joi.string().optional().messages({
|
| 42 |
-
"string.base": "please enter a valid url",
|
| 43 |
-
}),
|
| 44 |
-
public_id: joi.string().optional().messages({
|
| 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",
|
| 52 |
-
}),
|
| 53 |
-
height: joi.number().empty().required().messages({
|
| 54 |
-
"number.base": "please enter a valid height number",
|
| 55 |
-
"any.required": "height must be entered",
|
| 56 |
-
"number.empty": "height cannot be empty",
|
| 57 |
-
}),
|
| 58 |
-
weight: joi.number().empty().required().messages({
|
| 59 |
-
"number.base": "please enter a valid weight number",
|
| 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",
|
| 67 |
-
}),
|
| 68 |
-
preferences: 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",
|
| 76 |
-
}),
|
| 77 |
-
target_weight: joi.number().empty().required().messages({
|
| 78 |
-
"number.base": "please enter a valid target_weight number",
|
| 79 |
-
"any.required": "target_weight must be entered",
|
| 80 |
-
"number.empty": "target_weight cannot be empty",
|
| 81 |
-
}),
|
| 82 |
-
workout_frequency: joi.number().empty().required().messages({
|
| 83 |
-
"number.base": "please enter a valid workout_frequency number",
|
| 84 |
-
"any.required": "workout_frequency must be entered",
|
| 85 |
-
"number.empty": "workout_frequency cannot be empty",
|
| 86 |
-
}),
|
| 87 |
-
preferred_days: joi
|
| 88 |
-
.array()
|
| 89 |
-
.empty()
|
| 90 |
-
.required()
|
| 91 |
-
.items(
|
| 92 |
-
joi.string().empty().required().messages({
|
| 93 |
-
"string.base": "please enter a valid preferred_days",
|
| 94 |
-
"any.required": "preferred_days must be entered",
|
| 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(
|
| 108 |
-
joi.string().empty().required().messages({
|
| 109 |
-
"string.base": "please enter a valid preferred_equipment",
|
| 110 |
-
"any.required": "preferred_equipment must be entered",
|
| 111 |
-
"string.empty": "preferred_equipment cannot be empty",
|
| 112 |
-
})
|
| 113 |
-
),
|
| 114 |
-
}),
|
| 115 |
-
injuries: joi
|
| 116 |
-
.array()
|
| 117 |
-
.empty()
|
| 118 |
-
.required()
|
| 119 |
-
.items(
|
| 120 |
-
joi.string().empty().required().messages({
|
| 121 |
-
"string.base": "please enter a valid injuries",
|
| 122 |
-
"any.required": "injuries must be entered",
|
| 123 |
-
"string.empty": "injuries cannot be empty",
|
| 124 |
-
})
|
| 125 |
-
),
|
| 126 |
-
dob: joi.date().empty().optional().messages({
|
| 127 |
-
"date.base": "please enter a valid date",
|
| 128 |
-
}),
|
| 129 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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")
|