Skip to content

Instantly share code, notes, and snippets.

@TheRadioGuy
Created December 13, 2017 15:31
Show Gist options
  • Select an option

  • Save TheRadioGuy/997e405dfd5dd943f49488de733b94c5 to your computer and use it in GitHub Desktop.

Select an option

Save TheRadioGuy/997e405dfd5dd943f49488de733b94c5 to your computer and use it in GitHub Desktop.
NodeJS
var getMessages = async function(login, loginMy){
if(isEmpty(login) || isEmpty(loginMy)){
return(u(ERROR_PARAMS_EMPTY_CODE, 'Some params is empty', true));
return false;
}
var resp = await connection.query("SELECT * FROM messages WHERE fromU = '"+login+"' AND toU = '"+loginMy+"' UNION SELECT * FROM messages WHERE fromU = '"+loginMy+"' AND toU = '"+login+"' ORDER BY date DESC");
var messagesOne=[];
async.forEachOf(resp, function (value, key, callback) {
value['from'] = value['fromU'];
value['to'] = value['toU'];
value['fromU']=undefined;
value['toU']=undefined;
messagesOne.push(value);
callback();
}, function (err) {
if (err) console.error(err.message);
// configs is now a map of JSON data
console.log('return!');
return(u(SUCCESSFUL_GET_MESSAGES, messagesOne, false));
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment