-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.js
More file actions
30 lines (21 loc) · 822 Bytes
/
models.js
File metadata and controls
30 lines (21 loc) · 822 Bytes
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
function defineModels(mongoose, fn) {
var Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
/**
* Model: User
*/
function validatePresenceOf(value) {
var re = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i
return value && value.length && re.test(value);
}
User = new Schema({
'email': { type: String, validate: [validatePresenceOf, 'A valid email is required'], index: { unique: true } }
});
User.virtual('id')
.get(function() {
return this._id.toHexString();
});
mongoose.model('User', User);
fn();
}
exports.defineModels = defineModels;