8981a650fee3584b1692344ddea5fa249fae6007
[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 _0xb10b=['order','LOCK','UPDATE','Contact','keys','User','Agent','name','voicePause','length','push','CmHopperFinal','MoveContactManagedDialer','CountReScheduled','COUNT','`scheduledat`\x20>=\x20','format','\x22%s\x22','\x20,\x201,\x20null','contactsRescheduled','GetContactRecallMe','all','lodash','moment','bluebird','randomstring','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','http','request','then','info','CmHopper,\x20%s,\x20%s','CmHopper,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','message','result','GetCmHopper','CmHopper','findAll','options','raw','where','attributes','include','map','model','debug','catch','ShowCmHopper','CreateCmHopper','create','body','update','limit','UpdateCmHopper','destroy','DestroyCmHopper','GetContactDialer','CmContact','describe','sequelize','transaction'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0xb10b,0x12a));var _0xbb10=function(_0x305c31,_0x466b17){_0x305c31=_0x305c31-0x0;var _0x17f39f=_0xb10b[_0x305c31];return _0x17f39f;};'use strict';var _=require(_0xbb10('0x0'));var util=require('util');var moment=require(_0xbb10('0x1'));var BPromise=require(_0xbb10('0x2'));var rs=require(_0xbb10('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0xbb10('0x4'))['db'];var utils=require(_0xbb10('0x5'));var logger=require(_0xbb10('0x6'))(_0xbb10('0x7'));var config=require(_0xbb10('0x8'));var jayson=require(_0xbb10('0x9'));var client=jayson['client'][_0xbb10('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x3cdd53,_0x513741,_0x1b9e94){return new BPromise(function(_0x3fb675,_0x21370f){return client[_0xbb10('0xb')](_0x3cdd53,_0x1b9e94)[_0xbb10('0xc')](function(_0x1ce33e){logger[_0xbb10('0xd')](_0xbb10('0xe'),_0x513741,'request\x20sent');logger['debug'](_0xbb10('0xf'),_0x513741,_0xbb10('0x10'),JSON[_0xbb10('0x11')](_0x1ce33e));if(_0x1ce33e['error']){if(_0x1ce33e[_0xbb10('0x12')]['code']===0x1f4){logger[_0xbb10('0x12')](_0xbb10('0xe'),_0x513741,_0x1ce33e[_0xbb10('0x12')][_0xbb10('0x13')]);return _0x21370f(_0x1ce33e[_0xbb10('0x12')][_0xbb10('0x13')]);}logger['error'](_0xbb10('0xe'),_0x513741,_0x1ce33e[_0xbb10('0x12')][_0xbb10('0x13')]);return _0x3fb675(_0x1ce33e[_0xbb10('0x12')][_0xbb10('0x13')]);}else{logger[_0xbb10('0xd')](_0xbb10('0xe'),_0x513741,_0xbb10('0x10'));_0x3fb675(_0x1ce33e[_0xbb10('0x14')][_0xbb10('0x13')]);}})['catch'](function(_0x2eca0f){logger[_0xbb10('0x12')](_0xbb10('0xe'),_0x513741,_0x2eca0f);_0x21370f(_0x2eca0f);});});}exports[_0xbb10('0x15')]=function(_0x378da8){var _0x1682a4=this;return new Promise(function(_0x575cca,_0x30efc6){return db[_0xbb10('0x16')][_0xbb10('0x17')]({'raw':_0x378da8['options']?_0x378da8[_0xbb10('0x18')][_0xbb10('0x19')]===undefined?!![]:![]:!![],'where':_0x378da8[_0xbb10('0x18')]?_0x378da8[_0xbb10('0x18')][_0xbb10('0x1a')]||null:null,'attributes':_0x378da8[_0xbb10('0x18')]?_0x378da8['options'][_0xbb10('0x1b')]||null:null,'limit':_0x378da8[_0xbb10('0x18')]?_0x378da8['options']['limit']||null:null,'include':_0x378da8[_0xbb10('0x18')]?_0x378da8[_0xbb10('0x18')][_0xbb10('0x1c')]?_[_0xbb10('0x1d')](_0x378da8[_0xbb10('0x18')][_0xbb10('0x1c')],function(_0x407cb4){return{'model':db[_0x407cb4[_0xbb10('0x1e')]],'as':_0x407cb4['as'],'attributes':_0x407cb4[_0xbb10('0x1b')],'include':_0x407cb4[_0xbb10('0x1c')]?_[_0xbb10('0x1d')](_0x407cb4[_0xbb10('0x1c')],function(_0x537898){return{'model':db[_0x537898['model']],'as':_0x537898['as'],'attributes':_0x537898['attributes'],'include':_0x537898[_0xbb10('0x1c')]?_[_0xbb10('0x1d')](_0x537898[_0xbb10('0x1c')],function(_0x4e25ff){return{'model':db[_0x4e25ff[_0xbb10('0x1e')]],'as':_0x4e25ff['as'],'attributes':_0x4e25ff[_0xbb10('0x1b')]};}):[]};}):[]};}):[]:[]})[_0xbb10('0xc')](function(_0x1d5e95){logger[_0xbb10('0xd')](_0xbb10('0x15'),_0x378da8);logger[_0xbb10('0x1f')]('GetCmHopper',_0x378da8,JSON[_0xbb10('0x11')](_0x1d5e95));_0x575cca(_0x1d5e95);})[_0xbb10('0x20')](function(_0xfc3595){logger[_0xbb10('0x12')](_0xbb10('0x15'),_0xfc3595[_0xbb10('0x13')],_0x378da8);_0x30efc6(_0x1682a4['error'](0x1f4,_0xfc3595[_0xbb10('0x13')]));});});};exports['ShowCmHopper']=function(_0x448d5c){var _0x56f2da=this;return new Promise(function(_0x16ad2a,_0x1dcc9c){return db[_0xbb10('0x16')]['find']({'raw':_0x448d5c['options']?_0x448d5c[_0xbb10('0x18')][_0xbb10('0x19')]===undefined?!![]:![]:!![],'where':_0x448d5c['options']?_0x448d5c[_0xbb10('0x18')][_0xbb10('0x1a')]||null:null,'attributes':_0x448d5c[_0xbb10('0x18')]?_0x448d5c[_0xbb10('0x18')][_0xbb10('0x1b')]||null:null,'include':_0x448d5c[_0xbb10('0x18')]?_0x448d5c[_0xbb10('0x18')]['include']?_[_0xbb10('0x1d')](_0x448d5c[_0xbb10('0x18')][_0xbb10('0x1c')],function(_0x8c1ce6){return{'model':db[_0x8c1ce6[_0xbb10('0x1e')]],'as':_0x8c1ce6['as'],'attributes':_0x8c1ce6[_0xbb10('0x1b')],'include':_0x8c1ce6[_0xbb10('0x1c')]?_[_0xbb10('0x1d')](_0x8c1ce6[_0xbb10('0x1c')],function(_0x56943c){return{'model':db[_0x56943c[_0xbb10('0x1e')]],'as':_0x56943c['as'],'attributes':_0x56943c[_0xbb10('0x1b')],'include':_0x56943c[_0xbb10('0x1c')]?_[_0xbb10('0x1d')](_0x56943c['include'],function(_0x111762){return{'model':db[_0x111762['model']],'as':_0x111762['as'],'attributes':_0x111762['attributes']};}):[]};}):[]};}):[]:[]})[_0xbb10('0xc')](function(_0x40c164){logger[_0xbb10('0xd')](_0xbb10('0x21'),_0x448d5c);logger[_0xbb10('0x1f')](_0xbb10('0x21'),_0x448d5c,JSON['stringify'](_0x40c164));_0x16ad2a(_0x40c164);})[_0xbb10('0x20')](function(_0x25d72f){logger['error']('ShowCmHopper',_0x25d72f['message'],_0x448d5c);_0x1dcc9c(_0x56f2da[_0xbb10('0x12')](0x1f4,_0x25d72f[_0xbb10('0x13')]));});});};exports[_0xbb10('0x22')]=function(_0x4d5a9b){var _0x3c0cd7=this;return new Promise(function(_0x3e8538,_0x4345f3){return db['CmHopper'][_0xbb10('0x23')](_0x4d5a9b[_0xbb10('0x24')],{'raw':_0x4d5a9b[_0xbb10('0x18')]?_0x4d5a9b[_0xbb10('0x18')]['raw']===undefined?!![]:![]:!![]})[_0xbb10('0xc')](function(_0x110eb5){logger['info'](_0xbb10('0x22'),_0x4d5a9b);logger[_0xbb10('0x1f')](_0xbb10('0x22'),_0x4d5a9b,JSON[_0xbb10('0x11')](_0x110eb5));_0x3e8538(_0x110eb5);})[_0xbb10('0x20')](function(_0x185a52){logger['error'](_0xbb10('0x22'),_0x185a52[_0xbb10('0x13')],_0x4d5a9b);_0x4345f3(_0x3c0cd7[_0xbb10('0x12')](0x1f4,_0x185a52[_0xbb10('0x13')]));});});};exports['UpdateCmHopper']=function(_0x3fff6c){var _0x331751=this;return new Promise(function(_0x23dc18,_0x403beb){return db['CmHopper'][_0xbb10('0x25')](_0x3fff6c[_0xbb10('0x24')],{'raw':_0x3fff6c['options']?_0x3fff6c['options'][_0xbb10('0x19')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x3fff6c['options']?_0x3fff6c[_0xbb10('0x18')][_0xbb10('0x1a')]||null:null,'attributes':_0x3fff6c['options']?_0x3fff6c[_0xbb10('0x18')][_0xbb10('0x1b')]||null:null,'limit':_0x3fff6c[_0xbb10('0x18')]?_0x3fff6c['options'][_0xbb10('0x26')]||null:null})[_0xbb10('0xc')](function(_0x3b9fdf){logger[_0xbb10('0xd')](_0xbb10('0x27'),_0x3fff6c);logger[_0xbb10('0x1f')](_0xbb10('0x27'),_0x3fff6c,JSON[_0xbb10('0x11')](_0x3b9fdf));_0x23dc18(_0x3b9fdf);})[_0xbb10('0x20')](function(_0x43b948){logger[_0xbb10('0x12')](_0xbb10('0x27'),_0x43b948['message'],_0x3fff6c);_0x403beb(_0x331751[_0xbb10('0x12')](0x1f4,_0x43b948[_0xbb10('0x13')]));});});};exports['DestroyCmHopper']=function(_0x14e1cb){var _0x2f5027=this;return new Promise(function(_0x1a7df6,_0x5a5226){return db[_0xbb10('0x16')][_0xbb10('0x28')]({'where':_0x14e1cb[_0xbb10('0x18')]?_0x14e1cb['options']['where']||null:null})[_0xbb10('0xc')](function(_0x76a208){logger[_0xbb10('0xd')]('DestroyCmHopper',_0x14e1cb);logger['debug'](_0xbb10('0x29'),_0x14e1cb,JSON[_0xbb10('0x11')](_0x76a208));_0x1a7df6(_0x76a208);})[_0xbb10('0x20')](function(_0xf820fe){logger[_0xbb10('0x12')](_0xbb10('0x29'),_0xf820fe[_0xbb10('0x13')],_0x14e1cb);_0x5a5226(_0x2f5027[_0xbb10('0x12')](0x1f4,_0xf820fe[_0xbb10('0x13')]));});});};exports[_0xbb10('0x2a')]=function(_0x550111){var _0x5eafac=this;return new Promise(function(_0x412e13,_0x467dba){return db[_0xbb10('0x2b')][_0xbb10('0x2c')]()[_0xbb10('0xc')](function(_0x440f9e){return db[_0xbb10('0x2d')][_0xbb10('0x2e')](function(_0x1c0d8f){return db[_0xbb10('0x16')][_0xbb10('0x17')]({'where':_0x550111[_0xbb10('0x18')]?_0x550111[_0xbb10('0x18')][_0xbb10('0x1a')]||null:null,'attributes':_0x550111[_0xbb10('0x18')]?_0x550111['options'][_0xbb10('0x1b')]||null:null,'limit':_0x550111['options']?_0x550111[_0xbb10('0x18')][_0xbb10('0x26')]||null:null,'order':_0x550111[_0xbb10('0x18')]?_0x550111[_0xbb10('0x18')][_0xbb10('0x2f')]||null:null,'transaction':_0x1c0d8f,'lock':_0x1c0d8f[_0xbb10('0x30')][_0xbb10('0x31')],'include':[{'model':db[_0xbb10('0x2b')],'as':_0xbb10('0x32'),'attributes':_[_0xbb10('0x33')](_0x440f9e)},{'model':db[_0xbb10('0x34')],'as':_0xbb10('0x35'),'attributes':['id',_0xbb10('0x36'),_0xbb10('0x37')]}]})[_0xbb10('0xc')](function(_0x5de0cc){var _0x4571b6=[];for(var _0x466eb7=0x0;_0x466eb7<_0x5de0cc[_0xbb10('0x38')];_0x466eb7+=0x1){_0x4571b6[_0xbb10('0x39')](_0x5de0cc[_0x466eb7][_0xbb10('0x25')](_0x550111[_0xbb10('0x24')],{'transaction':_0x1c0d8f}));}return BPromise['all'](_0x4571b6);});})[_0xbb10('0xc')](function(_0x4731ce){logger[_0xbb10('0xd')](_0xbb10('0x2a'),_0x550111);logger[_0xbb10('0x1f')](_0xbb10('0x2a'),_0x550111,JSON[_0xbb10('0x11')](_0x4731ce));_0x412e13(_0x4731ce);})[_0xbb10('0x20')](function(_0x205e01){logger[_0xbb10('0x12')](_0xbb10('0x2a'),_0x205e01[_0xbb10('0x13')],_0x550111);_0x467dba(_0x5eafac[_0xbb10('0x12')](0x1f4,_0x205e01['message']));});});});};exports['MoveContactManagedDialer']=function(_0x16272d){var _0x3e6338=this;return new Promise(function(_0x3d0cb7,_0x8b0a7d){return db['sequelize']['transaction'](function(_0x79411e){return db[_0xbb10('0x3a')][_0xbb10('0x23')](_0x16272d[_0xbb10('0x24')],{'raw':_0x16272d[_0xbb10('0x18')]?_0x16272d[_0xbb10('0x18')][_0xbb10('0x19')]===undefined?!![]:![]:!![],'transaction':_0x79411e})['then'](function(){return db[_0xbb10('0x16')][_0xbb10('0x28')]({'where':_0x16272d['options']?_0x16272d['options']['where']||null:null,'transaction':_0x79411e});});})[_0xbb10('0xc')](function(_0x31c727){logger[_0xbb10('0xd')]('MoveContactManagedDialer',_0x16272d);logger['debug']('MoveContactManagedDialer',_0x16272d,JSON[_0xbb10('0x11')](_0x31c727));_0x3d0cb7(_0x31c727);})[_0xbb10('0x20')](function(_0x45167a){logger['error'](_0xbb10('0x3b'),_0x45167a[_0xbb10('0x13')],_0x16272d);_0x8b0a7d(_0x3e6338['error'](0x1f4,_0x45167a['message']));});});};exports[_0xbb10('0x3c')]=function(_0x308896){var _0xd77753=this;return new Promise(function(_0x237246,_0x54b7c5){return db[_0xbb10('0x16')][_0xbb10('0x17')]({'raw':_0x308896[_0xbb10('0x18')]?_0x308896['options'][_0xbb10('0x19')]===undefined?!![]:![]:!![],'where':_0x308896[_0xbb10('0x18')]?_0x308896[_0xbb10('0x18')]['where']||null:null,'attributes':[[db[_0xbb10('0x2d')]['fn'](_0xbb10('0x3d'),db[_0xbb10('0x2d')]['fn']('IF',db[_0xbb10('0x2d')]['literal'](_0xbb10('0x3e')+util[_0xbb10('0x3f')](_0xbb10('0x40'),moment()[_0xbb10('0x3f')]('YYYY-MM-DD\x20HH:mm:ss'))+_0xbb10('0x41')))),_0xbb10('0x42')]]})[_0xbb10('0xc')](function(_0x2ceb3e){logger[_0xbb10('0xd')](_0xbb10('0x3c'),_0x308896);logger[_0xbb10('0x1f')]('CountReScheduled',_0x308896,JSON['stringify'](_0x2ceb3e));_0x237246(_0x2ceb3e);})['catch'](function(_0xdfbc0b){logger[_0xbb10('0x12')](_0xbb10('0x3c'),_0xdfbc0b['message'],_0x308896);_0x54b7c5(_0xd77753['error'](0x1f4,_0xdfbc0b[_0xbb10('0x13')]));});});};exports[_0xbb10('0x43')]=function(_0xd9e743){var _0x3a9677=this;return new Promise(function(_0x260e06,_0x1ad2ed){return db['CmContact'][_0xbb10('0x2c')]()[_0xbb10('0xc')](function(_0x270fdb){return db[_0xbb10('0x2d')][_0xbb10('0x2e')](function(_0x5bfc68){return db['CmHopper']['findAll']({'where':_0xd9e743[_0xbb10('0x18')]?_0xd9e743[_0xbb10('0x18')][_0xbb10('0x1a')]||null:null,'attributes':_0xd9e743[_0xbb10('0x18')]?_0xd9e743[_0xbb10('0x18')][_0xbb10('0x1b')]||null:null,'limit':0x1,'order':_0xd9e743['options']?_0xd9e743[_0xbb10('0x18')]['order']||null:null,'group':db['CmHopper']['UserId'],'transaction':_0x5bfc68,'lock':_0x5bfc68[_0xbb10('0x30')][_0xbb10('0x31')],'include':_0xd9e743[_0xbb10('0x18')]?_0xd9e743[_0xbb10('0x18')]['include']?_[_0xbb10('0x1d')](_0xd9e743['options']['include'],function(_0x165fe9){return{'model':db[_0x165fe9[_0xbb10('0x1e')]],'as':_0x165fe9['as'],'attributes':_0x165fe9[_0xbb10('0x1b')],'include':_0x165fe9[_0xbb10('0x1c')]?_[_0xbb10('0x1d')](_0x165fe9['include'],function(_0x2d52ea){return{'model':db[_0x2d52ea[_0xbb10('0x1e')]],'as':_0x2d52ea['as'],'attributes':_0x2d52ea[_0xbb10('0x1b')],'include':_0x2d52ea[_0xbb10('0x1c')]?_[_0xbb10('0x1d')](_0x2d52ea[_0xbb10('0x1c')],function(_0x174395){return{'model':db[_0x174395['model']],'as':_0x174395['as'],'attributes':_0x174395[_0xbb10('0x1b')]};}):[]};}):[]};}):[]:[]})[_0xbb10('0xc')](function(_0x30f3ea){var _0x322b41=[];for(var _0x37b20e=0x0;_0x37b20e<_0x30f3ea[_0xbb10('0x38')];_0x37b20e+=0x1){_0x322b41[_0xbb10('0x39')](_0x30f3ea[_0x37b20e][_0xbb10('0x25')](_0xd9e743['body'],{'transaction':_0x5bfc68}));}return BPromise[_0xbb10('0x44')](_0x322b41);});})[_0xbb10('0xc')](function(_0x145baf){logger['info']('GetContactRecallMe',_0xd9e743);logger['debug'](_0xbb10('0x43'),_0xd9e743,JSON['stringify'](_0x145baf));_0x260e06(_0x145baf);})['catch'](function(_0x1701c5){logger[_0xbb10('0x12')](_0xbb10('0x43'),_0x1701c5[_0xbb10('0x13')],_0xd9e743);_0x1ad2ed(_0x3a9677[_0xbb10('0x12')](0x1f4,_0x1701c5[_0xbb10('0x13')]));});});});};