f6361f10988de90d02bf996f243e9dcb52c6a49a
[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 _0x64cc=['describe','sequelize','order','LOCK','UPDATE','Contact','User','Agent','name','length','UserId','push','MoveContactManagedDialer','transaction','CmHopperFinal','COUNT','literal','`scheduledat`\x20>=\x20','format','\x22%s\x22','YYYY-MM-DD\x20HH:mm:ss','\x20,\x201,\x20null','contactsRescheduled','CountReScheduled','GetContactRecallMe','GetCmHopperPreview','keys','util','moment','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','request','info','debug','stringify','error','code','CmHopper,\x20%s,\x20%s','message','request\x20sent','catch','GetCmHopper','CmHopper','findAll','options','raw','where','attributes','limit','include','map','model','then','ShowCmHopper','find','CreateCmHopper','create','body','UpdateCmHopper','update','DestroyCmHopper','destroy','GetContactDialer','CmContact'];(function(_0x39109d,_0x84e5ce){var _0x138412=function(_0x1c0418){while(--_0x1c0418){_0x39109d['push'](_0x39109d['shift']());}};_0x138412(++_0x84e5ce);}(_0x64cc,0x1cb));var _0xc64c=function(_0x190a34,_0x3cd1a2){_0x190a34=_0x190a34-0x0;var _0x1a83f3=_0x64cc[_0x190a34];return _0x1a83f3;};'use strict';var _=require('lodash');var util=require(_0xc64c('0x0'));var moment=require(_0xc64c('0x1'));var BPromise=require('bluebird');var rs=require(_0xc64c('0x2'));var fs=require('fs');var Redis=require(_0xc64c('0x3'));var db=require(_0xc64c('0x4'))['db'];var utils=require(_0xc64c('0x5'));var logger=require(_0xc64c('0x6'))(_0xc64c('0x7'));var config=require(_0xc64c('0x8'));var jayson=require(_0xc64c('0x9'));var client=jayson[_0xc64c('0xa')][_0xc64c('0xb')]({'port':0x232a});function respondWithRpcPromise(_0x2a6925,_0x15e5c6,_0x36723a){return new BPromise(function(_0xd65b63,_0x28ec3f){return client[_0xc64c('0xc')](_0x2a6925,_0x36723a)['then'](function(_0x52a620){logger[_0xc64c('0xd')]('CmHopper,\x20%s,\x20%s',_0x15e5c6,'request\x20sent');logger[_0xc64c('0xe')]('CmHopper,\x20%s,\x20%s,\x20%s',_0x15e5c6,'request\x20sent',JSON[_0xc64c('0xf')](_0x52a620));if(_0x52a620[_0xc64c('0x10')]){if(_0x52a620[_0xc64c('0x10')][_0xc64c('0x11')]===0x1f4){logger[_0xc64c('0x10')](_0xc64c('0x12'),_0x15e5c6,_0x52a620[_0xc64c('0x10')]['message']);return _0x28ec3f(_0x52a620[_0xc64c('0x10')][_0xc64c('0x13')]);}logger[_0xc64c('0x10')](_0xc64c('0x12'),_0x15e5c6,_0x52a620[_0xc64c('0x10')][_0xc64c('0x13')]);return _0xd65b63(_0x52a620[_0xc64c('0x10')]['message']);}else{logger[_0xc64c('0xd')](_0xc64c('0x12'),_0x15e5c6,_0xc64c('0x14'));_0xd65b63(_0x52a620['result'][_0xc64c('0x13')]);}})[_0xc64c('0x15')](function(_0x321581){logger[_0xc64c('0x10')](_0xc64c('0x12'),_0x15e5c6,_0x321581);_0x28ec3f(_0x321581);});});}exports[_0xc64c('0x16')]=function(_0x3a59ec){var _0x1ea849=this;return new Promise(function(_0x58cf72,_0x482f13){return db[_0xc64c('0x17')][_0xc64c('0x18')]({'raw':_0x3a59ec[_0xc64c('0x19')]?_0x3a59ec['options'][_0xc64c('0x1a')]===undefined?!![]:![]:!![],'where':_0x3a59ec['options']?_0x3a59ec[_0xc64c('0x19')][_0xc64c('0x1b')]||null:null,'attributes':_0x3a59ec[_0xc64c('0x19')]?_0x3a59ec['options'][_0xc64c('0x1c')]||null:null,'limit':_0x3a59ec['options']?_0x3a59ec[_0xc64c('0x19')][_0xc64c('0x1d')]||null:null,'include':_0x3a59ec[_0xc64c('0x19')]?_0x3a59ec[_0xc64c('0x19')][_0xc64c('0x1e')]?_[_0xc64c('0x1f')](_0x3a59ec[_0xc64c('0x19')][_0xc64c('0x1e')],function(_0x406ced){return{'model':db[_0x406ced['model']],'as':_0x406ced['as'],'attributes':_0x406ced[_0xc64c('0x1c')],'include':_0x406ced['include']?_[_0xc64c('0x1f')](_0x406ced[_0xc64c('0x1e')],function(_0x10a3c5){return{'model':db[_0x10a3c5[_0xc64c('0x20')]],'as':_0x10a3c5['as'],'attributes':_0x10a3c5[_0xc64c('0x1c')],'include':_0x10a3c5[_0xc64c('0x1e')]?_[_0xc64c('0x1f')](_0x10a3c5[_0xc64c('0x1e')],function(_0x121eeb){return{'model':db[_0x121eeb[_0xc64c('0x20')]],'as':_0x121eeb['as'],'attributes':_0x121eeb['attributes']};}):[]};}):[]};}):[]:[]})[_0xc64c('0x21')](function(_0x4d2b06){logger[_0xc64c('0xd')]('GetCmHopper',_0x3a59ec);logger[_0xc64c('0xe')]('GetCmHopper',_0x3a59ec,JSON[_0xc64c('0xf')](_0x4d2b06));_0x58cf72(_0x4d2b06);})[_0xc64c('0x15')](function(_0x452ae3){logger[_0xc64c('0x10')](_0xc64c('0x16'),_0x452ae3[_0xc64c('0x13')],_0x3a59ec);_0x482f13(_0x1ea849[_0xc64c('0x10')](0x1f4,_0x452ae3[_0xc64c('0x13')]));});});};exports[_0xc64c('0x22')]=function(_0x4418f5){var _0x3af6a4=this;return new Promise(function(_0x53d154,_0x3eeb4f){return db[_0xc64c('0x17')][_0xc64c('0x23')]({'raw':_0x4418f5[_0xc64c('0x19')]?_0x4418f5['options'][_0xc64c('0x1a')]===undefined?!![]:![]:!![],'where':_0x4418f5[_0xc64c('0x19')]?_0x4418f5['options'][_0xc64c('0x1b')]||null:null,'attributes':_0x4418f5['options']?_0x4418f5[_0xc64c('0x19')][_0xc64c('0x1c')]||null:null,'include':_0x4418f5['options']?_0x4418f5[_0xc64c('0x19')][_0xc64c('0x1e')]?_['map'](_0x4418f5['options'][_0xc64c('0x1e')],function(_0x557f8e){return{'model':db[_0x557f8e[_0xc64c('0x20')]],'as':_0x557f8e['as'],'attributes':_0x557f8e[_0xc64c('0x1c')],'include':_0x557f8e[_0xc64c('0x1e')]?_[_0xc64c('0x1f')](_0x557f8e[_0xc64c('0x1e')],function(_0x469d6d){return{'model':db[_0x469d6d[_0xc64c('0x20')]],'as':_0x469d6d['as'],'attributes':_0x469d6d['attributes'],'include':_0x469d6d['include']?_[_0xc64c('0x1f')](_0x469d6d[_0xc64c('0x1e')],function(_0x3f5387){return{'model':db[_0x3f5387[_0xc64c('0x20')]],'as':_0x3f5387['as'],'attributes':_0x3f5387[_0xc64c('0x1c')]};}):[]};}):[]};}):[]:[]})[_0xc64c('0x21')](function(_0x39bf03){logger[_0xc64c('0xd')](_0xc64c('0x22'),_0x4418f5);logger[_0xc64c('0xe')](_0xc64c('0x22'),_0x4418f5,JSON[_0xc64c('0xf')](_0x39bf03));_0x53d154(_0x39bf03);})[_0xc64c('0x15')](function(_0x403ba3){logger[_0xc64c('0x10')]('ShowCmHopper',_0x403ba3['message'],_0x4418f5);_0x3eeb4f(_0x3af6a4[_0xc64c('0x10')](0x1f4,_0x403ba3[_0xc64c('0x13')]));});});};exports[_0xc64c('0x24')]=function(_0x53561a){var _0xa002fb=this;return new Promise(function(_0x2893e0,_0x7fc219){return db['CmHopper'][_0xc64c('0x25')](_0x53561a[_0xc64c('0x26')],{'raw':_0x53561a[_0xc64c('0x19')]?_0x53561a[_0xc64c('0x19')]['raw']===undefined?!![]:![]:!![]})[_0xc64c('0x21')](function(_0x55f1c4){logger['info'](_0xc64c('0x24'),_0x53561a);logger[_0xc64c('0xe')]('CreateCmHopper',_0x53561a,JSON[_0xc64c('0xf')](_0x55f1c4));_0x2893e0(_0x55f1c4);})[_0xc64c('0x15')](function(_0x2d9593){logger[_0xc64c('0x10')]('CreateCmHopper',_0x2d9593[_0xc64c('0x13')],_0x53561a);_0x7fc219(_0xa002fb[_0xc64c('0x10')](0x1f4,_0x2d9593[_0xc64c('0x13')]));});});};exports[_0xc64c('0x27')]=function(_0x50a3e5){var _0x3817fa=this;return new Promise(function(_0x207dd4,_0x4628e3){return db[_0xc64c('0x17')][_0xc64c('0x28')](_0x50a3e5[_0xc64c('0x26')],{'raw':_0x50a3e5[_0xc64c('0x19')]?_0x50a3e5['options'][_0xc64c('0x1a')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x50a3e5['options']?_0x50a3e5[_0xc64c('0x19')][_0xc64c('0x1b')]||null:null,'attributes':_0x50a3e5['options']?_0x50a3e5['options']['attributes']||null:null,'limit':_0x50a3e5[_0xc64c('0x19')]?_0x50a3e5[_0xc64c('0x19')][_0xc64c('0x1d')]||null:null})[_0xc64c('0x21')](function(_0x2c1dee){logger[_0xc64c('0xd')](_0xc64c('0x27'),_0x50a3e5);logger[_0xc64c('0xe')]('UpdateCmHopper',_0x50a3e5,JSON['stringify'](_0x2c1dee));_0x207dd4(_0x2c1dee);})[_0xc64c('0x15')](function(_0x22da80){logger[_0xc64c('0x10')](_0xc64c('0x27'),_0x22da80['message'],_0x50a3e5);_0x4628e3(_0x3817fa[_0xc64c('0x10')](0x1f4,_0x22da80[_0xc64c('0x13')]));});});};exports[_0xc64c('0x29')]=function(_0x2f0f26){var _0x491d4d=this;return new Promise(function(_0xfc58dd,_0x1bb656){return db[_0xc64c('0x17')][_0xc64c('0x2a')]({'where':_0x2f0f26[_0xc64c('0x19')]?_0x2f0f26[_0xc64c('0x19')][_0xc64c('0x1b')]||null:null})['then'](function(_0x58e94d){logger[_0xc64c('0xd')](_0xc64c('0x29'),_0x2f0f26);logger[_0xc64c('0xe')](_0xc64c('0x29'),_0x2f0f26,JSON[_0xc64c('0xf')](_0x58e94d));_0xfc58dd(_0x58e94d);})[_0xc64c('0x15')](function(_0x62633f){logger[_0xc64c('0x10')]('DestroyCmHopper',_0x62633f[_0xc64c('0x13')],_0x2f0f26);_0x1bb656(_0x491d4d[_0xc64c('0x10')](0x1f4,_0x62633f[_0xc64c('0x13')]));});});};exports[_0xc64c('0x2b')]=function(_0x3c5d74){var _0x280718=this;return new Promise(function(_0x5f3c22,_0x118cc5){return db[_0xc64c('0x2c')][_0xc64c('0x2d')]()[_0xc64c('0x21')](function(_0x2e2a04){return db[_0xc64c('0x2e')]['transaction'](function(_0x59ef1c){return db[_0xc64c('0x17')][_0xc64c('0x18')]({'where':_0x3c5d74[_0xc64c('0x19')]?_0x3c5d74[_0xc64c('0x19')][_0xc64c('0x1b')]||null:null,'attributes':_0x3c5d74[_0xc64c('0x19')]?_0x3c5d74['options'][_0xc64c('0x1c')]||null:null,'limit':_0x3c5d74[_0xc64c('0x19')]?_0x3c5d74[_0xc64c('0x19')][_0xc64c('0x1d')]||null:null,'order':_0x3c5d74[_0xc64c('0x19')]?_0x3c5d74[_0xc64c('0x19')][_0xc64c('0x2f')]||null:null,'transaction':_0x59ef1c,'lock':_0x59ef1c[_0xc64c('0x30')][_0xc64c('0x31')],'include':[{'model':db[_0xc64c('0x2c')],'as':_0xc64c('0x32'),'attributes':_['keys'](_0x2e2a04)},{'model':db[_0xc64c('0x33')],'as':_0xc64c('0x34'),'attributes':['id',_0xc64c('0x35'),'voicePause']}]})['then'](function(_0x55eaf4){var _0x2a5c8d=[];var _0x26fccd=[];for(var _0x57c30b=0x0;_0x57c30b<_0x55eaf4[_0xc64c('0x36')];_0x57c30b+=0x1){if(!_0x26fccd['includes'](_0x55eaf4[_0x57c30b][_0xc64c('0x37')])){_0x26fccd[_0xc64c('0x38')](_0x55eaf4[_0x57c30b][_0xc64c('0x37')]);_0x2a5c8d['push'](_0x55eaf4[_0x57c30b]['update'](_0x3c5d74[_0xc64c('0x26')],{'transaction':_0x59ef1c}));}}return BPromise['all'](_0x2a5c8d);});})[_0xc64c('0x21')](function(_0x3005e2){logger['info'](_0xc64c('0x2b'),_0x3c5d74);logger[_0xc64c('0xe')](_0xc64c('0x2b'),_0x3c5d74,JSON[_0xc64c('0xf')](_0x3005e2));_0x5f3c22(_0x3005e2);})[_0xc64c('0x15')](function(_0x28ed26){logger[_0xc64c('0x10')]('GetContactDialer',_0x28ed26[_0xc64c('0x13')],_0x3c5d74);_0x118cc5(_0x280718[_0xc64c('0x10')](0x1f4,_0x28ed26[_0xc64c('0x13')]));});});});};exports[_0xc64c('0x39')]=function(_0x2fee28){var _0x3c2cf8=this;return new Promise(function(_0x223f3e,_0x73674a){return db[_0xc64c('0x2e')][_0xc64c('0x3a')](function(_0x49cd1d){return db[_0xc64c('0x3b')][_0xc64c('0x25')](_0x2fee28['body'],{'raw':_0x2fee28[_0xc64c('0x19')]?_0x2fee28[_0xc64c('0x19')]['raw']===undefined?!![]:![]:!![],'transaction':_0x49cd1d})['then'](function(){return db[_0xc64c('0x17')][_0xc64c('0x2a')]({'where':_0x2fee28['options']?_0x2fee28['options'][_0xc64c('0x1b')]||null:null,'transaction':_0x49cd1d});});})[_0xc64c('0x21')](function(_0x7297bf){logger[_0xc64c('0xd')](_0xc64c('0x39'),_0x2fee28);logger['debug']('MoveContactManagedDialer',_0x2fee28,JSON[_0xc64c('0xf')](_0x7297bf));_0x223f3e(_0x7297bf);})[_0xc64c('0x15')](function(_0x2dafcc){logger[_0xc64c('0x10')]('MoveContactManagedDialer',_0x2dafcc[_0xc64c('0x13')],_0x2fee28);_0x73674a(_0x3c2cf8[_0xc64c('0x10')](0x1f4,_0x2dafcc[_0xc64c('0x13')]));});});};exports['CountReScheduled']=function(_0x4da647){var _0x1a3b52=this;return new Promise(function(_0x5df973,_0x49764d){return db[_0xc64c('0x17')][_0xc64c('0x18')]({'raw':_0x4da647[_0xc64c('0x19')]?_0x4da647[_0xc64c('0x19')][_0xc64c('0x1a')]===undefined?!![]:![]:!![],'where':_0x4da647[_0xc64c('0x19')]?_0x4da647[_0xc64c('0x19')][_0xc64c('0x1b')]||null:null,'attributes':[[db[_0xc64c('0x2e')]['fn'](_0xc64c('0x3c'),db[_0xc64c('0x2e')]['fn']('IF',db[_0xc64c('0x2e')][_0xc64c('0x3d')](_0xc64c('0x3e')+util[_0xc64c('0x3f')](_0xc64c('0x40'),moment()[_0xc64c('0x3f')](_0xc64c('0x41')))+_0xc64c('0x42')))),_0xc64c('0x43')]]})[_0xc64c('0x21')](function(_0x1d9a2a){logger['info'](_0xc64c('0x44'),_0x4da647);logger['debug'](_0xc64c('0x44'),_0x4da647,JSON[_0xc64c('0xf')](_0x1d9a2a));_0x5df973(_0x1d9a2a);})[_0xc64c('0x15')](function(_0x51c763){logger[_0xc64c('0x10')]('CountReScheduled',_0x51c763[_0xc64c('0x13')],_0x4da647);_0x49764d(_0x1a3b52[_0xc64c('0x10')](0x1f4,_0x51c763[_0xc64c('0x13')]));});});};exports[_0xc64c('0x45')]=function(_0x26f873){var _0x19c8c1=this;return new Promise(function(_0x53d54e,_0x41350b){return db[_0xc64c('0x2c')]['describe']()[_0xc64c('0x21')](function(_0x5ab43e){return db[_0xc64c('0x2e')][_0xc64c('0x3a')](function(_0x5075e8){return db['CmHopper'][_0xc64c('0x18')]({'where':_0x26f873['options']?_0x26f873['options'][_0xc64c('0x1b')]||null:null,'attributes':_0x26f873[_0xc64c('0x19')]?_0x26f873[_0xc64c('0x19')]['attributes']||null:null,'limit':0x1,'order':_0x26f873['options']?_0x26f873[_0xc64c('0x19')][_0xc64c('0x2f')]||null:null,'group':db[_0xc64c('0x17')][_0xc64c('0x37')],'transaction':_0x5075e8,'lock':_0x5075e8['LOCK']['UPDATE'],'include':_0x26f873[_0xc64c('0x19')]?_0x26f873[_0xc64c('0x19')]['include']?_[_0xc64c('0x1f')](_0x26f873[_0xc64c('0x19')][_0xc64c('0x1e')],function(_0x47b0ec){return{'model':db[_0x47b0ec[_0xc64c('0x20')]],'as':_0x47b0ec['as'],'attributes':_0x47b0ec['attributes'],'include':_0x47b0ec[_0xc64c('0x1e')]?_[_0xc64c('0x1f')](_0x47b0ec[_0xc64c('0x1e')],function(_0x1a77de){return{'model':db[_0x1a77de[_0xc64c('0x20')]],'as':_0x1a77de['as'],'attributes':_0x1a77de[_0xc64c('0x1c')],'include':_0x1a77de[_0xc64c('0x1e')]?_['map'](_0x1a77de[_0xc64c('0x1e')],function(_0x281584){return{'model':db[_0x281584['model']],'as':_0x281584['as'],'attributes':_0x281584[_0xc64c('0x1c')]};}):[]};}):[]};}):[]:[]})[_0xc64c('0x21')](function(_0x143036){var _0x1b0263=[];for(var _0x2789d7=0x0;_0x2789d7<_0x143036['length'];_0x2789d7+=0x1){_0x1b0263[_0xc64c('0x38')](_0x143036[_0x2789d7][_0xc64c('0x28')](_0x26f873[_0xc64c('0x26')],{'transaction':_0x5075e8}));}return BPromise['all'](_0x1b0263);});})['then'](function(_0x8ee54e){logger[_0xc64c('0xd')](_0xc64c('0x45'),_0x26f873);logger[_0xc64c('0xe')]('GetContactRecallMe',_0x26f873,JSON[_0xc64c('0xf')](_0x8ee54e));_0x53d54e(_0x8ee54e);})[_0xc64c('0x15')](function(_0x3d946a){logger['error']('GetContactRecallMe',_0x3d946a['message'],_0x26f873);_0x41350b(_0x19c8c1['error'](0x1f4,_0x3d946a['message']));});});});};exports[_0xc64c('0x46')]=function(_0x302e49){var _0x369c63=this;return new Promise(function(_0x1d1363,_0x5b8b24){db[_0xc64c('0x2c')][_0xc64c('0x2d')]()[_0xc64c('0x21')](function(_0x506378){return db['CmHopper'][_0xc64c('0x18')]({'raw':_0x302e49[_0xc64c('0x19')]?_0x302e49['options'][_0xc64c('0x1a')]===undefined?!![]:![]:!![],'where':_0x302e49[_0xc64c('0x19')]?_0x302e49[_0xc64c('0x19')]['where']||null:null,'attributes':_0x302e49['options']?_0x302e49['options'][_0xc64c('0x1c')]||null:null,'limit':_0x302e49[_0xc64c('0x19')]?_0x302e49[_0xc64c('0x19')]['limit']||null:null,'include':_0x302e49[_0xc64c('0x19')]?_0x302e49[_0xc64c('0x19')][_0xc64c('0x1e')]?_[_0xc64c('0x1f')](_0x302e49[_0xc64c('0x19')]['include'],function(_0x3029e7){return{'model':db[_0x3029e7[_0xc64c('0x20')]],'as':_0x3029e7['as'],'attributes':_0x3029e7['as']===_0xc64c('0x32')?_[_0xc64c('0x47')](_0x506378):_0x3029e7[_0xc64c('0x1c')],'include':_0x3029e7['include']?_[_0xc64c('0x1f')](_0x3029e7[_0xc64c('0x1e')],function(_0x2c9fb3){return{'model':db[_0x2c9fb3[_0xc64c('0x20')]],'as':_0x2c9fb3['as'],'attributes':_0x2c9fb3[_0xc64c('0x1c')],'include':_0x2c9fb3['include']?_[_0xc64c('0x1f')](_0x2c9fb3['include'],function(_0x44acee){return{'model':db[_0x44acee[_0xc64c('0x20')]],'as':_0x44acee['as'],'attributes':_0x44acee[_0xc64c('0x1c')]};}):[]};}):[]};}):[]:[]})[_0xc64c('0x21')](function(_0x373706){logger[_0xc64c('0xd')]('GetCmHopper',_0x302e49);logger[_0xc64c('0xe')](_0xc64c('0x16'),_0x302e49,JSON['stringify'](_0x373706));_0x1d1363(_0x373706);})['catch'](function(_0x22c9ec){logger[_0xc64c('0x10')]('GetCmHopper',_0x22c9ec[_0xc64c('0x13')],_0x302e49);_0x5b8b24(_0x369c63[_0xc64c('0x10')](0x1f4,_0x22c9ec[_0xc64c('0x13')]));});});});};