Built motion from commit c738b9ac.|2.6.25
[motion2.git] / server / api / cmHopper / cmHopper.controller.js
index c43ee6d..ff38d51 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x9957=['Contact','List','Queue','preview','CmHopper,\x20%s,\x20%s,\x20%s','getOpenContacts','getTimezones','timezones','push','utcOffset','moment','lodash','../../components/parsers/qs','../../config/logger','../../config/environment','../../mysqldb','status','json','undefined','limit','count','offset','Content-Range','update','then','sendStatus','error','stack','name','send','index','map','fieldName','key','query','keys','filters','intersection','concat','$and','$or','$gt','$gte','$lte','$ne','$eq','$not','$between','$notBetween','$notIn','$notLike','$iLike','$notILike','$like','$overlap','$contained','attributes','model','length','order','sort','pick','filter','where','merge','options','includeAll','include','CmHopper','findAll','catch','show','params','rawAttributes','fields','find','create','body','describe','destroy','VoiceQueueId','Campaign','CampaignId','dataValues','createdAt','updatedAt','membername','user','UserId','deleted','deletedat','format','YYYY-MM-DD\x20HH:mm:ss','calleridnum','phone','campaigntype','queue','ivr','CmContact','ContactId','lastName','isNil','calleridname','firstName','finally','CmHopperFinal','CmHopperAdditionalPhone','end','getPreview','getVoiceQueues','outbound','dialOrderByScheduledAt','dialPreviewAutoRecallMe','transaction','value','direction','prev','hopperIds','priority','scheduledAt','DESC','ASC','sequelize','literal','COALESCE(CmHopper.UserId,\x200)\x20ASC','isEmpty','COALESCE(CmHopper.UserId,\x200)\x20DESC','findOne','scheduledat','recallme','LOCK','UPDATE','CmCompany','Company','CmList','VoiceQueue','dialActive'];(function(_0x404f13,_0x4fa35f){var _0x1f9dbb=function(_0x492b33){while(--_0x492b33){_0x404f13['push'](_0x404f13['shift']());}};_0x1f9dbb(++_0x4fa35f);}(_0x9957,0x93));var _0x7995=function(_0x3b380d,_0x4bf247){_0x3b380d=_0x3b380d-0x0;var _0x54502b=_0x9957[_0x3b380d];return _0x54502b;};'use strict';var moment=require(_0x7995('0x0'));var _=require(_0x7995('0x1'));var qs=require(_0x7995('0x2'));var logger=require(_0x7995('0x3'))('api');var shared=require(_0x7995('0x4'));var db=require(_0x7995('0x5'))['db'];function respondWithResult(_0x1902b4,_0x462a03){_0x462a03=_0x462a03||0xc8;return function(_0x576d89){if(_0x576d89){return _0x1902b4[_0x7995('0x6')](_0x462a03)[_0x7995('0x7')](_0x576d89);}};}function respondWithFilteredResult(_0x137b6b,_0x219534){return function(_0xbda126){if(_0xbda126){var _0x326741=typeof _0x219534['offset']===_0x7995('0x8')&&typeof _0x219534[_0x7995('0x9')]==='undefined';var _0xa2e5f0=_0xbda126[_0x7995('0xa')];var _0x18c8a3=_0x326741?0x0:_0x219534[_0x7995('0xb')];var _0x3c1d19=_0x326741?_0xbda126[_0x7995('0xa')]:_0x219534[_0x7995('0xb')]+_0x219534['limit'];var _0x245143;if(_0x3c1d19>=_0xa2e5f0){_0x3c1d19=_0xa2e5f0;_0x245143=0xc8;}else{_0x245143=0xce;}_0x137b6b[_0x7995('0x6')](_0x245143);return _0x137b6b['set'](_0x7995('0xc'),_0x18c8a3+'-'+_0x3c1d19+'/'+_0xa2e5f0)[_0x7995('0x7')](_0xbda126);}return null;};}function saveUpdates(_0x19a27e,_0x385f00){return function(_0x281576){if(_0x281576){return _0x281576[_0x7995('0xd')](_0x19a27e)[_0x7995('0xe')](function(_0x4cc004){return _0x4cc004;});}return null;};}function handleEntityNotFound(_0x58f5ad,_0x2b4e94){return function(_0x2233dd){if(!_0x2233dd){_0x58f5ad[_0x7995('0xf')](0x194);}return _0x2233dd;};}function handleError(_0x321ae8,_0x3f1d3e){_0x3f1d3e=_0x3f1d3e||0x1f4;return function(_0x1a5310){logger[_0x7995('0x10')](_0x1a5310[_0x7995('0x11')]);if(_0x1a5310['name']){delete _0x1a5310[_0x7995('0x12')];}_0x321ae8['status'](_0x3f1d3e)[_0x7995('0x13')](_0x1a5310);};}exports[_0x7995('0x14')]=function(_0x43d4b8,_0x291317){var _0x1e1415={},_0x37a7d4={},_0x4faa60={'count':0x0,'rows':[]};var _0x54c9ae=_[_0x7995('0x15')](db['CmHopper']['rawAttributes'],function(_0x3ec178){return{'name':_0x3ec178[_0x7995('0x16')],'type':_0x3ec178['type'][_0x7995('0x17')]};});_0x37a7d4['model']=_['map'](_0x54c9ae,_0x7995('0x12'));_0x37a7d4[_0x7995('0x18')]=_[_0x7995('0x19')](_0x43d4b8[_0x7995('0x18')]);_0x37a7d4[_0x7995('0x1a')]=_[_0x7995('0x1b')](_0x37a7d4['model'],_0x37a7d4[_0x7995('0x18')]);_0x37a7d4[_0x7995('0x1a')]=_[_0x7995('0x1c')](_0x37a7d4[_0x7995('0x1a')],[_0x7995('0x1d'),_0x7995('0x1e'),_0x7995('0x1f'),_0x7995('0x20'),'$lt',_0x7995('0x21'),_0x7995('0x22'),_0x7995('0x23'),_0x7995('0x24'),_0x7995('0x25'),_0x7995('0x26'),'$in',_0x7995('0x27'),'$like',_0x7995('0x28'),_0x7995('0x29'),_0x7995('0x2a'),_0x7995('0x2b'),_0x7995('0x2c'),'$contains',_0x7995('0x2d'),'$any']);_0x1e1415[_0x7995('0x2e')]=_[_0x7995('0x1b')](_0x37a7d4[_0x7995('0x2f')],qs['fields'](_0x43d4b8['query']['fields']));_0x1e1415[_0x7995('0x2e')]=_0x1e1415[_0x7995('0x2e')][_0x7995('0x30')]?_0x1e1415[_0x7995('0x2e')]:_0x37a7d4[_0x7995('0x2f')];if(!_0x43d4b8[_0x7995('0x18')]['hasOwnProperty']('nolimit')){_0x1e1415[_0x7995('0x9')]=qs['limit'](_0x43d4b8[_0x7995('0x18')][_0x7995('0x9')]);_0x1e1415[_0x7995('0xb')]=qs[_0x7995('0xb')](_0x43d4b8[_0x7995('0x18')]['offset']);}_0x1e1415[_0x7995('0x31')]=qs[_0x7995('0x32')](_0x43d4b8['query']['sort']);_0x1e1415['where']=qs[_0x7995('0x1a')](_[_0x7995('0x33')](_0x43d4b8['query'],_0x37a7d4[_0x7995('0x1a')]),_0x54c9ae);if(_0x43d4b8['query'][_0x7995('0x34')]){_0x1e1415[_0x7995('0x35')]=_[_0x7995('0x36')](_0x1e1415['where'],{'$or':_['map'](_0x54c9ae,function(_0x36d057){if(_0x36d057['type']!=='VIRTUAL'){var _0x3e99cd={};_0x3e99cd[_0x36d057[_0x7995('0x12')]]={'$like':'%'+_0x43d4b8['query'][_0x7995('0x34')]+'%'};return _0x3e99cd;}})});}_0x1e1415=_[_0x7995('0x36')]({},_0x1e1415,_0x43d4b8[_0x7995('0x37')]);var _0x18667c={'where':_0x1e1415[_0x7995('0x35')]};return db['CmHopper'][_0x7995('0xa')](_0x18667c)[_0x7995('0xe')](function(_0xf612e6){_0x4faa60[_0x7995('0xa')]=_0xf612e6;if(_0x43d4b8['query'][_0x7995('0x38')]){_0x1e1415[_0x7995('0x39')]=[{'all':!![]}];}return db[_0x7995('0x3a')][_0x7995('0x3b')](_0x1e1415);})[_0x7995('0xe')](function(_0x1035dc){_0x4faa60['rows']=_0x1035dc;return _0x4faa60;})[_0x7995('0xe')](respondWithFilteredResult(_0x291317,_0x1e1415))[_0x7995('0x3c')](handleError(_0x291317,null));};exports[_0x7995('0x3d')]=function(_0x2ea47f,_0x2e04cd){var _0x298fc2={'raw':!![],'where':{'id':_0x2ea47f[_0x7995('0x3e')]['id']}},_0x14d638={};_0x14d638[_0x7995('0x2f')]=_[_0x7995('0x19')](db[_0x7995('0x3a')][_0x7995('0x3f')]);_0x14d638[_0x7995('0x18')]=_['keys'](_0x2ea47f['query']);_0x14d638[_0x7995('0x1a')]=_[_0x7995('0x1b')](_0x14d638['model'],_0x14d638['query']);_0x298fc2[_0x7995('0x2e')]=_['intersection'](_0x14d638['model'],qs[_0x7995('0x40')](_0x2ea47f[_0x7995('0x18')][_0x7995('0x40')]));_0x298fc2['attributes']=_0x298fc2[_0x7995('0x2e')]['length']?_0x298fc2[_0x7995('0x2e')]:_0x14d638['model'];if(_0x2ea47f['query'][_0x7995('0x38')]){_0x298fc2[_0x7995('0x39')]=[{'all':!![]}];}_0x298fc2=_[_0x7995('0x36')]({},_0x298fc2,_0x2ea47f[_0x7995('0x37')]);return db['CmHopper'][_0x7995('0x41')](_0x298fc2)[_0x7995('0xe')](handleEntityNotFound(_0x2e04cd,null))[_0x7995('0xe')](respondWithResult(_0x2e04cd,null))[_0x7995('0x3c')](handleError(_0x2e04cd,null));};exports['create']=function(_0x5f28e7,_0x1c37c6){return db['CmHopper'][_0x7995('0x42')](_0x5f28e7['body'],{})[_0x7995('0xe')](respondWithResult(_0x1c37c6,0xc9))['catch'](handleError(_0x1c37c6,null));};exports[_0x7995('0xd')]=function(_0x1b0373,_0x4d9245){if(_0x1b0373[_0x7995('0x43')]['id']){delete _0x1b0373[_0x7995('0x43')]['id'];}return db[_0x7995('0x3a')][_0x7995('0x41')]({'where':{'id':_0x1b0373['params']['id']}})[_0x7995('0xe')](handleEntityNotFound(_0x4d9245,null))[_0x7995('0xe')](saveUpdates(_0x1b0373[_0x7995('0x43')],null))['then'](respondWithResult(_0x4d9245,null))[_0x7995('0x3c')](handleError(_0x4d9245,null));};exports[_0x7995('0x44')]=function(_0x511567,_0x3d8ae3){return db[_0x7995('0x3a')]['describe']()[_0x7995('0xe')](respondWithResult(_0x3d8ae3,null))[_0x7995('0x3c')](handleError(_0x3d8ae3,null));};exports['destroy']=function(_0x3d1dbb,_0x5843ba){var _0x1d87f9;var _0x187735=_0x3d1dbb[_0x7995('0x3e')]['id'];return db[_0x7995('0x3a')][_0x7995('0x41')]({'where':{'id':_0x3d1dbb[_0x7995('0x3e')]['id']}})[_0x7995('0xe')](handleEntityNotFound(_0x5843ba,null))['then'](function(_0x427dcf){if(_0x427dcf){return _0x427dcf[_0x7995('0x45')]()[_0x7995('0xe')](function(_0x4ffc8a){return _0x4ffc8a;});}})[_0x7995('0xe')](function(_0x1fe77e){_0x1d87f9=_0x1fe77e;if(_0x1fe77e){if(_0x1fe77e[_0x7995('0x46')]||_0x1fe77e['CampaignId']){return db[_0x1fe77e['VoiceQueueId']?'VoiceQueue':_0x7995('0x47')][_0x7995('0x41')]({'where':{'id':_0x1fe77e['VoiceQueueId']?_0x1fe77e[_0x7995('0x46')]:_0x1fe77e[_0x7995('0x48')]},'attributes':['id',_0x7995('0x12')],'raw':!![]});}}})[_0x7995('0xe')](function(_0xc04004){var _0x528c8e={};if(_0xc04004){_[_0x7995('0x36')](_0x528c8e,_['omit'](_0x1d87f9[_0x7995('0x49')],[_0x7995('0x4a'),_0x7995('0x4b'),'id']));_0x528c8e['state']=0x15;_0x528c8e['statedesc']='deleted';_0x528c8e['campaign']=_0xc04004[_0x7995('0x12')];_0x528c8e[_0x7995('0x4c')]=_0x3d1dbb[_0x7995('0x4d')][_0x7995('0x12')];_0x528c8e[_0x7995('0x4e')]=_0x3d1dbb[_0x7995('0x4d')]['id'];_0x528c8e[_0x7995('0x4f')]=!![];_0x528c8e[_0x7995('0x50')]=moment()[_0x7995('0x51')](_0x7995('0x52'));_0x528c8e[_0x7995('0x53')]=_0x1d87f9[_0x7995('0x54')];_0x528c8e[_0x7995('0x55')]=_0x1d87f9[_0x7995('0x46')]?_0x7995('0x56'):_0x7995('0x57');return db[_0x7995('0x58')][_0x7995('0x41')]({'where':{'id':_0x528c8e[_0x7995('0x59')]},'attributes':['firstName',_0x7995('0x5a')]})[_0x7995('0xe')](function(_0x3b8a54){if(!_[_0x7995('0x5b')](_0x5843ba)&&!_['isNil'](_0x3b8a54['firstName'])){_0x528c8e[_0x7995('0x5c')]=_0x3b8a54[_0x7995('0x5d')];if(!_[_0x7995('0x5b')](_0x3b8a54[_0x7995('0x5a')])){_0x528c8e['calleridname']+='\x20'+_0x3b8a54[_0x7995('0x5a')];}}})[_0x7995('0x5e')](function(){return db[_0x7995('0x5f')][_0x7995('0x42')](_0x528c8e);});}})['then'](function(_0x5e2d97){return db[_0x7995('0x60')][_0x7995('0x45')]({'where':{'CmHopperId':_0x187735}});})[_0x7995('0xe')](function(){return _0x5843ba[_0x7995('0x6')](0xcc)[_0x7995('0x61')]();})[_0x7995('0x3c')](handleError(_0x5843ba,null));};exports[_0x7995('0x62')]=function(_0x1e2206,_0x984c23){var _0x50caf5=[];return db[_0x7995('0x58')][_0x7995('0x44')]()[_0x7995('0xe')](function(_0x1ecfdb){_0x50caf5=_['keys'](_0x1ecfdb);return _0x1e2206['user'][_0x7995('0x63')]({'where':{'type':_0x7995('0x64'),'dialActive':!![],'dialMethod':'preview'},'attributes':['id',_0x7995('0x65'),_0x7995('0x66')],'raw':!![]});})[_0x7995('0xe')](function(_0x57727e){if(_0x57727e&&_0x57727e[_0x7995('0x30')]){return db['sequelize'][_0x7995('0x67')](function(_0x564fca){var _0x3e0a46={'active':![],'recallme':![],'scheduledAt':{'$lte':moment()[_0x7995('0x51')](_0x7995('0x52'))},'VoiceQueueId':{'$in':_[_0x7995('0x15')](_0x57727e,'id')},'$or':[{'UserId':null},{'UserId':_0x1e2206[_0x7995('0x4d')]['id']}]};var _0xeb8920={'active':![],'recallme':!![],'VoiceQueueId':{'$in':_(_0x57727e)[_0x7995('0x34')]([_0x7995('0x66'),0x0])[_0x7995('0x15')]('id')[_0x7995('0x68')]()},'$or':[{'UserId':null},{'UserId':_0x1e2206[_0x7995('0x4d')]['id']}]};var _0x234d8d={'$or':[_0x3e0a46,_0xeb8920]};var _0x56eb85=[];if(_0x1e2206[_0x7995('0x43')][_0x7995('0x69')]&&_0x1e2206[_0x7995('0x43')][_0x7995('0x69')]===_0x7995('0x6a')){if(!_['isEmpty'](_0x1e2206['body'][_0x7995('0x6b')])){_0x234d8d['id']={'$in':_0x1e2206[_0x7995('0x43')][_0x7995('0x6b')]};}_0x56eb85=[[_0x7995('0x6c'),'ASC'],[_0x7995('0x6d'),_0x57727e[0x0]['dialOrderByScheduledAt']==='ASC'?_0x7995('0x6e'):_0x7995('0x6f')],db[_0x7995('0x70')][_0x7995('0x71')](_0x7995('0x72')),['id',_0x7995('0x6e')]];}else{if(!_[_0x7995('0x73')](_0x1e2206[_0x7995('0x43')][_0x7995('0x6b')])){_0x234d8d['id']={'$notIn':_0x1e2206[_0x7995('0x43')]['hopperIds']};}_0x56eb85=[[_0x7995('0x6c'),_0x7995('0x6e')],[_0x7995('0x6d'),_0x57727e[0x0]['dialOrderByScheduledAt']],db[_0x7995('0x70')][_0x7995('0x71')](_0x7995('0x74')),['id',_0x7995('0x6f')]];}return db[_0x7995('0x3a')][_0x7995('0x75')]({'attributes':['id',_0x7995('0x76'),_0x7995('0x54'),_0x7995('0x77')],'where':_0x234d8d,'order':_0x56eb85,'transaction':_0x564fca,'lock':_0x564fca[_0x7995('0x78')][_0x7995('0x79')],'include':[{'model':db['CmContact'],'as':'Contact','attributes':_0x50caf5,'include':[{'model':db[_0x7995('0x7a')],'as':_0x7995('0x7b'),'attributes':['id',_0x7995('0x12')]}]},{'model':db[_0x7995('0x7c')],'as':'List','attributes':['id',_0x7995('0x12')]},{'model':db[_0x7995('0x7d')],'as':'Queue','attributes':['id','name',_0x7995('0x7e')]}]})[_0x7995('0xe')](function(_0x555277){if(_0x555277){return _0x555277[_0x7995('0xd')]({'UserId':_0x1e2206['user']['id']},{'transaction':_0x564fca});}});});}})[_0x7995('0xe')](handleEntityNotFound(_0x984c23,null))[_0x7995('0xe')](respondWithResult(_0x984c23,null))['catch'](handleError(_0x984c23,null));};exports['getPreviewRecall']=function(_0x1f01c0,_0x50c1a4,_0x31b9e6){var _0xa41fff=[];var _0x3dd197=_0x1f01c0[_0x7995('0x3e')]['id'];var _0x1a1873=_0x1f01c0[_0x7995('0x4d')]['id'];return db[_0x7995('0x58')][_0x7995('0x44')]()[_0x7995('0xe')](function(_0x117317){_0xa41fff=_[_0x7995('0x19')](_0x117317);return db[_0x7995('0x70')][_0x7995('0x67')](function(_0x1ff436){const _0x36e3a7={'id':_0x3dd197};return db[_0x7995('0x3a')][_0x7995('0x75')]({'attributes':['id',_0x7995('0x76'),_0x7995('0x77')],'where':_0x36e3a7,'transaction':_0x1ff436,'lock':_0x1ff436[_0x7995('0x78')][_0x7995('0x79')],'include':[{'model':db[_0x7995('0x58')],'as':_0x7995('0x7f'),'attributes':_0xa41fff,'include':[{'model':db[_0x7995('0x7a')],'as':_0x7995('0x7b'),'attributes':['id',_0x7995('0x12')]}]},{'model':db[_0x7995('0x7c')],'as':_0x7995('0x80'),'attributes':['id','name']},{'model':db[_0x7995('0x7d')],'as':_0x7995('0x81'),'attributes':['id','name','dialActive']}]})[_0x7995('0xe')](function(_0x3fe8fc){if(_0x3fe8fc){return _0x3fe8fc[_0x7995('0xd')]({'UserId':_0x1a1873},{'transaction':_0x1ff436});}});});})[_0x7995('0xe')](handleEntityNotFound(_0x50c1a4,null))[_0x7995('0xe')](respondWithResult(_0x50c1a4,null))[_0x7995('0x3c')](handleError(_0x50c1a4,null));};exports['getOpenContacts']=function(_0x2f8a2d,_0xb68962){return _0x2f8a2d[_0x7995('0x4d')][_0x7995('0x63')]({'where':{'type':_0x7995('0x64'),'dialActive':!![],'dialMethod':_0x7995('0x82')},'attributes':['id'],'raw':!![]})[_0x7995('0xe')](function(_0xc93dcb){if(_0xc93dcb&&_0xc93dcb['length']){return db[_0x7995('0x3a')][_0x7995('0xa')]({'where':{'active':![],'recallme':![],'scheduledAt':{'$lte':moment()['format']('YYYY-MM-DD\x20HH:mm:ss')},'VoiceQueueId':{'$in':_[_0x7995('0x15')](_0xc93dcb,'id')},'$or':[{'UserId':null},{'UserId':_0x2f8a2d[_0x7995('0x4d')]['id']}]}});}return 0x0;})[_0x7995('0xe')](function(_0x3db7a9){if(!_[_0x7995('0x5b')](_0x3db7a9)&&_['isNumber'](_0x3db7a9)){return _0xb68962[_0x7995('0x6')](0xc8)[_0x7995('0x7')]({'contacts':_0x3db7a9});}else{logger['error'](_0x7995('0x83'),_0x7995('0x84'),0x194,'entity\x20not\x20found');_0xb68962[_0x7995('0xf')](0x194);}})['catch'](handleError(_0xb68962,null));};exports[_0x7995('0x85')]=function(_0x2322bf,_0x3ab421){var _0x428a1b=shared[_0x7995('0x86')];var _0x5d16da=[];_[_0x7995('0x15')](_0x428a1b,function(_0x345080){_0x5d16da[_0x7995('0x87')]({'id':_0x345080['name'],'name':_0x345080[_0x7995('0x12')],'utcOffset':_0x345080[_0x7995('0x88')]});});return _0x3ab421[_0x7995('0x6')](0xc8)[_0x7995('0x7')]({'tz':_0x5d16da});};exports['getTimezone']=function(_0x3356fd,_0xf59a39){var _0x3a5f5e=shared['timezones'];var _0x5358d4={};if(!_[_0x7995('0x5b')](_0x3a5f5e[_0x3356fd[_0x7995('0x43')]['id']]))_0x5358d4=_0x3a5f5e[_0x3356fd['body']['id']];return _0xf59a39['status'](0xc8)[_0x7995('0x7')](_0x5358d4);};
\ No newline at end of file
+var _0x7bae=['format','YYYY-MM-DD\x20HH:mm:ss','phone','campaigntype','queue','ivr','ContactId','firstName','lastName','isNil','calleridname','finally','CmHopperFinal','CmHopperAdditionalPhone','end','getPreview','CmContact','getVoiceQueues','outbound','dialOrderByScheduledAt','dialPreviewAutoRecallMe','value','direction','prev','isEmpty','hopperIds','ASC','scheduledAt','sequelize','literal','COALESCE(CmHopper.UserId,\x200)\x20ASC','priority','findOne','scheduledat','recallme','Contact','CmCompany','Company','CmList','List','VoiceQueue','Queue','dialActive','getPreviewRecall','LOCK','UPDATE','preview','isNumber','CmHopper,\x20%s,\x20%s,\x20%s','getOpenContacts','entity\x20not\x20found','getTimezones','timezones','push','utcOffset','../../components/parsers/qs','../../config/logger','../../config/environment','status','json','offset','undefined','limit','count','set','update','then','sendStatus','error','index','map','CmHopper','fieldName','type','key','name','keys','query','filters','intersection','model','concat','$and','$lte','$between','$notBetween','$in','$notIn','$like','$notLike','$iLike','$notILike','$overlap','$contained','$any','attributes','fields','hasOwnProperty','order','sort','pick','filter','merge','where','VIRTUAL','options','include','findAll','rows','catch','show','params','rawAttributes','length','includeAll','find','create','body','describe','destroy','VoiceQueueId','CampaignId','omit','dataValues','updatedAt','state','statedesc','campaign','user','deletedat'];(function(_0x41c381,_0x1176bd){var _0x427981=function(_0x508843){while(--_0x508843){_0x41c381['push'](_0x41c381['shift']());}};_0x427981(++_0x1176bd);}(_0x7bae,0x13b));var _0xe7ba=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x7bae[_0x3dd15e];return _0x231fd0;};'use strict';var moment=require('moment');var _=require('lodash');var qs=require(_0xe7ba('0x0'));var logger=require(_0xe7ba('0x1'))('api');var shared=require(_0xe7ba('0x2'));var db=require('../../mysqldb')['db'];function respondWithResult(_0x120efa,_0x10908b){_0x10908b=_0x10908b||0xc8;return function(_0x166acb){if(_0x166acb){return _0x120efa[_0xe7ba('0x3')](_0x10908b)[_0xe7ba('0x4')](_0x166acb);}};}function respondWithFilteredResult(_0xfd3a22,_0x2d31df){return function(_0x3c5e59){if(_0x3c5e59){var _0x10b307=typeof _0x2d31df[_0xe7ba('0x5')]===_0xe7ba('0x6')&&typeof _0x2d31df[_0xe7ba('0x7')]===_0xe7ba('0x6');var _0x1b2693=_0x3c5e59['count'];var _0x3df8bf=_0x10b307?0x0:_0x2d31df[_0xe7ba('0x5')];var _0x375ebb=_0x10b307?_0x3c5e59[_0xe7ba('0x8')]:_0x2d31df[_0xe7ba('0x5')]+_0x2d31df[_0xe7ba('0x7')];var _0x99a86f;if(_0x375ebb>=_0x1b2693){_0x375ebb=_0x1b2693;_0x99a86f=0xc8;}else{_0x99a86f=0xce;}_0xfd3a22[_0xe7ba('0x3')](_0x99a86f);return _0xfd3a22[_0xe7ba('0x9')]('Content-Range',_0x3df8bf+'-'+_0x375ebb+'/'+_0x1b2693)[_0xe7ba('0x4')](_0x3c5e59);}return null;};}function saveUpdates(_0x588c8b,_0x602b1){return function(_0x45229c){if(_0x45229c){return _0x45229c[_0xe7ba('0xa')](_0x588c8b)[_0xe7ba('0xb')](function(_0x15d018){return _0x15d018;});}return null;};}function handleEntityNotFound(_0x41369f,_0x561dbb){return function(_0x561c48){if(!_0x561c48){_0x41369f[_0xe7ba('0xc')](0x194);}return _0x561c48;};}function handleError(_0x7ba72a,_0x359f6f){_0x359f6f=_0x359f6f||0x1f4;return function(_0x5d1d03){logger[_0xe7ba('0xd')](_0x5d1d03['stack']);if(_0x5d1d03['name']){delete _0x5d1d03['name'];}_0x7ba72a[_0xe7ba('0x3')](_0x359f6f)['send'](_0x5d1d03);};}exports[_0xe7ba('0xe')]=function(_0x4888d9,_0x4e3021){var _0x5a82b5={},_0x3f326a={},_0x30086c={'count':0x0,'rows':[]};var _0x39ca38=_[_0xe7ba('0xf')](db[_0xe7ba('0x10')]['rawAttributes'],function(_0x149c62){return{'name':_0x149c62[_0xe7ba('0x11')],'type':_0x149c62[_0xe7ba('0x12')][_0xe7ba('0x13')]};});_0x3f326a['model']=_[_0xe7ba('0xf')](_0x39ca38,_0xe7ba('0x14'));_0x3f326a['query']=_[_0xe7ba('0x15')](_0x4888d9[_0xe7ba('0x16')]);_0x3f326a[_0xe7ba('0x17')]=_[_0xe7ba('0x18')](_0x3f326a[_0xe7ba('0x19')],_0x3f326a[_0xe7ba('0x16')]);_0x3f326a[_0xe7ba('0x17')]=_[_0xe7ba('0x1a')](_0x3f326a[_0xe7ba('0x17')],[_0xe7ba('0x1b'),'$or','$gt','$gte','$lt',_0xe7ba('0x1c'),'$ne','$eq','$not',_0xe7ba('0x1d'),_0xe7ba('0x1e'),_0xe7ba('0x1f'),_0xe7ba('0x20'),_0xe7ba('0x21'),_0xe7ba('0x22'),_0xe7ba('0x23'),_0xe7ba('0x24'),'$like',_0xe7ba('0x25'),'$contains',_0xe7ba('0x26'),_0xe7ba('0x27')]);_0x5a82b5[_0xe7ba('0x28')]=_['intersection'](_0x3f326a['model'],qs[_0xe7ba('0x29')](_0x4888d9[_0xe7ba('0x16')][_0xe7ba('0x29')]));_0x5a82b5[_0xe7ba('0x28')]=_0x5a82b5[_0xe7ba('0x28')]['length']?_0x5a82b5[_0xe7ba('0x28')]:_0x3f326a[_0xe7ba('0x19')];if(!_0x4888d9['query'][_0xe7ba('0x2a')]('nolimit')){_0x5a82b5['limit']=qs[_0xe7ba('0x7')](_0x4888d9[_0xe7ba('0x16')][_0xe7ba('0x7')]);_0x5a82b5['offset']=qs[_0xe7ba('0x5')](_0x4888d9['query'][_0xe7ba('0x5')]);}_0x5a82b5[_0xe7ba('0x2b')]=qs[_0xe7ba('0x2c')](_0x4888d9[_0xe7ba('0x16')][_0xe7ba('0x2c')]);_0x5a82b5['where']=qs[_0xe7ba('0x17')](_[_0xe7ba('0x2d')](_0x4888d9['query'],_0x3f326a[_0xe7ba('0x17')]),_0x39ca38);if(_0x4888d9[_0xe7ba('0x16')][_0xe7ba('0x2e')]){_0x5a82b5['where']=_[_0xe7ba('0x2f')](_0x5a82b5[_0xe7ba('0x30')],{'$or':_['map'](_0x39ca38,function(_0x3e850e){if(_0x3e850e[_0xe7ba('0x12')]!==_0xe7ba('0x31')){var _0x4c1325={};_0x4c1325[_0x3e850e[_0xe7ba('0x14')]]={'$like':'%'+_0x4888d9[_0xe7ba('0x16')]['filter']+'%'};return _0x4c1325;}})});}_0x5a82b5=_[_0xe7ba('0x2f')]({},_0x5a82b5,_0x4888d9[_0xe7ba('0x32')]);var _0x8a5776={'where':_0x5a82b5['where']};return db['CmHopper'][_0xe7ba('0x8')](_0x8a5776)[_0xe7ba('0xb')](function(_0x58d2a){_0x30086c[_0xe7ba('0x8')]=_0x58d2a;if(_0x4888d9[_0xe7ba('0x16')]['includeAll']){_0x5a82b5[_0xe7ba('0x33')]=[{'all':!![]}];}return db[_0xe7ba('0x10')][_0xe7ba('0x34')](_0x5a82b5);})[_0xe7ba('0xb')](function(_0x5e9619){_0x30086c[_0xe7ba('0x35')]=_0x5e9619;return _0x30086c;})[_0xe7ba('0xb')](respondWithFilteredResult(_0x4e3021,_0x5a82b5))[_0xe7ba('0x36')](handleError(_0x4e3021,null));};exports[_0xe7ba('0x37')]=function(_0x35a5f3,_0x3793c6){var _0x124cc4={'raw':!![],'where':{'id':_0x35a5f3[_0xe7ba('0x38')]['id']}},_0x4e22f3={};_0x4e22f3[_0xe7ba('0x19')]=_[_0xe7ba('0x15')](db[_0xe7ba('0x10')][_0xe7ba('0x39')]);_0x4e22f3[_0xe7ba('0x16')]=_[_0xe7ba('0x15')](_0x35a5f3[_0xe7ba('0x16')]);_0x4e22f3[_0xe7ba('0x17')]=_['intersection'](_0x4e22f3[_0xe7ba('0x19')],_0x4e22f3[_0xe7ba('0x16')]);_0x124cc4['attributes']=_['intersection'](_0x4e22f3[_0xe7ba('0x19')],qs[_0xe7ba('0x29')](_0x35a5f3[_0xe7ba('0x16')]['fields']));_0x124cc4[_0xe7ba('0x28')]=_0x124cc4[_0xe7ba('0x28')][_0xe7ba('0x3a')]?_0x124cc4[_0xe7ba('0x28')]:_0x4e22f3[_0xe7ba('0x19')];if(_0x35a5f3['query'][_0xe7ba('0x3b')]){_0x124cc4['include']=[{'all':!![]}];}_0x124cc4=_[_0xe7ba('0x2f')]({},_0x124cc4,_0x35a5f3[_0xe7ba('0x32')]);return db[_0xe7ba('0x10')][_0xe7ba('0x3c')](_0x124cc4)[_0xe7ba('0xb')](handleEntityNotFound(_0x3793c6,null))[_0xe7ba('0xb')](respondWithResult(_0x3793c6,null))[_0xe7ba('0x36')](handleError(_0x3793c6,null));};exports[_0xe7ba('0x3d')]=function(_0x51e6f1,_0x42f4c3){return db[_0xe7ba('0x10')][_0xe7ba('0x3d')](_0x51e6f1[_0xe7ba('0x3e')],{})[_0xe7ba('0xb')](respondWithResult(_0x42f4c3,0xc9))[_0xe7ba('0x36')](handleError(_0x42f4c3,null));};exports[_0xe7ba('0xa')]=function(_0x2c54ac,_0x45f49a){if(_0x2c54ac[_0xe7ba('0x3e')]['id']){delete _0x2c54ac['body']['id'];}return db[_0xe7ba('0x10')]['find']({'where':{'id':_0x2c54ac[_0xe7ba('0x38')]['id']}})[_0xe7ba('0xb')](handleEntityNotFound(_0x45f49a,null))[_0xe7ba('0xb')](saveUpdates(_0x2c54ac[_0xe7ba('0x3e')],null))[_0xe7ba('0xb')](respondWithResult(_0x45f49a,null))[_0xe7ba('0x36')](handleError(_0x45f49a,null));};exports['describe']=function(_0x271592,_0x1cc668){return db[_0xe7ba('0x10')][_0xe7ba('0x3f')]()[_0xe7ba('0xb')](respondWithResult(_0x1cc668,null))[_0xe7ba('0x36')](handleError(_0x1cc668,null));};exports[_0xe7ba('0x40')]=function(_0x266ace,_0x272cb9){var _0x1189bd;var _0xbe2a32=_0x266ace['params']['id'];return db[_0xe7ba('0x10')][_0xe7ba('0x3c')]({'where':{'id':_0x266ace[_0xe7ba('0x38')]['id']}})[_0xe7ba('0xb')](handleEntityNotFound(_0x272cb9,null))[_0xe7ba('0xb')](function(_0x1fd246){if(_0x1fd246){return _0x1fd246['destroy']()[_0xe7ba('0xb')](function(_0x3ee828){return _0x3ee828;});}})['then'](function(_0x330ebd){_0x1189bd=_0x330ebd;if(_0x330ebd){if(_0x330ebd[_0xe7ba('0x41')]||_0x330ebd[_0xe7ba('0x42')]){return db[_0x330ebd[_0xe7ba('0x41')]?'VoiceQueue':'Campaign'][_0xe7ba('0x3c')]({'where':{'id':_0x330ebd[_0xe7ba('0x41')]?_0x330ebd[_0xe7ba('0x41')]:_0x330ebd['CampaignId']},'attributes':['id',_0xe7ba('0x14')],'raw':!![]});}}})[_0xe7ba('0xb')](function(_0x377877){var _0x45bcbd={};if(_0x377877){_[_0xe7ba('0x2f')](_0x45bcbd,_[_0xe7ba('0x43')](_0x1189bd[_0xe7ba('0x44')],['createdAt',_0xe7ba('0x45'),'id']));_0x45bcbd[_0xe7ba('0x46')]=0x15;_0x45bcbd[_0xe7ba('0x47')]='deleted';_0x45bcbd[_0xe7ba('0x48')]=_0x377877[_0xe7ba('0x14')];_0x45bcbd['membername']=_0x266ace[_0xe7ba('0x49')][_0xe7ba('0x14')];_0x45bcbd['UserId']=_0x266ace[_0xe7ba('0x49')]['id'];_0x45bcbd['deleted']=!![];_0x45bcbd[_0xe7ba('0x4a')]=moment()[_0xe7ba('0x4b')](_0xe7ba('0x4c'));_0x45bcbd['calleridnum']=_0x1189bd[_0xe7ba('0x4d')];_0x45bcbd[_0xe7ba('0x4e')]=_0x1189bd[_0xe7ba('0x41')]?_0xe7ba('0x4f'):_0xe7ba('0x50');return db['CmContact'][_0xe7ba('0x3c')]({'where':{'id':_0x45bcbd[_0xe7ba('0x51')]},'attributes':[_0xe7ba('0x52'),_0xe7ba('0x53')]})[_0xe7ba('0xb')](function(_0x50aecc){if(!_[_0xe7ba('0x54')](_0x272cb9)&&!_[_0xe7ba('0x54')](_0x50aecc[_0xe7ba('0x52')])){_0x45bcbd[_0xe7ba('0x55')]=_0x50aecc['firstName'];if(!_[_0xe7ba('0x54')](_0x50aecc[_0xe7ba('0x53')])){_0x45bcbd[_0xe7ba('0x55')]+='\x20'+_0x50aecc[_0xe7ba('0x53')];}}})[_0xe7ba('0x56')](function(){return db[_0xe7ba('0x57')]['create'](_0x45bcbd);});}})[_0xe7ba('0xb')](function(_0x103762){return db[_0xe7ba('0x58')]['destroy']({'where':{'CmHopperId':_0xbe2a32}});})[_0xe7ba('0xb')](function(){return _0x272cb9[_0xe7ba('0x3')](0xcc)[_0xe7ba('0x59')]();})[_0xe7ba('0x36')](handleError(_0x272cb9,null));};exports[_0xe7ba('0x5a')]=function(_0x162d7f,_0x3a7bfb){var _0x3351d5=[];return db[_0xe7ba('0x5b')][_0xe7ba('0x3f')]()[_0xe7ba('0xb')](function(_0x27422d){_0x3351d5=_['keys'](_0x27422d);return _0x162d7f[_0xe7ba('0x49')][_0xe7ba('0x5c')]({'where':{'type':_0xe7ba('0x5d'),'dialActive':!![],'dialMethod':'preview'},'attributes':['id',_0xe7ba('0x5e'),'dialPreviewAutoRecallMe'],'raw':!![]});})[_0xe7ba('0xb')](function(_0x194dff){if(_0x194dff&&_0x194dff[_0xe7ba('0x3a')]){return db['sequelize']['transaction'](function(_0x46d06e){var _0x2812af={'active':![],'recallme':![],'scheduledAt':{'$lte':moment()[_0xe7ba('0x4b')]('YYYY-MM-DD\x20HH:mm:ss')},'VoiceQueueId':{'$in':_[_0xe7ba('0xf')](_0x194dff,'id')},'$or':[{'UserId':null},{'UserId':_0x162d7f[_0xe7ba('0x49')]['id']}]};var _0x3fe82a={'active':![],'recallme':!![],'VoiceQueueId':{'$in':_(_0x194dff)[_0xe7ba('0x2e')]([_0xe7ba('0x5f'),0x0])['map']('id')[_0xe7ba('0x60')]()},'$or':[{'UserId':null},{'UserId':_0x162d7f[_0xe7ba('0x49')]['id']}]};var _0x70ce9c={'$or':[_0x2812af,_0x3fe82a]};var _0x50cc8b=[];if(_0x162d7f[_0xe7ba('0x3e')][_0xe7ba('0x61')]&&_0x162d7f[_0xe7ba('0x3e')][_0xe7ba('0x61')]===_0xe7ba('0x62')){if(!_[_0xe7ba('0x63')](_0x162d7f[_0xe7ba('0x3e')][_0xe7ba('0x64')])){_0x70ce9c['id']={'$in':_0x162d7f[_0xe7ba('0x3e')][_0xe7ba('0x64')]};}_0x50cc8b=[['priority',_0xe7ba('0x65')],[_0xe7ba('0x66'),_0x194dff[0x0][_0xe7ba('0x5e')]===_0xe7ba('0x65')?'DESC':'ASC'],db[_0xe7ba('0x67')][_0xe7ba('0x68')](_0xe7ba('0x69')),['id','DESC']];}else{if(!_['isEmpty'](_0x162d7f['body'][_0xe7ba('0x64')])){_0x70ce9c['id']={'$notIn':_0x162d7f[_0xe7ba('0x3e')]['hopperIds']};}_0x50cc8b=[[_0xe7ba('0x6a'),'DESC'],[_0xe7ba('0x66'),_0x194dff[0x0]['dialOrderByScheduledAt']],db[_0xe7ba('0x67')]['literal']('COALESCE(CmHopper.UserId,\x200)\x20DESC'),['id',_0xe7ba('0x65')]];}return db[_0xe7ba('0x10')][_0xe7ba('0x6b')]({'attributes':['id',_0xe7ba('0x6c'),_0xe7ba('0x4d'),_0xe7ba('0x6d')],'where':_0x70ce9c,'order':_0x50cc8b,'transaction':_0x46d06e,'lock':_0x46d06e['LOCK']['UPDATE'],'include':[{'model':db[_0xe7ba('0x5b')],'as':_0xe7ba('0x6e'),'attributes':_0x3351d5,'include':[{'model':db[_0xe7ba('0x6f')],'as':_0xe7ba('0x70'),'attributes':['id',_0xe7ba('0x14')]}]},{'model':db[_0xe7ba('0x71')],'as':_0xe7ba('0x72'),'attributes':['id',_0xe7ba('0x14')]},{'model':db[_0xe7ba('0x73')],'as':_0xe7ba('0x74'),'attributes':['id',_0xe7ba('0x14'),_0xe7ba('0x75')]}]})[_0xe7ba('0xb')](function(_0x2e31df){if(_0x2e31df){return _0x2e31df[_0xe7ba('0xa')]({'UserId':_0x162d7f['user']['id']},{'transaction':_0x46d06e});}});});}})[_0xe7ba('0xb')](handleEntityNotFound(_0x3a7bfb,null))[_0xe7ba('0xb')](respondWithResult(_0x3a7bfb,null))[_0xe7ba('0x36')](handleError(_0x3a7bfb,null));};exports[_0xe7ba('0x76')]=function(_0x1f149c,_0x3ff0e6,_0x2471c8){var _0x11ca03=[];var _0x2044db=_0x1f149c[_0xe7ba('0x38')]['id'];var _0x418831=_0x1f149c[_0xe7ba('0x49')]['id'];return db['CmContact'][_0xe7ba('0x3f')]()['then'](function(_0x27a939){_0x11ca03=_[_0xe7ba('0x15')](_0x27a939);return db[_0xe7ba('0x67')]['transaction'](function(_0x156b66){const _0x40eb35={'id':_0x2044db};return db[_0xe7ba('0x10')][_0xe7ba('0x6b')]({'attributes':['id','scheduledat',_0xe7ba('0x6d')],'where':_0x40eb35,'transaction':_0x156b66,'lock':_0x156b66[_0xe7ba('0x77')][_0xe7ba('0x78')],'include':[{'model':db[_0xe7ba('0x5b')],'as':'Contact','attributes':_0x11ca03,'include':[{'model':db[_0xe7ba('0x6f')],'as':_0xe7ba('0x70'),'attributes':['id',_0xe7ba('0x14')]}]},{'model':db[_0xe7ba('0x71')],'as':_0xe7ba('0x72'),'attributes':['id','name']},{'model':db['VoiceQueue'],'as':'Queue','attributes':['id',_0xe7ba('0x14'),_0xe7ba('0x75')]}]})[_0xe7ba('0xb')](function(_0x27e7a5){if(_0x27e7a5){return _0x27e7a5[_0xe7ba('0xa')]({'UserId':_0x418831},{'transaction':_0x156b66});}});});})[_0xe7ba('0xb')](handleEntityNotFound(_0x3ff0e6,null))['then'](respondWithResult(_0x3ff0e6,null))[_0xe7ba('0x36')](handleError(_0x3ff0e6,null));};exports['getOpenContacts']=function(_0x439c96,_0x2e3e28){return _0x439c96[_0xe7ba('0x49')][_0xe7ba('0x5c')]({'where':{'type':_0xe7ba('0x5d'),'dialActive':!![],'dialMethod':_0xe7ba('0x79')},'attributes':['id'],'raw':!![]})['then'](function(_0x44563b){if(_0x44563b&&_0x44563b[_0xe7ba('0x3a')]){return db[_0xe7ba('0x10')][_0xe7ba('0x8')]({'where':{'active':![],'recallme':![],'scheduledAt':{'$lte':moment()[_0xe7ba('0x4b')]('YYYY-MM-DD\x20HH:mm:ss')},'VoiceQueueId':{'$in':_[_0xe7ba('0xf')](_0x44563b,'id')},'$or':[{'UserId':null},{'UserId':_0x439c96['user']['id']}]}});}return 0x0;})[_0xe7ba('0xb')](function(_0x157686){if(!_[_0xe7ba('0x54')](_0x157686)&&_[_0xe7ba('0x7a')](_0x157686)){return _0x2e3e28[_0xe7ba('0x3')](0xc8)[_0xe7ba('0x4')]({'contacts':_0x157686});}else{logger[_0xe7ba('0xd')](_0xe7ba('0x7b'),_0xe7ba('0x7c'),0x194,_0xe7ba('0x7d'));_0x2e3e28[_0xe7ba('0xc')](0x194);}})[_0xe7ba('0x36')](handleError(_0x2e3e28,null));};exports[_0xe7ba('0x7e')]=function(_0x167996,_0x3129e5){var _0x27eb0e=shared[_0xe7ba('0x7f')];var _0x158615=[];_[_0xe7ba('0xf')](_0x27eb0e,function(_0x1b39b7){_0x158615[_0xe7ba('0x80')]({'id':_0x1b39b7[_0xe7ba('0x14')],'name':_0x1b39b7[_0xe7ba('0x14')],'utcOffset':_0x1b39b7[_0xe7ba('0x81')]});});return _0x3129e5[_0xe7ba('0x3')](0xc8)['json']({'tz':_0x158615});};exports['getTimezone']=function(_0x5889b9,_0xaccf6e){var _0x2ecfac=shared['timezones'];var _0x5ad36f={};if(!_[_0xe7ba('0x54')](_0x2ecfac[_0x5889b9[_0xe7ba('0x3e')]['id']]))_0x5ad36f=_0x2ecfac[_0x5889b9['body']['id']];return _0xaccf6e[_0xe7ba('0x3')](0xc8)['json'](_0x5ad36f);};
\ No newline at end of file