Skip to content

Instantly share code, notes, and snippets.

@dperussina
Last active July 19, 2017 20:49
Show Gist options
  • Save dperussina/a16d7b8218ee00e41b397654c484e34c to your computer and use it in GitHub Desktop.
Save dperussina/a16d7b8218ee00e41b397654c484e34c to your computer and use it in GitHub Desktop.
var TAGNET = require('tagnet-tools');
var U = TAGNET.utility.u;
var SQL = TAGNET.sql;
var ORIGIN = parseInt(process.argv[2]);
var DESTINATION = parseInt(process.argv[3]);
U.log('[Copying ServiceLevels from ORIGIN to DESTINATION]', ORIGIN, DESTINATION);
function getOriginNotes() {
var query = "SELECT * FROM " +
" [tagnet].[dbo].[tagnet_AppointmentSPN_PartnerServiceLevels] " +
" WHERE PartnerID = " + ORIGIN + " ";
SQL.tagnet(query, function (err, reply) {
if (err) {
U.error('[getOriginNotes error]', err, reply);
return;
}
U.log('[Get levels success]', reply);
setDestinationNotes(reply)
});
}
function setDestinationNotes(notes) {
function process(data) {
var insert = 'INSERT INTO [tagnet].[dbo].[tagnet_AppointmentSPN_PartnerServiceLevels]' +
"(" +
" PartnerID" +
",[ServiceLevel]" +
" ,[ServiceDescription]" +
")" +
"VALUES" +
"(" +
DESTINATION +
", '" + data.ServiceLevel + "'" +
", '" + data.ServiceDescription.replace(/'/g, "\''") + "'" +
")";
return function (cb) {
SQL.tagnet(insert, function (err, reply) {
if (err) {
U.error('[setDestinationNotes insert query error]', insert);
}
cb(false, null);
});
};
}
TAGNET.flow.queue_task(notes, process, function (err, reply) {
if (err) {
U.error('[SetLevels queue_task error]', err, reply);
return;
}
U.log('[SetLevels queue_task ]', reply);
});
}
getOriginNotes();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment