Hozifa Elgherbawy commited on
Commit
33997da
·
unverified ·
2 Parent(s): 4f5431a 98d83e7

Merge pull request #6 from Modarb-Ai-Trainer/test

Browse files
src/modules/common/User/models/user.model.ts CHANGED
@@ -2,25 +2,95 @@ import mongoose from "mongoose";
2
  import bcrypt from "bcrypt";
3
  export const saltrounds = 5;
4
  const { Schema } = mongoose;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  const userSchema = new Schema({
7
  name: { type: String, required: true },
8
  email: { type: String, required: true, unique: true, dropDups: true },
9
  password: { type: String, required: true },
10
- image: { type: Object, default: {} },
11
- gender: { type: String, required: true },
 
 
 
 
12
  height: { type: Number, required: true },
13
  weight: { type: Number, required: true },
14
- fitness_level: { type: Number, required: true },
15
- preferences: {
16
- fitness_goal: { type: Number, required: true },
 
 
 
 
 
 
 
 
17
  target_weight: { type: Number, required: true },
18
  workout_frequency: { type: Number, required: true },
19
- preferred_days: [{ type: String, required: true }],
20
- workout_place: { type: String, required: true },
21
- preferred_equipments: { type: String, required: true }
 
 
 
 
 
 
 
 
 
 
 
 
22
  },
23
- injuries: [{ type: String, required: true }],
 
 
 
 
24
  dob: { type: Date }
25
  });
26
 
 
2
  import bcrypt from "bcrypt";
3
  export const saltrounds = 5;
4
  const { Schema } = mongoose;
5
+ enum Gender {
6
+ MALE= "male",
7
+ FEMALE= "female"
8
+ }
9
+ enum FitnessLevel {
10
+ BEGINNER= "beginner",
11
+ INTERMEDIATE= "intermediate",
12
+ ADVANCED= "advanced"
13
+ }
14
+ enum FitnessGoal {
15
+ LOSE_WEIGHT= "lose weight",
16
+ GAIN_MUSCLE= "gain muscle",
17
+ GET_FITTER= "get fitter"
18
+ }
19
+ enum WorkoutPlace {
20
+ GYM= "gym",
21
+ HOME= "home",
22
+ BOTH= "both"
23
+ }
24
+ enum PreferredDay {
25
+ SATURDAY= "saturday",
26
+ SUNDAY= "sunday",
27
+ MONDAY= "monday",
28
+ TUESDAY= "tuesday",
29
+ WEDNESDAY= "wednesday",
30
+ THURSDAY= "thursday",
31
+ FRIDAY= "friday"
32
+ }
33
+ enum PreferredEquipment {
34
+ BARBELLS= "barbells",
35
+ DUMBBELLS= "dumbbells",
36
+ GYM_MACHINES= "gym machines",
37
+ RESISTANCE_BAND= "resistance band",
38
+ BODYWEIGHT= "bodyweight"
39
+ }
40
+ enum Injurie {
41
+ NECK= "neck",
42
+ SHOULDERS= "shoulders",
43
+ BACK= "back",
44
+ ARMS= "arms",
45
+ KNEES= "knees"
46
+ }
47
 
48
  const userSchema = new Schema({
49
  name: { type: String, required: true },
50
  email: { type: String, required: true, unique: true, dropDups: true },
51
  password: { type: String, required: true },
52
+ image: { type: String },
53
+ gender: {
54
+ type: String,
55
+ enum: Gender,
56
+ required: true
57
+ },
58
  height: { type: Number, required: true },
59
  weight: { type: Number, required: true },
60
+ fitness_level: {
61
+ type: String,
62
+ enum: FitnessLevel,
63
+ required: true
64
+ },
65
+ preferences: {
66
+ fitness_goal: {
67
+ type: String,
68
+ enum: FitnessGoal,
69
+ required: true
70
+ },
71
  target_weight: { type: Number, required: true },
72
  workout_frequency: { type: Number, required: true },
73
+ preferred_days: [{
74
+ type: String,
75
+ enum: PreferredDay,
76
+ required: true
77
+ }],
78
+ workout_place: {
79
+ type: String,
80
+ enum: WorkoutPlace,
81
+ required: true
82
+ },
83
+ preferred_equipment: [{
84
+ type: String,
85
+ enum: PreferredEquipment,
86
+ required: true
87
+ }]
88
  },
89
+ injuries: [{
90
+ type: String,
91
+ enum: Injurie,
92
+ required: true
93
+ }],
94
  dob: { type: Date }
95
  });
