-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperation.js
More file actions
35 lines (29 loc) · 865 Bytes
/
Copy pathoperation.js
File metadata and controls
35 lines (29 loc) · 865 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
var mongoose = require('mongoose')
, env = process.env.NODE_ENV || 'development'
, Schema = mongoose.Schema
// schema
var OperationSchema = new Schema({
system : {type : String, default : '', trim : true}
, starts_at : {type : Date, default : Date.now}
, created_at : {type : Date, default : Date.now}
})
// validations
OperationSchema.path('system').validate(function (system) {
return system.length > 0
}, 'System name cannot be blank')
// static functions
OperationSchema.statics = {
load: function (id, cb) {
this.findOne({ _id : id })
.exec(cb)
},
list: function (options, cb) {
var criteria = options.criteria || {}
this.find(criteria)
.sort({'createdAt': -1})
.limit(options.perPage)
.skip(options.perPage * options.page)
.exec(cb)
}
}
mongoose.model('Operation', OperationSchema)