forked from rowlandekemezie/Document-Manager-REST-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument.model.js
More file actions
44 lines (40 loc) · 998 Bytes
/
Copy pathdocument.model.js
File metadata and controls
44 lines (40 loc) · 998 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(function() {
'use strict';
var mongoose = require('mongoose'),
date = require('./../../seeds/dateHelper')(),
// var Schema = mongoose.Shema;
documentSchema = new mongoose.Schema({
ownerId: {
type: mongoose.Schema.Types.ObjectId,
Ref: 'User',
},
title: {
type: String,
required: true
},
content: {
type: String,
required: true,
validate: /[a-zA-Z\^w]/
},
role: {
type: String,
Ref: 'Role'
},
createdAt: {
type: String
},
lastModified: {
type: Date,
default: Date.now
}
});
//set dateCreated and lastmodified to current date before saving a document
documentSchema.pre('save', function(next) {
var doc = this;
doc.createdAt = date;
next();
});
// The mongoose API requires the model name and schema to create the model
module.exports = mongoose.model('Document', documentSchema);
})();