96
 
src/modules/common/User/services/user.base.service.ts ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { userModel, } from '../models/user.model'
2
+
3
+
4
+ export class UserBaseService {
5
+ static async find(filterObject) {
6
+ try {
7
+ const resultObject = await userModel.findOne(filterObject).lean();
8
+
9
+ if (!resultObject)
10
+ return {
11
+ success: false,
12
+ code: 404,
13
+ error: "No Matching Result Found.",
14
+ };
15
+
16
+ return {
17
+ success: true,
18
+ code: 200,
19
+ result: resultObject,
20
+ };
21
+ } catch (err) {
22
+ console.log(`err.message`, err.message);
23
+ return {
24
+ success: false,
25
+ code: 500,
26
+ error: "Unexpected Error Happened.",
27
+ };
28
+ }
29
+ }
30
+
31
+ static async get(filterObject) {
32
+ try {
33
+ const resultObject = await userModel.findOne(filterObject).lean().select("-password");
34
+ if (!resultObject)
35
+ return {
36
+ success: false,
37
+ code: 404,
38
+ error: "No Matching Result Found.",
39
+ };
40
+ return {
41
+ success: true,
42
+ code: 200,
43
+ result: resultObject,
44
+ };
45
+ } catch (err) {
46
+ console.log(`err.message`, err.message);
47
+ return {
48
+ success: false,
49
+ code: 500,
50
+ error: "Unexpected Error Happened.",
51
+ };
52
+ }
53
+ }
54
+
55
+ static async list(filterObject) {
56
+ try {
57
+ const resultArray = await userModel
58
+ .find(filterObject)
59
+ .lean()
60
+ .select("-password");
61
+
62
+ if (!resultArray)
63
+ return {
64
+ success: false,
65
+ code: 404,
66
+ error: "No Matching Result Found.",
67
+ };
68
+ const count = await userModel.countDocuments(filterObject);
69
+ return {
70
+ success: true,
71
+ code: 200,
72
+ result: resultArray,
73
+ count,
74
+ };
75
+ } catch (err) {
76
+ console.log(`err.message`, err.message);
77
+ return {
78
+ success: false,
79
+ code: 500,
80
+ error: "Unexpected Error Happened.",
81
+ };
82
+ }
83
+ }
84
+
85
+ }
86
+
87
+
88
+
src/modules/console/Admin/models/admin.model.ts CHANGED
@@ -2,16 +2,19 @@ import mongoose from "mongoose";
2
  import bcrypt from "bcrypt";
3
  export const saltrounds = 5;
4
  const { Schema } = mongoose;
5
-
 
 
 
6
  const adminSchema = new Schema({
7
  name: { type: String, required: true },
8
  email: { type: String, required: true, unique: true, dropDups: true },
9
  password: { type: String, required: true },
10
  image: { type: Object, default: {} },
 
11
  role: {
12
  type: String,
13
- enum: ["superAdmin", "admin"],
14
- default: "admin"
15
  },
16
  gender: { type: String, required: true },
17
  dob: { type: Date }
 
2
  import bcrypt from "bcrypt";
3
  export const saltrounds = 5;
4
  const { Schema } = mongoose;
5
+ enum Role {
6
+ SUPER_ADMIN= "superAdmin",
7
+ ADMIN= "admin"
8
+ }
9
  const adminSchema = new Schema({
10
  name: { type: String, required: true },
11
  email: { type: String, required: true, unique: true, dropDups: true },
12
  password: { type: String, required: true },
13
  image: { type: Object, default: {} },
14
+ permission: { type: Object, required: true },
15
  role: {
16
  type: String,
17
+ enum: Role
 
18
  },
19
  gender: { type: String, required: true },
20
  dob: { type: Date }
src/modules/console/Admin/services/admin.service.ts CHANGED
@@ -31,7 +31,7 @@ export class AdminService {
31
 
32
  static async get(filterObject) {
33
  try {
34
- const resultObject = await adminModel.findOne(filterObject).lean();
35
  if (!resultObject)
36
  return {
37
  success: false,
 
31
 
32
  static async get(filterObject) {
33
  try {
34
+ const resultObject = await adminModel.findOne(filterObject).lean().select("-password");
35
  if (!resultObject)
36
  return {
37
  success: false,
src/modules/console/User/services/user.service.ts ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import { UserBaseService } from "../../../common/User/services/user.base.service";
2
+
3
+
4
+
5
+ export class userService extends UserBaseService {
6
+
7
+ }
8
+
9
+
10
+