Built motion from commit (unavailable).|2.0.78
[motion2.git] / server / api / cmHopper / cmHopper.rpc.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xcf52=['where','attributes','limit','map','include','model','GetCmHopper','catch','ShowCmHopper','find','CreateCmHopper','create','body','then','update','UpdateCmHopper','DestroyCmHopper','destroy','describe','sequelize','transaction','order','UPDATE','CmContact','Contact','length','all','GetContactDialer','MoveContactManagedDialer','CmHopperFinal','CountReScheduled','COUNT','literal','`scheduledat`\x20>=\x20','format','\x22%s\x22','\x20,\x201,\x20null','contactsRescheduled','GetContactRecallMe','UserId','LOCK','push','lodash','util','bluebird','randomstring','../../mysqldb','../../config/utils','../../config/logger','rpc','jayson/promise','client','http','info','CmHopper,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','CmHopper','findAll','options','raw'];(function(_0x1cea80,_0x21d0d3){var _0x4dfb14=function(_0x117c27){while(--_0x117c27){_0x1cea80['push'](_0x1cea80['shift']());}};_0x4dfb14(++_0x21d0d3);}(_0xcf52,0x6b));var _0x2cf5=function(_0x27a76e,_0x1f6502){_0x27a76e=_0x27a76e-0x0;var _0x34940b=_0xcf52[_0x27a76e];return _0x34940b;};'use strict';var _=require(_0x2cf5('0x0'));var util=require(_0x2cf5('0x1'));var moment=require('moment');var BPromise=require(_0x2cf5('0x2'));var rs=require(_0x2cf5('0x3'));var fs=require('fs');var db=require(_0x2cf5('0x4'))['db'];var utils=require(_0x2cf5('0x5'));var logger=require(_0x2cf5('0x6'))(_0x2cf5('0x7'));var config=require('../../config/environment');var jayson=require(_0x2cf5('0x8'));var client=jayson[_0x2cf5('0x9')][_0x2cf5('0xa')]({'port':0x232a});function respondWithRpcPromise(_0xbdce9e,_0x575538,_0x2e2d03){return new BPromise(function(_0x3bb464,_0x5165da){return client['request'](_0xbdce9e,_0x2e2d03)['then'](function(_0x11bc9c){logger[_0x2cf5('0xb')](_0x2cf5('0xc'),_0x575538,_0x2cf5('0xd'));logger[_0x2cf5('0xe')]('CmHopper,\x20%s,\x20%s,\x20%s',_0x575538,_0x2cf5('0xd'),JSON[_0x2cf5('0xf')](_0x11bc9c));if(_0x11bc9c[_0x2cf5('0x10')]){if(_0x11bc9c[_0x2cf5('0x10')][_0x2cf5('0x11')]===0x1f4){logger[_0x2cf5('0x10')]('CmHopper,\x20%s,\x20%s',_0x575538,_0x11bc9c[_0x2cf5('0x10')][_0x2cf5('0x12')]);return _0x5165da(_0x11bc9c[_0x2cf5('0x10')][_0x2cf5('0x12')]);}logger['error'](_0x2cf5('0xc'),_0x575538,_0x11bc9c[_0x2cf5('0x10')][_0x2cf5('0x12')]);return _0x3bb464(_0x11bc9c['error'][_0x2cf5('0x12')]);}else{logger[_0x2cf5('0xb')]('CmHopper,\x20%s,\x20%s',_0x575538,_0x2cf5('0xd'));_0x3bb464(_0x11bc9c['result'][_0x2cf5('0x12')]);}})['catch'](function(_0x27efe0){logger['error'](_0x2cf5('0xc'),_0x575538,_0x27efe0);_0x5165da(_0x27efe0);});});}exports['GetCmHopper']=function(_0x3a00b9){var _0x43d20f=this;return new Promise(function(_0x3b6065,_0x5da874){return db[_0x2cf5('0x13')][_0x2cf5('0x14')]({'raw':_0x3a00b9[_0x2cf5('0x15')]?_0x3a00b9[_0x2cf5('0x15')][_0x2cf5('0x16')]===undefined?!![]:![]:!![],'where':_0x3a00b9['options']?_0x3a00b9['options'][_0x2cf5('0x17')]||null:null,'attributes':_0x3a00b9[_0x2cf5('0x15')]?_0x3a00b9['options'][_0x2cf5('0x18')]||null:null,'limit':_0x3a00b9['options']?_0x3a00b9[_0x2cf5('0x15')][_0x2cf5('0x19')]||null:null,'include':_0x3a00b9[_0x2cf5('0x15')]?_0x3a00b9['options']['include']?_[_0x2cf5('0x1a')](_0x3a00b9[_0x2cf5('0x15')][_0x2cf5('0x1b')],function(_0x431cfd){return{'model':db[_0x431cfd['model']],'as':_0x431cfd['as'],'attributes':_0x431cfd[_0x2cf5('0x18')],'include':_0x431cfd['include']?_[_0x2cf5('0x1a')](_0x431cfd[_0x2cf5('0x1b')],function(_0x1f650a){return{'model':db[_0x1f650a[_0x2cf5('0x1c')]],'as':_0x1f650a['as'],'attributes':_0x1f650a['attributes'],'include':_0x1f650a[_0x2cf5('0x1b')]?_[_0x2cf5('0x1a')](_0x1f650a[_0x2cf5('0x1b')],function(_0x2a3106){return{'model':db[_0x2a3106['model']],'as':_0x2a3106['as'],'attributes':_0x2a3106['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x14f60a){logger['info'](_0x2cf5('0x1d'),_0x3a00b9);logger[_0x2cf5('0xe')](_0x2cf5('0x1d'),_0x3a00b9,JSON[_0x2cf5('0xf')](_0x14f60a));_0x3b6065(_0x14f60a);})[_0x2cf5('0x1e')](function(_0x2e2472){logger[_0x2cf5('0x10')](_0x2cf5('0x1d'),_0x2e2472[_0x2cf5('0x12')],_0x3a00b9);_0x5da874(_0x43d20f[_0x2cf5('0x10')](0x1f4,_0x2e2472[_0x2cf5('0x12')]));});});};exports[_0x2cf5('0x1f')]=function(_0x14100d){var _0x3b6969=this;return new Promise(function(_0x18f8d8,_0x232f5d){return db[_0x2cf5('0x13')][_0x2cf5('0x20')]({'raw':_0x14100d[_0x2cf5('0x15')]?_0x14100d[_0x2cf5('0x15')]['raw']===undefined?!![]:![]:!![],'where':_0x14100d['options']?_0x14100d['options']['where']||null:null,'attributes':_0x14100d['options']?_0x14100d[_0x2cf5('0x15')]['attributes']||null:null,'include':_0x14100d[_0x2cf5('0x15')]?_0x14100d[_0x2cf5('0x15')][_0x2cf5('0x1b')]?_[_0x2cf5('0x1a')](_0x14100d[_0x2cf5('0x15')][_0x2cf5('0x1b')],function(_0x5054c9){return{'model':db[_0x5054c9[_0x2cf5('0x1c')]],'as':_0x5054c9['as'],'attributes':_0x5054c9[_0x2cf5('0x18')],'include':_0x5054c9[_0x2cf5('0x1b')]?_['map'](_0x5054c9['include'],function(_0x3c95ff){return{'model':db[_0x3c95ff[_0x2cf5('0x1c')]],'as':_0x3c95ff['as'],'attributes':_0x3c95ff[_0x2cf5('0x18')],'include':_0x3c95ff[_0x2cf5('0x1b')]?_[_0x2cf5('0x1a')](_0x3c95ff[_0x2cf5('0x1b')],function(_0xd2f884){return{'model':db[_0xd2f884['model']],'as':_0xd2f884['as'],'attributes':_0xd2f884['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x21ddec){logger['info']('ShowCmHopper',_0x14100d);logger[_0x2cf5('0xe')](_0x2cf5('0x1f'),_0x14100d,JSON[_0x2cf5('0xf')](_0x21ddec));_0x18f8d8(_0x21ddec);})['catch'](function(_0x408097){logger[_0x2cf5('0x10')](_0x2cf5('0x1f'),_0x408097[_0x2cf5('0x12')],_0x14100d);_0x232f5d(_0x3b6969[_0x2cf5('0x10')](0x1f4,_0x408097['message']));});});};exports[_0x2cf5('0x21')]=function(_0x45e214){var _0x4e3ce1=this;return new Promise(function(_0xc12206,_0x1cdc59){return db[_0x2cf5('0x13')][_0x2cf5('0x22')](_0x45e214[_0x2cf5('0x23')],{'raw':_0x45e214[_0x2cf5('0x15')]?_0x45e214['options'][_0x2cf5('0x16')]===undefined?!![]:![]:!![]})[_0x2cf5('0x24')](function(_0x3480fe){logger[_0x2cf5('0xb')](_0x2cf5('0x21'),_0x45e214);logger[_0x2cf5('0xe')](_0x2cf5('0x21'),_0x45e214,JSON[_0x2cf5('0xf')](_0x3480fe));_0xc12206(_0x3480fe);})[_0x2cf5('0x1e')](function(_0x46277d){logger['error'](_0x2cf5('0x21'),_0x46277d[_0x2cf5('0x12')],_0x45e214);_0x1cdc59(_0x4e3ce1[_0x2cf5('0x10')](0x1f4,_0x46277d['message']));});});};exports['UpdateCmHopper']=function(_0x1600b7){var _0x2eb99e=this;return new Promise(function(_0x27fc3c,_0x237cd7){return db[_0x2cf5('0x13')][_0x2cf5('0x25')](_0x1600b7[_0x2cf5('0x23')],{'raw':_0x1600b7[_0x2cf5('0x15')]?_0x1600b7[_0x2cf5('0x15')][_0x2cf5('0x16')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x1600b7['options']?_0x1600b7['options'][_0x2cf5('0x17')]||null:null,'attributes':_0x1600b7[_0x2cf5('0x15')]?_0x1600b7['options'][_0x2cf5('0x18')]||null:null,'limit':_0x1600b7[_0x2cf5('0x15')]?_0x1600b7[_0x2cf5('0x15')][_0x2cf5('0x19')]||null:null})[_0x2cf5('0x24')](function(_0x299ea9){logger[_0x2cf5('0xb')](_0x2cf5('0x26'),_0x1600b7);logger[_0x2cf5('0xe')](_0x2cf5('0x26'),_0x1600b7,JSON['stringify'](_0x299ea9));_0x27fc3c(_0x299ea9);})['catch'](function(_0x56470a){logger[_0x2cf5('0x10')](_0x2cf5('0x26'),_0x56470a['message'],_0x1600b7);_0x237cd7(_0x2eb99e[_0x2cf5('0x10')](0x1f4,_0x56470a['message']));});});};exports[_0x2cf5('0x27')]=function(_0x316564){var _0x4646e4=this;return new Promise(function(_0x3e36b3,_0x4c73ac){return db[_0x2cf5('0x13')][_0x2cf5('0x28')]({'where':_0x316564[_0x2cf5('0x15')]?_0x316564['options'][_0x2cf5('0x17')]||null:null})[_0x2cf5('0x24')](function(_0x34ffff){logger[_0x2cf5('0xb')](_0x2cf5('0x27'),_0x316564);logger[_0x2cf5('0xe')](_0x2cf5('0x27'),_0x316564,JSON[_0x2cf5('0xf')](_0x34ffff));_0x3e36b3(_0x34ffff);})[_0x2cf5('0x1e')](function(_0x12630e){logger[_0x2cf5('0x10')]('DestroyCmHopper',_0x12630e[_0x2cf5('0x12')],_0x316564);_0x4c73ac(_0x4646e4[_0x2cf5('0x10')](0x1f4,_0x12630e[_0x2cf5('0x12')]));});});};exports['GetContactDialer']=function(_0xa56b3){var _0x18b23c=this;return new Promise(function(_0x203e6,_0x18f9cd){return db['CmContact'][_0x2cf5('0x29')]()[_0x2cf5('0x24')](function(_0x21438f){return db[_0x2cf5('0x2a')][_0x2cf5('0x2b')](function(_0x57cd19){return db['CmHopper']['findAll']({'where':_0xa56b3[_0x2cf5('0x15')]?_0xa56b3[_0x2cf5('0x15')][_0x2cf5('0x17')]||null:null,'attributes':_0xa56b3[_0x2cf5('0x15')]?_0xa56b3[_0x2cf5('0x15')][_0x2cf5('0x18')]||null:null,'limit':_0xa56b3[_0x2cf5('0x15')]?_0xa56b3[_0x2cf5('0x15')][_0x2cf5('0x19')]||null:null,'order':_0xa56b3[_0x2cf5('0x15')]?_0xa56b3[_0x2cf5('0x15')][_0x2cf5('0x2c')]||null:null,'transaction':_0x57cd19,'lock':_0x57cd19['LOCK'][_0x2cf5('0x2d')],'include':[{'model':db[_0x2cf5('0x2e')],'as':_0x2cf5('0x2f'),'attributes':_['keys'](_0x21438f)}]})[_0x2cf5('0x24')](function(_0x18a95b){var _0x4e9f38=[];for(var _0x3b348b=0x0;_0x3b348b<_0x18a95b[_0x2cf5('0x30')];_0x3b348b+=0x1){_0x4e9f38['push'](_0x18a95b[_0x3b348b][_0x2cf5('0x25')](_0xa56b3[_0x2cf5('0x23')],{'transaction':_0x57cd19}));}return BPromise[_0x2cf5('0x31')](_0x4e9f38);});})[_0x2cf5('0x24')](function(_0x351948){logger[_0x2cf5('0xb')](_0x2cf5('0x32'),_0xa56b3);logger['debug']('GetContactDialer',_0xa56b3,JSON[_0x2cf5('0xf')](_0x351948));_0x203e6(_0x351948);})[_0x2cf5('0x1e')](function(_0x46cfc4){logger[_0x2cf5('0x10')]('GetContactDialer',_0x46cfc4[_0x2cf5('0x12')],_0xa56b3);_0x18f9cd(_0x18b23c[_0x2cf5('0x10')](0x1f4,_0x46cfc4[_0x2cf5('0x12')]));});});});};exports[_0x2cf5('0x33')]=function(_0xa56b03){var _0x19dd1e=this;return new Promise(function(_0x398b77,_0x5971b3){return db[_0x2cf5('0x2a')][_0x2cf5('0x2b')](function(_0x50163b){return db[_0x2cf5('0x34')][_0x2cf5('0x22')](_0xa56b03[_0x2cf5('0x23')],{'raw':_0xa56b03[_0x2cf5('0x15')]?_0xa56b03[_0x2cf5('0x15')]['raw']===undefined?!![]:![]:!![],'transaction':_0x50163b})[_0x2cf5('0x24')](function(){return db[_0x2cf5('0x13')][_0x2cf5('0x28')]({'where':_0xa56b03[_0x2cf5('0x15')]?_0xa56b03[_0x2cf5('0x15')][_0x2cf5('0x17')]||null:null,'transaction':_0x50163b});});})[_0x2cf5('0x24')](function(_0xa6ea1e){logger[_0x2cf5('0xb')]('MoveContactManagedDialer',_0xa56b03);logger[_0x2cf5('0xe')](_0x2cf5('0x33'),_0xa56b03,JSON['stringify'](_0xa6ea1e));_0x398b77(_0xa6ea1e);})[_0x2cf5('0x1e')](function(_0x4910cb){logger[_0x2cf5('0x10')](_0x2cf5('0x33'),_0x4910cb['message'],_0xa56b03);_0x5971b3(_0x19dd1e[_0x2cf5('0x10')](0x1f4,_0x4910cb[_0x2cf5('0x12')]));});});};exports[_0x2cf5('0x35')]=function(_0x2b380e){var _0x4d30c3=this;return new Promise(function(_0x3738de,_0x7dbeb2){return db[_0x2cf5('0x13')][_0x2cf5('0x14')]({'raw':_0x2b380e[_0x2cf5('0x15')]?_0x2b380e[_0x2cf5('0x15')]['raw']===undefined?!![]:![]:!![],'where':_0x2b380e[_0x2cf5('0x15')]?_0x2b380e[_0x2cf5('0x15')][_0x2cf5('0x17')]||null:null,'attributes':[[db[_0x2cf5('0x2a')]['fn'](_0x2cf5('0x36'),db['sequelize']['fn']('IF',db[_0x2cf5('0x2a')][_0x2cf5('0x37')](_0x2cf5('0x38')+util[_0x2cf5('0x39')](_0x2cf5('0x3a'),moment()['format']('YYYY-MM-DD\x20HH:mm:ss'))+_0x2cf5('0x3b')))),_0x2cf5('0x3c')]]})['then'](function(_0x5d3251){logger[_0x2cf5('0xb')]('CountReScheduled',_0x2b380e);logger['debug'](_0x2cf5('0x35'),_0x2b380e,JSON[_0x2cf5('0xf')](_0x5d3251));_0x3738de(_0x5d3251);})[_0x2cf5('0x1e')](function(_0x34d88b){logger[_0x2cf5('0x10')](_0x2cf5('0x35'),_0x34d88b[_0x2cf5('0x12')],_0x2b380e);_0x7dbeb2(_0x4d30c3[_0x2cf5('0x10')](0x1f4,_0x34d88b[_0x2cf5('0x12')]));});});};exports[_0x2cf5('0x3d')]=function(_0xe13d52){var _0x44406b=this;return new Promise(function(_0x44f298,_0x3ce925){return db[_0x2cf5('0x2e')][_0x2cf5('0x29')]()[_0x2cf5('0x24')](function(_0x4d50ee){return db[_0x2cf5('0x2a')]['transaction'](function(_0x24f8c2){return db['CmHopper'][_0x2cf5('0x14')]({'where':_0xe13d52[_0x2cf5('0x15')]?_0xe13d52['options'][_0x2cf5('0x17')]||null:null,'attributes':_0xe13d52[_0x2cf5('0x15')]?_0xe13d52[_0x2cf5('0x15')][_0x2cf5('0x18')]||null:null,'limit':0x1,'order':_0xe13d52[_0x2cf5('0x15')]?_0xe13d52[_0x2cf5('0x15')][_0x2cf5('0x2c')]||null:null,'group':db[_0x2cf5('0x13')][_0x2cf5('0x3e')],'transaction':_0x24f8c2,'lock':_0x24f8c2[_0x2cf5('0x3f')]['UPDATE'],'include':_0xe13d52[_0x2cf5('0x15')]?_0xe13d52[_0x2cf5('0x15')][_0x2cf5('0x1b')]?_[_0x2cf5('0x1a')](_0xe13d52[_0x2cf5('0x15')][_0x2cf5('0x1b')],function(_0x1a79b4){return{'model':db[_0x1a79b4['model']],'as':_0x1a79b4['as'],'attributes':_0x1a79b4[_0x2cf5('0x18')],'include':_0x1a79b4[_0x2cf5('0x1b')]?_[_0x2cf5('0x1a')](_0x1a79b4['include'],function(_0x5fd1cd){return{'model':db[_0x5fd1cd[_0x2cf5('0x1c')]],'as':_0x5fd1cd['as'],'attributes':_0x5fd1cd[_0x2cf5('0x18')],'include':_0x5fd1cd[_0x2cf5('0x1b')]?_['map'](_0x5fd1cd[_0x2cf5('0x1b')],function(_0x517ca5){return{'model':db[_0x517ca5['model']],'as':_0x517ca5['as'],'attributes':_0x517ca5['attributes']};}):[]};}):[]};}):[]:[]})[_0x2cf5('0x24')](function(_0x5d32eb){var _0x4ce41f=[];for(var _0x4978aa=0x0;_0x4978aa<_0x5d32eb[_0x2cf5('0x30')];_0x4978aa+=0x1){_0x4ce41f[_0x2cf5('0x40')](_0x5d32eb[_0x4978aa][_0x2cf5('0x25')](_0xe13d52[_0x2cf5('0x23')],{'transaction':_0x24f8c2}));}return BPromise[_0x2cf5('0x31')](_0x4ce41f);});})[_0x2cf5('0x24')](function(_0x691d19){logger[_0x2cf5('0xb')](_0x2cf5('0x3d'),_0xe13d52);logger[_0x2cf5('0xe')](_0x2cf5('0x3d'),_0xe13d52,JSON[_0x2cf5('0xf')](_0x691d19));_0x44f298(_0x691d19);})[_0x2cf5('0x1e')](function(_0x30ff12){logger[_0x2cf5('0x10')]('GetContactRecallMe',_0x30ff12[_0x2cf5('0x12')],_0xe13d52);_0x3ce925(_0x44406b[_0x2cf5('0x10')](0x1f4,_0x30ff12['message']));});});});};