-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatient.js
61 lines (57 loc) · 1.34 KB
/
patient.js
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
var mongoose = require('mongoose');
const bcrypt = require('bcrypt');
//Define a schema
var Schema = mongoose.Schema;
var Patient = new Schema({
_id: {
type:Number,
min: [6, 'Too few characters'],
required:[true,"Need an ID!"],
},
firstname:{
type:String,
required:[true,"Need an First Name!"],
},
lastname:{
type:String,
required:[true,"Need an Last Name!"],
},
email:{
type:String,
required:[true,"Need an Email!"],
},
phone_number:{
type:Number,
required: [true,"Need an Phone Number!"],
validate: {
validator: function (v) {
//Must have XXX-XXX-XXXX format
//return true to pass the validation
//return false to fail the validation
return (/\d{3}-\d{3}-\d{4}/.test(v));
}
},
//message to return if validation fails
message: props => `${props.value} is not a valid number!`
},
username:{
type:String,
required:[true,"Need an Username!"],
max:[10,"Don't keep the username too long"],
},
hashPassword:{
type:String,
required:[true,"Need an Password!"],
min:[7, "password must be more secure"],
},
symptoms: {
type:String,
max:[100,"Keep it shorter"],
},
appointment:[String],
doctorIDs:[Number],
});
Patient.methods.comparePasswords = (password, hashPassword) => {
return bcrypt.compareSync(password, hashPassword);
}
module.exports = mongoose.model('Patient', Patient );