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
|
const mongoose = require('mongoose');
const validator = require('validator');
const UserSchema = new mongoose.Schema({
firstname: {
type: String,
required: [true, "You need to provide your first name."],
maxLength: [32, "You can't have a first name longer than 32 characters."],
validate: {
validator: validator.isAlpha,
message: props => "Your first name can only contain characters."
}
},
lastname: {
type: String,
required: [true, "You need to provide your last name."],
maxLength: [32, "You can't have a last name longer than 32 characters."],
validate: {
validator: validator.isAlpha,
message: props => "Your last name can only contain characters."
}
},
email: {
type: String,
unique: [true, "Account with given email already exists!"],
required: [true, "You need to provide an email."],
maxLength: [100, "You can't have a email longer than 100 characters."],
validate: {
validator: validator.isEmail,
message: props => "Provided email is not valid."
}
},
password: {
type: String,
required: [true, "You need to provide a password."],
},
admin: {
type: Boolean,
default: false
}
});
const UserModel = new mongoose.model('User', UserSchema);
module.exports = UserModel;
|