mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
Changes
This commit is contained in:
64
app/controllers/db.js
Normal file
64
app/controllers/db.js
Normal file
@ -0,0 +1,64 @@
|
||||
var mongoose = require('mongoose');
|
||||
|
||||
var TimeClockSpan = mongoose.model('TimeClockSpan');
|
||||
var Workorder = mongoose.model('Workorder');
|
||||
|
||||
var db = {};
|
||||
|
||||
db.spans = {
|
||||
forWeek: function(week) {
|
||||
const startOfWeek = week.clone();
|
||||
const endOfWeek = week.clone().endOf('week');
|
||||
|
||||
const query = {
|
||||
start: {
|
||||
$gte: startOfWeek,
|
||||
$lte: endOfWeek
|
||||
}
|
||||
};
|
||||
|
||||
return TimeClockSpan.find(query);
|
||||
},
|
||||
forWeekByUser: function(week, user) {
|
||||
const startOfWeek = week.clone();
|
||||
const endOfWeek = week.clone().endOf('week');
|
||||
|
||||
const query = {
|
||||
start: {
|
||||
$gte: startOfWeek,
|
||||
$lte: endOfWeek
|
||||
},
|
||||
user: user
|
||||
};
|
||||
|
||||
return TimeClockSpan.find(query);
|
||||
}
|
||||
};
|
||||
|
||||
db.workorders = {
|
||||
findByIds: function(ids) {
|
||||
const query = {
|
||||
_id: {
|
||||
$in: ids
|
||||
}
|
||||
};
|
||||
|
||||
return Workorder.find(query);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = db;
|
||||
|
||||
|
||||
function findWorkordersById(ids) {
|
||||
const query = {
|
||||
_id: {
|
||||
$in: ids
|
||||
}
|
||||
};
|
||||
|
||||
return Workorder
|
||||
.find(query)
|
||||
.populate('client', 'name identifier')
|
||||
.exec();
|
||||
}
|
Reference in New Issue
Block a user