This commit is contained in:
Dobie Wollert
2015-12-16 09:12:35 -08:00
parent f9c9672818
commit f94ca33b9e
805 changed files with 67409 additions and 24609 deletions

View File

@ -0,0 +1,30 @@
"use strict";
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;
const EXCEPTION_REASONS = [
'late_to_first_workorder',
'too_little_travel',
'too_much_travel'
];
var schema = new Schema({
user: {
type: ObjectId,
ref: 'User',
required: true
},
date: {
type: Date,
required: true
},
reason: {
type: String,
enum: EXCEPTION_REASONS,
required: true
}
});
module.exports = mongoose.model('TimeClockException', schema);

View File

@ -1,58 +1,106 @@
"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
},
user: {
type: ObjectId,
ref: 'User'
},
client: {
type: ObjectId,
ref: 'Client'
},
workorder: {
type: ObjectId,
ref: 'Workorder'
},
status: {
type: String,
enum: ['open', 'closed']
},
start: {
type: Date
},
end: {
type: Date
},
duration: {
type: Number,
min: 0
},
type: {
type: String,
enum: [ 'workorder', 'workday', 'nonBillable' ]
},
reason: {
type: String,
enum: ['shop', 'break', 'pto', 'meeting', 'event', 'weather', 'holiday']
},
notes: {
type: String,
trim: true
client: {
type: ObjectId,
ref: 'Client',
required: function() {
return this.type === 'workorder';
}
},
workorder: {
type: ObjectId,
ref: 'Workorder',
required: function() {
return this.type === 'workorder';
}
},
status: {
type: String,
enum: ['open', 'closed'],
required: true
},
start: {
type: Date,
required: true
},
end: {
type: Date,
required: function() {
return this.status === 'closed';
}
},
duration: {
type: Number,
min: 0
},
type: {
type: String,
enum: ['workorder', 'workday', 'nonBillable'],
required: true
},
reason: {
type: String,
enum: ['shop', 'break', 'pto', 'meeting', 'event', 'weather', 'holiday'],
required: function() {
return this.type === 'nonBillable';
}
},
notes: {
type: String,
trim: true,
required: function() {
return this.type === 'workorder' && this.status === 'closed';
}
}
});
schema.pre('save', function (next) {
if (this.status === 'open') {
this.end = undefined;
}
if (this.type === 'workorder') {
this.reason = undefined;
}
if (this.type !== 'workorder') {
this.workorder = undefined;
this.client = undefined;
}
if (this.start && this.end) {
this.duration = moment(this.end).diff(this.start, 'seconds');
}
next();
});
schema.pre('validate', function (next) {
if (this.start > this.end) {
return next(new Error('End date must be greater than start date.'));
}
next();
});
module.exports = mongoose.model('TimeClockSpan', schema);

View File

@ -11,10 +11,26 @@ var userSchema = new Schema({
picture: String,
refreshToken: String,
accessToken: String,
groups: [String],
perms: [String],
deleted: { type: Boolean, default: false }
employmentType: {
type: String,
enum: ['hourly', 'salary'],
default: 'hourly',
required: true
},
unpaidTravel: {
type: Number,
default: 0,
required: true
},
deleted: {
type: Boolean,
default: false
}
});
userSchema.methods.hasPermission = function(perm) {

View File

@ -1,37 +1,70 @@
var mongoose = require('mongoose')
Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
var workorderSchema = new Schema({
biomedId: Number,
client: { type: ObjectId, ref: 'Client' },
emails: [String],
createdOn: Date,
createdBy: { type: ObjectId, ref: 'User' },
modifiedBy: { type: ObjectId, ref: 'User' },
reason: String,
maintenanceType: String,
remarks: String,
status: String,
scheduling: {
start: Date,
end: Date
},
calendarId: String,
techs: [{ type: ObjectId, ref: 'User' }],
history: [{
oldValues: {},
newValues: {},
modifiedBy: { type: ObjectId, ref: 'User' }
}],
deleted: { type: Boolean, default: false },
invoiceNumber: String,
invoicedOn: Date,
checkNumber: String,
paidOn: Date,
alternativeContact: String,
trackingNumber: String,
devices: [{ type: ObjectId, ref: 'Device' }]
biomedId: Number,
client: {type: ObjectId, ref: 'Client'},
emails: [String],
createdOn: Date,
createdBy: {type: ObjectId, ref: 'User'},
modifiedBy: {type: ObjectId, ref: 'User'},
reason: String,
maintenanceType: String,
remarks: String,
status: String,
scheduling: {
start: Date,
end: Date
},
calendarId: String,
techs: [{type: ObjectId, ref: 'User'}],
history: [{
oldValues: {},
newValues: {},
modifiedBy: {type: ObjectId, ref: 'User'}
}],
deleted: {type: Boolean, default: false},
invoiceNumber: String,
invoicedTime: String,
invoicedOn: Date,
checkNumber: String,
paidOn: Date,
alternativeContact: String,
trackingNumber: String,
devices: [{type: ObjectId, ref: 'Device'}],
workorderType: {
type: String,
enum: [
'office',
'anesthesia',
'biomed',
'bsp',
'ice',
'imaging',
'sales',
'sterile-processing',
'depot',
'trace-gas',
'room-air-exchange',
'isolation-panels',
'ups-systems',
'relocation',
'ice-maker',
'waste-management-system',
'medgas',
'staffing',
'ert',
'shop',
'break',
'pto',
'meeting',
'event',
'weather',
'legacy'
],
default: 'legacy'
},
});
module.exports = mongoose.model('Workorder', workorderSchema);