more bits

This commit is contained in:
Dobie Wollert
2015-12-20 23:44:49 -08:00
parent a680042374
commit 977ea41cef
6 changed files with 198 additions and 31 deletions

42
app/model/timeSheet.js Normal file
View File

@ -0,0 +1,42 @@
"use strict";
var moment = require('moment');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;
var schema = new Schema({
user: {
type: ObjectId,
ref: 'User',
required: true
},
week: {
type: Date,
required: true
},
approved: {
type: Boolean,
default: false,
required: true
},
approvedOn: {
type: Date,
required: function() {
return this.approved === true;
}
}
});
schema.pre('save', function (next) {
if (!this.approved) {
this.approvedOn = undefined;
}
next();
});
module.exports = mongoose.model('TimeSheet', schema);