Skip to content

Commit

Permalink
Merge pull request #3 from Nexmo/markl-refine-es6-changes
Browse files Browse the repository at this point in the history
Complete ES6 refactoring
  • Loading branch information
Mark Lewin authored Nov 15, 2018
2 parents a864705 + 4ec0184 commit 627eebc
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ app
.get(handleInboundSms)
.post(handleInboundSms);

let concat_sms = []; // Array of message objects
const concat_sms = []; // Array of message objects

function handleInboundSms(request, response) {
const handleInboundSms = (request, response) => {
const params = Object.assign(request.query, request.body);

if (params['concat'] === 'true') {
console.dir(params)
if (params['concat'] == 'true') {
/* This is a concatenated message. Add it to an array
so that we can process it later. */
concat_sms.push({
Expand All @@ -27,9 +27,7 @@ function handleInboundSms(request, response) {

/* Do we have all the message parts yet? They might
not arrive consecutively. */
let parts_for_ref = concat_sms.filter(function (part) {
return part.ref == params['concat-ref'];
});
const parts_for_ref = concat_sms.filter(part => part.ref == params['concat-ref']);

// Is this the last message part for this reference?
if (parts_for_ref.length == params['concat-total']) {
Expand All @@ -45,31 +43,24 @@ function handleInboundSms(request, response) {
response.status(204).send();
}

function processConcatSms(all_parts) {

// Order all the message parts
all_parts.sort(function (a, b) {
if (Number(a.part) < Number(b.part)) {
return -1;
} else {
return 1;
}
})
const processConcatSms = (all_parts) => {

let concat_message = '';
// Sort the message parts
all_parts.sort((a, b) => a.part - b.part);

// Reassemble the message from the parts
let concat_message = '';
for (i = 0; i < all_parts.length; i++) {
concat_message += all_parts[i].message;
}

displaySms(all_parts[0].from, concat_message);
}

function displaySms(msisdn, text) {
const displaySms = (msisdn, text) => {
console.log('FROM: ' + msisdn);
console.log('MESSAGE: ' + text);
console.log('---');
}

app.listen(process.env.PORT);
app.listen(process.env.PORT);

0 comments on commit 627eebc

Please sign in to comment.