Latest work

This commit is contained in:
Dobie Wollert
2015-04-19 21:15:06 -04:00
parent 8cfff70ce0
commit 397b828024
12 changed files with 200 additions and 70 deletions

View File

@ -85,7 +85,7 @@ exports.create = function(req, res, next) {
var client = new Client({
name: req.body.name,
identifier: req.body.identifier,
identifier: req.body.identifier.toUpperCase(),
contacts: req.body.contacts,
address: req.body.address,
notes: req.body.notes,
@ -106,13 +106,44 @@ exports.create = function(req, res, next) {
})
};
exports.isUnique = function(req, res, next) {
var field = req.param('field');
var value = req.param('value');
var key = req.param('key');
if (!field || !value) {
return res.json(400, 'missing field or value');
}
var query = {};
if (field === 'identifier') {
query[field] = value.toUpperCase();
} else {
query[field] = value;
}
if (key) {
query['_id'] = { $ne: key };
}
Client.find(query)
.exec(function(err, result) {
if (err) return next(err);
res.json({
isUnique: result.length === 0
});
});
};
exports.update = function(req, res, next) {
var id = req.param('client_id');
log.info("clients.update %s %j", id, req.body);
return Client.findById(id, function(err, client) {
client.name = req.body.name;
client.identifier = req.body.identifier;
client.identifier = req.body.identifier.toUpperCase();
client.contacts = req.body.contacts;
client.address = req.body.address;
client.frequencies = req.body.frequencies;

View File

@ -132,7 +132,7 @@ module.exports = function(config, calendar) {
return callback(null);
var description = generateDescription(client, workorder, req.user, null, techs);
var techDescription = appendNotes(description, client);
var techDescription = appendNotes(description, client, workorder);
var to = req.body.emails;
var techTo = generateToLine(techs);
@ -302,7 +302,7 @@ module.exports = function(config, calendar) {
var description = generateDescription(client, workorder, createdBy, modifiedBy, techs);
var techDescription = appendNotes(description, client);
var techDescription = appendNotes(description, client, workorder);
var to = req.body.emails;
var techTo = generateToLine(techs);
@ -394,17 +394,21 @@ function generateLocation(client) {
return sprintf("%(street1)s %(street2)s %(city)s, %(state)s. %(zip)s", data);
}
function appendNotes(message, client) {
function appendNotes(message, client, workorder) {
var template =
"%(message)s\n" +
"Tech Notes:\n" +
" %(notes)s\n" +
"\n" +
"Alternative Contact:\n" +
" %(alternativeContact)s\n" +
"\n";
if (client.notes && client.notes['tech']) {
var resources = {
message: message || '',
notes: client.notes['tech'] || ''
notes: client.notes['tech'] || '',
alternativeContact: workorder.alternativeContact || ''
};
return sprintf(template, resources);
@ -491,7 +495,6 @@ function generateDescription(client, workorder, createdBy, modifiedBy) {
}
function generateAttendees(techs, workorder) {
console.log('here');
return techs.map(function(t) { return t.email; }).concat(workorder.emails);
}