File size: 2,429 Bytes
f37be3f
 
 
 
98d83e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f37be3f
 
 
 
 
98d83e7
 
 
 
 
 
f37be3f
 
98d83e7
 
 
 
 
 
 
 
 
 
 
f37be3f
 
98d83e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f37be3f
98d83e7
 
 
 
 
f37be3f
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import mongoose from "mongoose";
import bcrypt from "bcrypt";
export const saltrounds = 5;
const { Schema } = mongoose;
enum Gender {
    MALE= "male",
    FEMALE= "female"
}
enum FitnessLevel {
    BEGINNER= "beginner",
    INTERMEDIATE= "intermediate",
    ADVANCED= "advanced"
}
enum FitnessGoal {
    LOSE_WEIGHT= "lose weight",
    GAIN_MUSCLE= "gain muscle",
    GET_FITTER= "get fitter"
}
enum WorkoutPlace {
    GYM= "gym",
    HOME= "home",
    BOTH= "both"
}
enum PreferredDay {
    SATURDAY= "saturday",
    SUNDAY= "sunday",
    MONDAY= "monday",
    TUESDAY= "tuesday",
    WEDNESDAY= "wednesday",
    THURSDAY= "thursday",
    FRIDAY= "friday"
}
enum PreferredEquipment {
    BARBELLS= "barbells",
    DUMBBELLS= "dumbbells",
    GYM_MACHINES= "gym machines",
    RESISTANCE_BAND= "resistance band",
    BODYWEIGHT= "bodyweight"
}
enum Injurie {
    NECK= "neck",
    SHOULDERS= "shoulders",
    BACK= "back",
    ARMS= "arms",
    KNEES= "knees"
}

const userSchema = new Schema({
    name: { type: String, required: true },
    email: { type: String, required: true, unique: true, dropDups: true },
    password: { type: String, required: true },
    image: { type: String },
    gender: {
        type: String,
        enum: Gender,
        required: true
    },
    height: { type: Number, required: true },
    weight: { type: Number, required: true },
    fitness_level: {
        type: String,
        enum: FitnessLevel,
        required: true
    },
    preferences: {
        fitness_goal: {
            type: String,
            enum: FitnessGoal,
            required: true
        },
        target_weight: { type: Number, required: true },
        workout_frequency: { type: Number, required: true },
        preferred_days: [{
            type: String,
            enum: PreferredDay,
            required: true
        }],
        workout_place: {
            type: String,
            enum: WorkoutPlace,
            required: true
        },
        preferred_equipment: [{
            type: String,
            enum: PreferredEquipment,
            required: true
        }]
    },
    injuries: [{
        type: String,
        enum: Injurie,
        required: true
    }],
    dob: { type: Date }
});

userSchema.pre("save", async function (next) {
    this.password = await bcrypt.hash(this.password, saltrounds);
    next();
});

export const userModel = mongoose.model("users", userSchema);