Skip to content

Commit

Permalink
Merge pull request #254 from slco-2016/v4
Browse files Browse the repository at this point in the history
Resolves bugs related to date, col val types, twilio responses
  • Loading branch information
kuanb authored Dec 5, 2016
2 parents 35dddba + 1d87642 commit d6561c9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 17 deletions.
20 changes: 11 additions & 9 deletions app/controllers/voice.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ module.exports = {
Organizations.findOneByPhone(toNumber)
.then((resp) => {
organizationNumber = resp && resp.phone ? resp.phone : '';
console.log('\n\n');console.log('\n\n');
console.log('got call');console.log('got call');
console.log('got call', resp);
console.log('got call - organizationNumber', organizationNumber);

return Communications.findByValue(fromNumber);
}).then((resp) => {
Expand All @@ -61,6 +57,7 @@ module.exports = {
twilioResponse.dial({callerId: organizationNumber, });
}

// this will make the text-to-voice in twilio read the phone number more clearly
try {
organizationNumber = organizationNumber.replace(/\D+/g, '');
organizationNumber = organizationNumber.replace(/(\d{1})(\d{3})(\d{3})(\d{4})/, '$1 ($2) $3-$4');
Expand All @@ -86,8 +83,10 @@ module.exports = {
return message.update({content: req.body.TranscriptionText,});
});
}
}).then(() => res.send('ok'))
.catch(res.error500);
}).then(() => {
const emptyResponse = twilio.TwimlResponse().toString();
res.send(emptyResponse);
}).catch(res.error500);
},

status(req, res) {
Expand All @@ -110,7 +109,8 @@ module.exports = {
return null;
}
}).then((notification) => {
res.send('ok');
const emptyResponse = twilio.TwimlResponse().toString();
res.send(emptyResponse);
}).catch(res.error500);
}
},
Expand Down Expand Up @@ -239,8 +239,10 @@ module.exports = {
}
});
}
}).then(() => res.send('ok'))
.catch(res.error500);
}).then(() => {
const emptyResponse = twilio.TwimlResponse().toString();
res.send(emptyResponse);
}).catch(res.error500);
},

new(req, res) {
Expand Down
9 changes: 9 additions & 0 deletions app/models/capture.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ class CaptureBoard {
static findByOrg (orgId) {
return new Promise((fulfill, reject) => {
db('msgs')
.select('msgs.msgid',
'msgs.convo',
'msgs.content',
'msgs.inbound',
'msgs.created',
'convos.subject',
'comms.type',
'comms.value',
'commconns.name')
.leftJoin('convos', 'msgs.convo', 'convos.convid')
.leftJoin('comms', 'comms.commid', 'msgs.comm')
.leftJoin('commconns', 'commconns.commconnid', 'comms.commid')
Expand Down
22 changes: 16 additions & 6 deletions app/models/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ const moment = require('moment');
const momentTz = require('moment-timezone');

const resourceRequire = require('../lib/resourceRequire');
const OutboundVoiceMessages = resourceRequire('models', 'OutboundVoiceMessages');

const Alerts = resourceRequire('models', 'Alerts');
const Conversations = resourceRequire('models', 'Conversations');
const Messages = resourceRequire('models', 'Messages');
const OutboundVoiceMessages = resourceRequire('models', 'OutboundVoiceMessages');
const Users = resourceRequire('models', 'Users');

const voice = resourceRequire('lib', 'voice');
Expand Down Expand Up @@ -46,8 +48,6 @@ class Notifications extends BaseModel {
static checkAndSendNotifications () {
return new Promise((fulfill, reject) => {
db('notifications')
// .select("notifications.*", "comms.type", "comms.value")
// .leftJoin("comms", "notifications.comm", "comms.commid")
.where('send', '<', db.fn.now())
.andWhere('notifications.sent', false)
.andWhere('notifications.closed', false)
Expand All @@ -65,7 +65,17 @@ class Notifications extends BaseModel {
} else {
return this.sendTextorEmailNotification(notification);
}
}).then((resp) => {
}).then((notifications) => {
return new Promise((fulfill, reject) => {
fulfill(notifications);
});
}).map((notification) => {
let targetUserId = notification.cm;
let createdByUserId = notification.cm;
let subject = 'Notification Sent';
let message = `Message subject \"${notification.subject}\" was sent and will appear as a sent message in the conversation stream.`;
return Alerts.createForUser(targetUserId, createdByUserId, subject, message);
}).then(() => {
fulfill();
}).catch(reject);
});
Expand All @@ -77,7 +87,7 @@ class Notifications extends BaseModel {
.then((ovm) => {
return voice.processPendingOutboundVoiceMessages(ovm);
}).then(() => {
fulfill();
fulfill(notification);
}).catch(reject);
});
};
Expand All @@ -103,7 +113,7 @@ class Notifications extends BaseModel {
sendMethod.then(() => {
return this.markAsSent(notification.notificationid);
}).then(() => {
fulfill();
fulfill(notification);
}).catch(reject);

}).catch(reject);
Expand Down
16 changes: 16 additions & 0 deletions migrations/20161205151256_dob_update_in_clients_table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

exports.up = function(knex, Promise) {
return Promise.all([

knex.raw('ALTER TABLE clients ALTER COLUMN dob TYPE date'),

]);
};

exports.down = function(knex, Promise) {
return Promise.all([

knex.raw('ALTER TABLE clients ALTER COLUMN dob TYPE timestamptz'),

]);
};
2 changes: 0 additions & 2 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,6 @@ $(function() {
}

function buildUserActivityChart(users) {
console.log(users);

// Set height based off of remaining users post filter operation
var height = Math.max(users.length * 30, 100);
c3.generate({
Expand Down

0 comments on commit d6561c9

Please sign in to comment.