mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
Added a bunch of stuff
This commit is contained in:
73
app/controllers/checkLists.js
Normal file
73
app/controllers/checkLists.js
Normal file
@ -0,0 +1,73 @@
|
||||
var mongoose = require('mongoose'),
|
||||
CheckList = mongoose.model('CheckList');
|
||||
|
||||
var _ = require('lodash');
|
||||
var md5 = require('MD5');
|
||||
|
||||
var log = require('log4node');
|
||||
|
||||
exports.index = function(req, res, next) {
|
||||
log.info('check_lists.index');
|
||||
|
||||
CheckList.find({ deleted: false })
|
||||
.exec(returnResult(res));
|
||||
};
|
||||
|
||||
exports.get = function(req, res, next) {
|
||||
var id = req.param('check_list_id');
|
||||
|
||||
log.info("check_lists.get %s", id);
|
||||
|
||||
CheckList.findById(id)
|
||||
.exec(returnResult(res));
|
||||
};
|
||||
|
||||
exports.create = function(req, res, next) {
|
||||
log.info("check_lists.create %j", res.body);
|
||||
|
||||
var checkList = new CheckList(req.body);
|
||||
checkList.save(returnResult(res));
|
||||
};
|
||||
|
||||
exports.update = function(req, res, next) {
|
||||
var id = req.param('check_list_id');
|
||||
log.info('check_lists.update %s %j', id, req.body);
|
||||
|
||||
CheckList.findById(id, function(err, checkList) {
|
||||
if (err) {
|
||||
log.error("Error: %s", err);
|
||||
res.json(500, err);
|
||||
} else if (!checkList) {
|
||||
res.json(404, 'Unknown CheckList: %s', id);
|
||||
} else {
|
||||
_.assign(checkList, req.body);
|
||||
checkList.save(returnResult(res, checkList));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function returnResult(res, result) {
|
||||
return function(err, data) {
|
||||
if (err) {
|
||||
log.error("Error: %s", err);
|
||||
res.json(500, err);
|
||||
} else {
|
||||
if (result) {
|
||||
res.json(result);
|
||||
} else {
|
||||
res.json(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function mutateResult(res, mutator) {
|
||||
return function(err, results) {
|
||||
if (err) {
|
||||
log.error("Error: %s", err);
|
||||
res.json(500, err);
|
||||
} else {
|
||||
res.json(mutator(results));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
var mongoose = require('mongoose'),
|
||||
Device = mongoose.model('Device');
|
||||
Device = mongoose.model('Device'),
|
||||
TestRun = mongoose.model('TestRun');
|
||||
|
||||
var _ = require('lodash');
|
||||
var md5 = require('MD5');
|
||||
@ -9,7 +10,18 @@ var log = require('log4node');
|
||||
exports.index = function(req, res, next) {
|
||||
log.info('devices.index');
|
||||
|
||||
Device.find({ deleted: false })
|
||||
var query = {
|
||||
deleted: false
|
||||
};
|
||||
|
||||
var deviceType = req.param('deviceType');
|
||||
if (deviceType) {
|
||||
query.deviceType = deviceType;
|
||||
}
|
||||
|
||||
Device.find(query)
|
||||
.populate('deviceType', 'category make model')
|
||||
.populate('client', 'name identifier')
|
||||
.exec(returnResult(res));
|
||||
};
|
||||
|
||||
@ -19,9 +31,25 @@ exports.get = function(req, res, next) {
|
||||
log.info("devices.get %s", id);
|
||||
|
||||
Device.findById(id)
|
||||
.populate('deviceType', 'category make model checkList')
|
||||
.populate('deviceType.checkList', 'name fields')
|
||||
.populate('client', 'name identifier')
|
||||
.exec(returnResult(res));
|
||||
};
|
||||
|
||||
exports.testRuns = function(req, res, next) {
|
||||
var id = req.param('device_id');
|
||||
log.info("devices.testRuns %s", id);
|
||||
|
||||
TestRun.find({device: id, deleted: false })
|
||||
.exec(function(err, devices) {
|
||||
if (err) return next(err);
|
||||
if (!devices) return next(new Error('Failed to load testRuns ' + id));
|
||||
|
||||
res.json(devices);
|
||||
});
|
||||
}
|
||||
|
||||
exports.create = function(req, res, next) {
|
||||
log.info("devices.create %j", res.body);
|
||||
|
||||
|
73
app/controllers/testRuns.js
Normal file
73
app/controllers/testRuns.js
Normal file
@ -0,0 +1,73 @@
|
||||
var mongoose = require('mongoose'),
|
||||
TestRun = mongoose.model('TestRun');
|
||||
|
||||
var _ = require('lodash');
|
||||
var md5 = require('MD5');
|
||||
|
||||
var log = require('log4node');
|
||||
|
||||
exports.index = function(req, res, next) {
|
||||
log.info('test_runs.index');
|
||||
|
||||
TestRun.find({ deleted: false })
|
||||
.exec(returnResult(res));
|
||||
};
|
||||
|
||||
exports.get = function(req, res, next) {
|
||||
var id = req.param('test_run_id');
|
||||
|
||||
log.info("test_runs.get %s", id);
|
||||
|
||||
TestRun.findById(id)
|
||||
.exec(returnResult(res));
|
||||
};
|
||||
|
||||
exports.create = function(req, res, next) {
|
||||
log.info("test_runs.create %j", res.body);
|
||||
|
||||
var testRun = new TestRun(req.body);
|
||||
testRun.save(returnResult(res));
|
||||
};
|
||||
|
||||
exports.update = function(req, res, next) {
|
||||
var id = req.param('test_run_id');
|
||||
log.info('test_runs.update %s %j', id, req.body);
|
||||
|
||||
TestRun.findById(id, function(err, testRun) {
|
||||
if (err) {
|
||||
log.error("Error: %s", err);
|
||||
res.json(500, err);
|
||||
} else if (!testRun) {
|
||||
res.json(404, 'Unknown TestRun: %s', id);
|
||||
} else {
|
||||
_.assign(testRun, req.body);
|
||||
testRun.save(returnResult(res, testRun));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function returnResult(res, result) {
|
||||
return function(err, data) {
|
||||
if (err) {
|
||||
log.error("Error: %s", err);
|
||||
res.json(500, err);
|
||||
} else {
|
||||
if (result) {
|
||||
res.json(result);
|
||||
} else {
|
||||
res.json(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function mutateResult(res, mutator) {
|
||||
return function(err, results) {
|
||||
if (err) {
|
||||
log.error("Error: %s", err);
|
||||
res.json(500, err);
|
||||
} else {
|
||||
res.json(mutator(results));
|
||||
}
|
||||
}
|
||||
}
|
@ -77,7 +77,8 @@ module.exports = function(config, calendar) {
|
||||
scheduling: req.body.scheduling,
|
||||
techs: req.body.techs,
|
||||
alternativeContact: req.body.alternativeContact,
|
||||
trackingNumber: req.body.trackingNumber
|
||||
trackingNumber: req.body.trackingNumber,
|
||||
devices: req.body.devices
|
||||
});
|
||||
|
||||
var notify = req.body._notify || "";
|
||||
@ -241,6 +242,7 @@ module.exports = function(config, calendar) {
|
||||
workorder.paidOn = req.body.paidOn;
|
||||
workorder.alternativeContact = req.body.alternativeContact;
|
||||
workorder.trackingNumber = req.body.trackingNumber;
|
||||
workorder.devices = req.body.devices;
|
||||
callback(err);
|
||||
});
|
||||
},
|
||||
|
11
app/model/checkList.js
Normal file
11
app/model/checkList.js
Normal file
@ -0,0 +1,11 @@
|
||||
var mongoose = require('mongoose')
|
||||
Schema = mongoose.Schema,
|
||||
ObjectId = Schema.ObjectId;
|
||||
|
||||
var checkListSchema = new Schema({
|
||||
name: String,
|
||||
fields: [{}],
|
||||
deleted: { type: Boolean, default: false }
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('CheckList', checkListSchema);
|
@ -11,6 +11,8 @@ var deviceSchema = new Schema({
|
||||
purchaseDate: Date,
|
||||
warrantyExpiration: Date,
|
||||
location: String,
|
||||
frequencyType: String,
|
||||
frequencySchedule: [],
|
||||
deleted: { type: Boolean, default: false }
|
||||
});
|
||||
|
||||
|
@ -10,6 +10,7 @@ var deviceTypeSchema = new Schema({
|
||||
links: String,
|
||||
partsRecommended: String,
|
||||
images: [{ type: String }],
|
||||
checkList: { type: ObjectId, ref: 'CheckList' },
|
||||
deleted: { type: Boolean, default: false }
|
||||
});
|
||||
|
||||
|
14
app/model/testRun.js
Normal file
14
app/model/testRun.js
Normal file
@ -0,0 +1,14 @@
|
||||
var mongoose = require('mongoose')
|
||||
Schema = mongoose.Schema,
|
||||
ObjectId = Schema.ObjectId;
|
||||
|
||||
var testRunSchema = new Schema({
|
||||
device: { type: ObjectId, ref: 'Device' },
|
||||
fields: [{}],
|
||||
date: Date,
|
||||
result: Boolean,
|
||||
comment: String,
|
||||
deleted: { type: Boolean, default: false }
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('TestRun', testRunSchema);
|
@ -30,7 +30,8 @@ var workorderSchema = new Schema({
|
||||
checkNumber: String,
|
||||
paidOn: Date,
|
||||
alternativeContact: String,
|
||||
trackingNumber: String
|
||||
trackingNumber: String,
|
||||
devices: [{ type: ObjectId, ref: 'Device' }]
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('Workorder', workorderSchema);
|
||||
|
@ -64,6 +64,10 @@ html(lang="en", ng-app="biomed", ng-controller="PageCtrl")
|
||||
a(href='/deviceTypes')
|
||||
| Devices
|
||||
|
||||
li(data-match-route='/checkLists.*')
|
||||
a(href='/checkLists')
|
||||
| Check Lists
|
||||
|
||||
li(data-match-route='/posts.*', ng-show="accountHasPermission('system.admin')")
|
||||
a(href='/posts')
|
||||
| Posts
|
||||
|
Reference in New Issue
Block a user