Built motion from commit 953226e6.|2.6.32
[motion2.git] / server / api / cmHopper / cmHopper.controller.js
index 8e696f7..5033cc2 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x50a6=['CmHopperFinal','getPreview','CmContact','getVoiceQueues','outbound','preview','dialPreviewAutoRecallMe','sequelize','transaction','value','direction','prev','isEmpty','hopperIds','ASC','scheduledAt','dialOrderByScheduledAt','DESC','literal','priority','COALESCE(CmHopper.UserId,\x200)\x20DESC','findOne','LOCK','UPDATE','Contact','CmCompany','Company','CmList','Queue','dialActive','scheduledat','isNumber','CmHopper,\x20%s,\x20%s,\x20%s','getOpenContacts','entity\x20not\x20found','getTimezones','timezones','moment','lodash','api','../../mysqldb','status','offset','limit','count','set','json','update','sendStatus','stack','name','rawAttributes','type','key','map','query','keys','intersection','filters','concat','$and','$or','$gt','$gte','$lt','$lte','$ne','$eq','$not','$between','$notBetween','$in','$notIn','$like','$iLike','$notILike','$contains','$contained','$any','attributes','model','fields','length','nolimit','order','where','pick','filter','merge','options','CmHopper','then','includeAll','include','findAll','catch','show','params','find','create','body','describe','destroy','VoiceQueueId','CampaignId','VoiceQueue','Campaign','omit','dataValues','createdAt','statedesc','deleted','membername','user','UserId','deletedat','format','YYYY-MM-DD\x20HH:mm:ss','calleridnum','phone','campaigntype','queue','ContactId','isNil','calleridname','lastName','finally'];(function(_0xfb969f,_0x374e6a){var _0x41b841=function(_0x4e15ea){while(--_0x4e15ea){_0xfb969f['push'](_0xfb969f['shift']());}};_0x41b841(++_0x374e6a);}(_0x50a6,0xa4));var _0x650a=function(_0xecc551,_0x471cac){_0xecc551=_0xecc551-0x0;var _0x344658=_0x50a6[_0xecc551];return _0x344658;};'use strict';var moment=require(_0x650a('0x0'));var _=require(_0x650a('0x1'));var qs=require('../../components/parsers/qs');var logger=require('../../config/logger')(_0x650a('0x2'));var shared=require('../../config/environment');var db=require(_0x650a('0x3'))['db'];function respondWithResult(_0x15dd02,_0x2c71ba){_0x2c71ba=_0x2c71ba||0xc8;return function(_0x4a0147){if(_0x4a0147){return _0x15dd02[_0x650a('0x4')](_0x2c71ba)['json'](_0x4a0147);}};}function respondWithFilteredResult(_0x4eabde,_0x2d486d){return function(_0x2d1bb4){if(_0x2d1bb4){var _0x2c22b9=typeof _0x2d486d[_0x650a('0x5')]==='undefined'&&typeof _0x2d486d[_0x650a('0x6')]==='undefined';var _0x3b50e7=_0x2d1bb4[_0x650a('0x7')];var _0x495fca=_0x2c22b9?0x0:_0x2d486d[_0x650a('0x5')];var _0x3bbdca=_0x2c22b9?_0x2d1bb4['count']:_0x2d486d[_0x650a('0x5')]+_0x2d486d['limit'];var _0x142cdb;if(_0x3bbdca>=_0x3b50e7){_0x3bbdca=_0x3b50e7;_0x142cdb=0xc8;}else{_0x142cdb=0xce;}_0x4eabde['status'](_0x142cdb);return _0x4eabde[_0x650a('0x8')]('Content-Range',_0x495fca+'-'+_0x3bbdca+'/'+_0x3b50e7)[_0x650a('0x9')](_0x2d1bb4);}return null;};}function saveUpdates(_0x48077a,_0x33e73d){return function(_0x163e5f){if(_0x163e5f){return _0x163e5f[_0x650a('0xa')](_0x48077a)['then'](function(_0x10fb8f){return _0x10fb8f;});}return null;};}function handleEntityNotFound(_0x3919a7,_0x2f727d){return function(_0x15f2fd){if(!_0x15f2fd){_0x3919a7[_0x650a('0xb')](0x194);}return _0x15f2fd;};}function handleError(_0x24f11f,_0x5b7c74){_0x5b7c74=_0x5b7c74||0x1f4;return function(_0x2460a3){logger['error'](_0x2460a3[_0x650a('0xc')]);if(_0x2460a3[_0x650a('0xd')]){delete _0x2460a3[_0x650a('0xd')];}_0x24f11f['status'](_0x5b7c74)['send'](_0x2460a3);};}exports['index']=function(_0x52e5bb,_0x2ad2d7){var _0x359314={},_0x41d2fa={},_0xd0f717={'count':0x0,'rows':[]};var _0x2a0f0c=_['map'](db['CmHopper'][_0x650a('0xe')],function(_0x1c65f6){return{'name':_0x1c65f6['fieldName'],'type':_0x1c65f6[_0x650a('0xf')][_0x650a('0x10')]};});_0x41d2fa['model']=_[_0x650a('0x11')](_0x2a0f0c,_0x650a('0xd'));_0x41d2fa[_0x650a('0x12')]=_[_0x650a('0x13')](_0x52e5bb[_0x650a('0x12')]);_0x41d2fa['filters']=_[_0x650a('0x14')](_0x41d2fa['model'],_0x41d2fa[_0x650a('0x12')]);_0x41d2fa[_0x650a('0x15')]=_[_0x650a('0x16')](_0x41d2fa[_0x650a('0x15')],[_0x650a('0x17'),_0x650a('0x18'),_0x650a('0x19'),_0x650a('0x1a'),_0x650a('0x1b'),_0x650a('0x1c'),_0x650a('0x1d'),_0x650a('0x1e'),_0x650a('0x1f'),_0x650a('0x20'),_0x650a('0x21'),_0x650a('0x22'),_0x650a('0x23'),_0x650a('0x24'),'$notLike',_0x650a('0x25'),_0x650a('0x26'),_0x650a('0x24'),'$overlap',_0x650a('0x27'),_0x650a('0x28'),_0x650a('0x29')]);_0x359314[_0x650a('0x2a')]=_[_0x650a('0x14')](_0x41d2fa[_0x650a('0x2b')],qs['fields'](_0x52e5bb[_0x650a('0x12')][_0x650a('0x2c')]));_0x359314[_0x650a('0x2a')]=_0x359314[_0x650a('0x2a')][_0x650a('0x2d')]?_0x359314[_0x650a('0x2a')]:_0x41d2fa[_0x650a('0x2b')];if(!_0x52e5bb[_0x650a('0x12')]['hasOwnProperty'](_0x650a('0x2e'))){_0x359314[_0x650a('0x6')]=qs[_0x650a('0x6')](_0x52e5bb['query'][_0x650a('0x6')]);_0x359314[_0x650a('0x5')]=qs['offset'](_0x52e5bb[_0x650a('0x12')][_0x650a('0x5')]);}_0x359314[_0x650a('0x2f')]=qs['sort'](_0x52e5bb['query']['sort']);_0x359314[_0x650a('0x30')]=qs[_0x650a('0x15')](_[_0x650a('0x31')](_0x52e5bb[_0x650a('0x12')],_0x41d2fa['filters']),_0x2a0f0c);if(_0x52e5bb[_0x650a('0x12')][_0x650a('0x32')]){_0x359314['where']=_[_0x650a('0x33')](_0x359314[_0x650a('0x30')],{'$or':_[_0x650a('0x11')](_0x2a0f0c,function(_0xd2256b){if(_0xd2256b[_0x650a('0xf')]!=='VIRTUAL'){var _0x14260e={};_0x14260e[_0xd2256b['name']]={'$like':'%'+_0x52e5bb[_0x650a('0x12')][_0x650a('0x32')]+'%'};return _0x14260e;}})});}_0x359314=_['merge']({},_0x359314,_0x52e5bb[_0x650a('0x34')]);var _0xa0e8ec={'where':_0x359314['where']};return db[_0x650a('0x35')][_0x650a('0x7')](_0xa0e8ec)[_0x650a('0x36')](function(_0x53179e){_0xd0f717[_0x650a('0x7')]=_0x53179e;if(_0x52e5bb[_0x650a('0x12')][_0x650a('0x37')]){_0x359314[_0x650a('0x38')]=[{'all':!![]}];}return db['CmHopper'][_0x650a('0x39')](_0x359314);})[_0x650a('0x36')](function(_0x2ace75){_0xd0f717['rows']=_0x2ace75;return _0xd0f717;})['then'](respondWithFilteredResult(_0x2ad2d7,_0x359314))[_0x650a('0x3a')](handleError(_0x2ad2d7,null));};exports[_0x650a('0x3b')]=function(_0x5b33c9,_0x1acbe5){var _0x48bdd4={'raw':!![],'where':{'id':_0x5b33c9[_0x650a('0x3c')]['id']}},_0x3ebe8b={};_0x3ebe8b[_0x650a('0x2b')]=_[_0x650a('0x13')](db[_0x650a('0x35')]['rawAttributes']);_0x3ebe8b[_0x650a('0x12')]=_['keys'](_0x5b33c9[_0x650a('0x12')]);_0x3ebe8b[_0x650a('0x15')]=_[_0x650a('0x14')](_0x3ebe8b[_0x650a('0x2b')],_0x3ebe8b[_0x650a('0x12')]);_0x48bdd4[_0x650a('0x2a')]=_[_0x650a('0x14')](_0x3ebe8b['model'],qs['fields'](_0x5b33c9[_0x650a('0x12')]['fields']));_0x48bdd4['attributes']=_0x48bdd4[_0x650a('0x2a')]['length']?_0x48bdd4[_0x650a('0x2a')]:_0x3ebe8b['model'];if(_0x5b33c9[_0x650a('0x12')][_0x650a('0x37')]){_0x48bdd4[_0x650a('0x38')]=[{'all':!![]}];}_0x48bdd4=_[_0x650a('0x33')]({},_0x48bdd4,_0x5b33c9[_0x650a('0x34')]);return db[_0x650a('0x35')][_0x650a('0x3d')](_0x48bdd4)[_0x650a('0x36')](handleEntityNotFound(_0x1acbe5,null))[_0x650a('0x36')](respondWithResult(_0x1acbe5,null))[_0x650a('0x3a')](handleError(_0x1acbe5,null));};exports[_0x650a('0x3e')]=function(_0x381632,_0x4ac78e){return db[_0x650a('0x35')][_0x650a('0x3e')](_0x381632[_0x650a('0x3f')],{})[_0x650a('0x36')](respondWithResult(_0x4ac78e,0xc9))[_0x650a('0x3a')](handleError(_0x4ac78e,null));};exports[_0x650a('0xa')]=function(_0x5b23b5,_0x2c692b){if(_0x5b23b5[_0x650a('0x3f')]['id']){delete _0x5b23b5[_0x650a('0x3f')]['id'];}return db[_0x650a('0x35')][_0x650a('0x3d')]({'where':{'id':_0x5b23b5[_0x650a('0x3c')]['id']}})['then'](handleEntityNotFound(_0x2c692b,null))['then'](saveUpdates(_0x5b23b5[_0x650a('0x3f')],null))[_0x650a('0x36')](respondWithResult(_0x2c692b,null))[_0x650a('0x3a')](handleError(_0x2c692b,null));};exports['describe']=function(_0x16fc65,_0x5b360a){return db[_0x650a('0x35')][_0x650a('0x40')]()['then'](respondWithResult(_0x5b360a,null))[_0x650a('0x3a')](handleError(_0x5b360a,null));};exports[_0x650a('0x41')]=function(_0x39e8e6,_0x47ec0d){var _0x40f9eb;var _0x3e7cfc=_0x39e8e6[_0x650a('0x3c')]['id'];return db['CmHopper'][_0x650a('0x3d')]({'where':{'id':_0x39e8e6[_0x650a('0x3c')]['id']}})[_0x650a('0x36')](handleEntityNotFound(_0x47ec0d,null))[_0x650a('0x36')](function(_0x134cb5){if(_0x134cb5){return _0x134cb5['destroy']()['then'](function(_0x215f2e){return _0x215f2e;});}})[_0x650a('0x36')](function(_0x5b2907){_0x40f9eb=_0x5b2907;if(_0x5b2907){if(_0x5b2907[_0x650a('0x42')]||_0x5b2907[_0x650a('0x43')]){return db[_0x5b2907[_0x650a('0x42')]?_0x650a('0x44'):_0x650a('0x45')][_0x650a('0x3d')]({'where':{'id':_0x5b2907['VoiceQueueId']?_0x5b2907[_0x650a('0x42')]:_0x5b2907[_0x650a('0x43')]},'attributes':['id',_0x650a('0xd')],'raw':!![]});}}})[_0x650a('0x36')](function(_0xeb5d49){var _0x5206bf={};if(_0xeb5d49){_[_0x650a('0x33')](_0x5206bf,_[_0x650a('0x46')](_0x40f9eb[_0x650a('0x47')],[_0x650a('0x48'),'updatedAt','id']));_0x5206bf['state']=0x15;_0x5206bf[_0x650a('0x49')]=_0x650a('0x4a');_0x5206bf['campaign']=_0xeb5d49[_0x650a('0xd')];_0x5206bf[_0x650a('0x4b')]=_0x39e8e6[_0x650a('0x4c')][_0x650a('0xd')];_0x5206bf[_0x650a('0x4d')]=_0x39e8e6[_0x650a('0x4c')]['id'];_0x5206bf[_0x650a('0x4a')]=!![];_0x5206bf[_0x650a('0x4e')]=moment()[_0x650a('0x4f')](_0x650a('0x50'));_0x5206bf[_0x650a('0x51')]=_0x40f9eb[_0x650a('0x52')];_0x5206bf[_0x650a('0x53')]=_0x40f9eb[_0x650a('0x42')]?_0x650a('0x54'):'ivr';return db['CmContact'][_0x650a('0x3d')]({'where':{'id':_0x5206bf[_0x650a('0x55')]},'attributes':['firstName','lastName']})[_0x650a('0x36')](function(_0x56031a){if(!_[_0x650a('0x56')](_0x47ec0d)&&!_['isNil'](_0x56031a['firstName'])){_0x5206bf[_0x650a('0x57')]=_0x56031a['firstName'];if(!_[_0x650a('0x56')](_0x56031a[_0x650a('0x58')])){_0x5206bf['calleridname']+='\x20'+_0x56031a[_0x650a('0x58')];}}})[_0x650a('0x59')](function(){return db[_0x650a('0x5a')][_0x650a('0x3e')](_0x5206bf);});}})[_0x650a('0x36')](function(_0x2e7347){return db['CmHopperAdditionalPhone'][_0x650a('0x41')]({'where':{'CmHopperId':_0x3e7cfc}});})[_0x650a('0x36')](function(){return _0x47ec0d[_0x650a('0x4')](0xcc)['end']();})[_0x650a('0x3a')](handleError(_0x47ec0d,null));};exports[_0x650a('0x5b')]=function(_0x431ef9,_0x5920a6){var _0x581ead=[];return db[_0x650a('0x5c')][_0x650a('0x40')]()['then'](function(_0x2fa55b){_0x581ead=_[_0x650a('0x13')](_0x2fa55b);return _0x431ef9[_0x650a('0x4c')][_0x650a('0x5d')]({'where':{'type':_0x650a('0x5e'),'dialActive':!![],'dialMethod':_0x650a('0x5f')},'attributes':['id','dialOrderByScheduledAt',_0x650a('0x60')],'raw':!![]});})[_0x650a('0x36')](function(_0x19f11b){if(_0x19f11b&&_0x19f11b['length']){return db[_0x650a('0x61')][_0x650a('0x62')](function(_0x576834){var _0x2ca5c0={'active':![],'recallme':![],'scheduledAt':{'$lte':moment()['format'](_0x650a('0x50'))},'VoiceQueueId':{'$in':_['map'](_0x19f11b,'id')},'$or':[{'UserId':null},{'UserId':_0x431ef9[_0x650a('0x4c')]['id']}]};var _0x1564c0={'active':![],'recallme':!![],'VoiceQueueId':{'$in':_(_0x19f11b)['filter']([_0x650a('0x60'),0x0])[_0x650a('0x11')]('id')[_0x650a('0x63')]()},'$or':[{'UserId':null},{'UserId':_0x431ef9[_0x650a('0x4c')]['id']}]};var _0x3205e4={'$or':[_0x2ca5c0,_0x1564c0]};var _0x3bd508=[];if(_0x431ef9[_0x650a('0x3f')][_0x650a('0x64')]&&_0x431ef9[_0x650a('0x3f')][_0x650a('0x64')]===_0x650a('0x65')){if(!_[_0x650a('0x66')](_0x431ef9[_0x650a('0x3f')]['hopperIds'])){_0x3205e4['id']={'$in':_0x431ef9['body'][_0x650a('0x67')]};}_0x3bd508=[['priority',_0x650a('0x68')],[_0x650a('0x69'),_0x19f11b[0x0][_0x650a('0x6a')]===_0x650a('0x68')?_0x650a('0x6b'):_0x650a('0x68')],db['sequelize'][_0x650a('0x6c')]('COALESCE(CmHopper.UserId,\x200)\x20ASC'),['id',_0x650a('0x6b')]];}else{if(!_[_0x650a('0x66')](_0x431ef9[_0x650a('0x3f')][_0x650a('0x67')])){_0x3205e4['id']={'$notIn':_0x431ef9[_0x650a('0x3f')]['hopperIds']};}_0x3bd508=[[_0x650a('0x6d'),_0x650a('0x6b')],[_0x650a('0x69'),_0x19f11b[0x0][_0x650a('0x6a')]],db[_0x650a('0x61')][_0x650a('0x6c')](_0x650a('0x6e')),['id',_0x650a('0x68')]];}return db[_0x650a('0x35')][_0x650a('0x6f')]({'attributes':['id','scheduledat','phone','recallme'],'where':_0x3205e4,'order':_0x3bd508,'transaction':_0x576834,'lock':_0x576834[_0x650a('0x70')][_0x650a('0x71')],'include':[{'model':db['CmContact'],'as':_0x650a('0x72'),'attributes':_0x581ead,'include':[{'model':db[_0x650a('0x73')],'as':_0x650a('0x74'),'attributes':['id','name']}]},{'model':db[_0x650a('0x75')],'as':'List','attributes':['id',_0x650a('0xd')]},{'model':db[_0x650a('0x44')],'as':_0x650a('0x76'),'attributes':['id',_0x650a('0xd'),_0x650a('0x77')]}]})['then'](function(_0x5e0dd7){if(_0x5e0dd7){return _0x5e0dd7[_0x650a('0xa')]({'UserId':_0x431ef9[_0x650a('0x4c')]['id']},{'transaction':_0x576834});}});});}})[_0x650a('0x36')](handleEntityNotFound(_0x5920a6,null))['then'](respondWithResult(_0x5920a6,null))[_0x650a('0x3a')](handleError(_0x5920a6,null));};exports['getPreviewRecall']=function(_0x4c29ba,_0x3767e1,_0x409f8b){var _0x383fb3=[];var _0x39b2d2=_0x4c29ba[_0x650a('0x3c')]['id'];var _0x50dfbb=_0x4c29ba[_0x650a('0x4c')]['id'];return db[_0x650a('0x5c')][_0x650a('0x40')]()['then'](function(_0x537688){_0x383fb3=_[_0x650a('0x13')](_0x537688);return db['sequelize']['transaction'](function(_0x48b3f4){const _0x14211e={'id':_0x39b2d2};return db['CmHopper']['findOne']({'attributes':['id',_0x650a('0x78'),'recallme'],'where':_0x14211e,'transaction':_0x48b3f4,'lock':_0x48b3f4[_0x650a('0x70')]['UPDATE'],'include':[{'model':db[_0x650a('0x5c')],'as':_0x650a('0x72'),'attributes':_0x383fb3,'include':[{'model':db[_0x650a('0x73')],'as':_0x650a('0x74'),'attributes':['id','name']}]},{'model':db[_0x650a('0x75')],'as':'List','attributes':['id','name']},{'model':db[_0x650a('0x44')],'as':_0x650a('0x76'),'attributes':['id',_0x650a('0xd'),_0x650a('0x77')]}]})[_0x650a('0x36')](function(_0x7701cc){if(_0x7701cc){return _0x7701cc['update']({'UserId':_0x50dfbb},{'transaction':_0x48b3f4});}});});})[_0x650a('0x36')](handleEntityNotFound(_0x3767e1,null))[_0x650a('0x36')](respondWithResult(_0x3767e1,null))[_0x650a('0x3a')](handleError(_0x3767e1,null));};exports['getOpenContacts']=function(_0x13e6fe,_0x1fec64){return _0x13e6fe[_0x650a('0x4c')][_0x650a('0x5d')]({'where':{'type':_0x650a('0x5e'),'dialActive':!![],'dialMethod':'preview'},'attributes':['id'],'raw':!![]})[_0x650a('0x36')](function(_0x2e62f3){if(_0x2e62f3&&_0x2e62f3['length']){return db[_0x650a('0x35')]['count']({'where':{'active':![],'recallme':![],'scheduledAt':{'$lte':moment()['format'](_0x650a('0x50'))},'VoiceQueueId':{'$in':_[_0x650a('0x11')](_0x2e62f3,'id')},'$or':[{'UserId':null},{'UserId':_0x13e6fe['user']['id']}]}});}return 0x0;})[_0x650a('0x36')](function(_0x446c6f){if(!_[_0x650a('0x56')](_0x446c6f)&&_[_0x650a('0x79')](_0x446c6f)){return _0x1fec64[_0x650a('0x4')](0xc8)[_0x650a('0x9')]({'contacts':_0x446c6f});}else{logger['error'](_0x650a('0x7a'),_0x650a('0x7b'),0x194,_0x650a('0x7c'));_0x1fec64[_0x650a('0xb')](0x194);}})[_0x650a('0x3a')](handleError(_0x1fec64,null));};exports[_0x650a('0x7d')]=function(_0x5631bf,_0x16e596){var _0xcf6cb3=shared[_0x650a('0x7e')];var _0x2fb487=[];_[_0x650a('0x11')](_0xcf6cb3,function(_0x273943){_0x2fb487['push']({'id':_0x273943[_0x650a('0xd')],'name':_0x273943[_0x650a('0xd')],'utcOffset':_0x273943['utcOffset']});});return _0x16e596[_0x650a('0x4')](0xc8)[_0x650a('0x9')]({'tz':_0x2fb487});};exports['getTimezone']=function(_0x47e6a6,_0x5dd509){var _0x137bdd=shared[_0x650a('0x7e')];var _0x20780e={};if(!_['isNil'](_0x137bdd[_0x47e6a6[_0x650a('0x3f')]['id']]))_0x20780e=_0x137bdd[_0x47e6a6[_0x650a('0x3f')]['id']];return _0x5dd509[_0x650a('0x4')](0xc8)[_0x650a('0x9')](_0x20780e);};
\ No newline at end of file
+var _0x6f47=['VoiceQueue','Campaign','CampaignId','omit','dataValues','createdAt','updatedAt','statedesc','deleted','campaign','user','UserId','format','YYYY-MM-DD\x20HH:mm:ss','calleridnum','campaigntype','queue','ContactId','isNil','firstName','calleridname','lastName','CmHopperFinal','create','end','getPreview','getVoiceQueues','outbound','dialOrderByScheduledAt','dialPreviewAutoRecallMe','sequelize','transaction','value','body','direction','prev','isEmpty','priority','ASC','scheduledAt','DESC','literal','COALESCE(CmHopper.UserId,\x200)\x20ASC','hopperIds','COALESCE(CmHopper.UserId,\x200)\x20DESC','findOne','scheduledat','phone','recallme','LOCK','UPDATE','Contact','CmCompany','Company','List','dialActive','getPreviewRecall','CmContact','CmList','getOpenContacts','preview','isNumber','CmHopper,\x20%s,\x20%s,\x20%s','entity\x20not\x20found','sendStatus','getTimezones','timezones','push','getTimezone','lodash','../../components/parsers/qs','api','../../mysqldb','status','json','undefined','limit','count','set','Content-Range','update','error','stack','name','send','index','map','CmHopper','rawAttributes','fieldName','type','model','query','keys','filters','concat','$and','$or','$lt','$ne','$notBetween','$in','$notIn','$like','$notLike','$iLike','$any','attributes','intersection','length','nolimit','offset','order','sort','filter','where','VIRTUAL','merge','options','then','includeAll','include','show','params','fields','find','catch','describe','destroy','VoiceQueueId'];(function(_0x19e1e8,_0x150698){var _0x21fc2c=function(_0x55facc){while(--_0x55facc){_0x19e1e8['push'](_0x19e1e8['shift']());}};_0x21fc2c(++_0x150698);}(_0x6f47,0xc7));var _0x76f4=function(_0x9fd887,_0x47f76c){_0x9fd887=_0x9fd887-0x0;var _0x1a54ab=_0x6f47[_0x9fd887];return _0x1a54ab;};'use strict';var moment=require('moment');var _=require(_0x76f4('0x0'));var qs=require(_0x76f4('0x1'));var logger=require('../../config/logger')(_0x76f4('0x2'));var shared=require('../../config/environment');var db=require(_0x76f4('0x3'))['db'];function respondWithResult(_0x47d3e1,_0xe214ad){_0xe214ad=_0xe214ad||0xc8;return function(_0xc5dddc){if(_0xc5dddc){return _0x47d3e1[_0x76f4('0x4')](_0xe214ad)[_0x76f4('0x5')](_0xc5dddc);}};}function respondWithFilteredResult(_0x5754ca,_0x35602f){return function(_0xfc2405){if(_0xfc2405){var _0x2176a7=typeof _0x35602f['offset']===_0x76f4('0x6')&&typeof _0x35602f[_0x76f4('0x7')]===_0x76f4('0x6');var _0xf9b468=_0xfc2405[_0x76f4('0x8')];var _0x4c6b5c=_0x2176a7?0x0:_0x35602f['offset'];var _0x3347ef=_0x2176a7?_0xfc2405[_0x76f4('0x8')]:_0x35602f['offset']+_0x35602f['limit'];var _0x3d8554;if(_0x3347ef>=_0xf9b468){_0x3347ef=_0xf9b468;_0x3d8554=0xc8;}else{_0x3d8554=0xce;}_0x5754ca[_0x76f4('0x4')](_0x3d8554);return _0x5754ca[_0x76f4('0x9')](_0x76f4('0xa'),_0x4c6b5c+'-'+_0x3347ef+'/'+_0xf9b468)[_0x76f4('0x5')](_0xfc2405);}return null;};}function saveUpdates(_0xafd21e,_0xf7e347){return function(_0x3ec740){if(_0x3ec740){return _0x3ec740[_0x76f4('0xb')](_0xafd21e)['then'](function(_0x41ba00){return _0x41ba00;});}return null;};}function handleEntityNotFound(_0x30dabf,_0x5da1ff){return function(_0x4b6021){if(!_0x4b6021){_0x30dabf['sendStatus'](0x194);}return _0x4b6021;};}function handleError(_0x1d7755,_0x3dd240){_0x3dd240=_0x3dd240||0x1f4;return function(_0x979946){logger[_0x76f4('0xc')](_0x979946[_0x76f4('0xd')]);if(_0x979946[_0x76f4('0xe')]){delete _0x979946[_0x76f4('0xe')];}_0x1d7755[_0x76f4('0x4')](_0x3dd240)[_0x76f4('0xf')](_0x979946);};}exports[_0x76f4('0x10')]=function(_0x672960,_0x2d4bd1){var _0x214bef={},_0x38450e={},_0x17625e={'count':0x0,'rows':[]};var _0x397360=_[_0x76f4('0x11')](db[_0x76f4('0x12')][_0x76f4('0x13')],function(_0x35b406){return{'name':_0x35b406[_0x76f4('0x14')],'type':_0x35b406[_0x76f4('0x15')]['key']};});_0x38450e[_0x76f4('0x16')]=_['map'](_0x397360,_0x76f4('0xe'));_0x38450e[_0x76f4('0x17')]=_[_0x76f4('0x18')](_0x672960['query']);_0x38450e['filters']=_['intersection'](_0x38450e[_0x76f4('0x16')],_0x38450e[_0x76f4('0x17')]);_0x38450e[_0x76f4('0x19')]=_[_0x76f4('0x1a')](_0x38450e[_0x76f4('0x19')],[_0x76f4('0x1b'),_0x76f4('0x1c'),'$gt','$gte',_0x76f4('0x1d'),'$lte',_0x76f4('0x1e'),'$eq','$not','$between',_0x76f4('0x1f'),_0x76f4('0x20'),_0x76f4('0x21'),_0x76f4('0x22'),_0x76f4('0x23'),_0x76f4('0x24'),'$notILike',_0x76f4('0x22'),'$overlap','$contains','$contained',_0x76f4('0x25')]);_0x214bef[_0x76f4('0x26')]=_[_0x76f4('0x27')](_0x38450e[_0x76f4('0x16')],qs['fields'](_0x672960[_0x76f4('0x17')]['fields']));_0x214bef[_0x76f4('0x26')]=_0x214bef[_0x76f4('0x26')][_0x76f4('0x28')]?_0x214bef[_0x76f4('0x26')]:_0x38450e[_0x76f4('0x16')];if(!_0x672960['query']['hasOwnProperty'](_0x76f4('0x29'))){_0x214bef[_0x76f4('0x7')]=qs[_0x76f4('0x7')](_0x672960[_0x76f4('0x17')][_0x76f4('0x7')]);_0x214bef[_0x76f4('0x2a')]=qs[_0x76f4('0x2a')](_0x672960[_0x76f4('0x17')][_0x76f4('0x2a')]);}_0x214bef[_0x76f4('0x2b')]=qs[_0x76f4('0x2c')](_0x672960[_0x76f4('0x17')]['sort']);_0x214bef['where']=qs['filters'](_['pick'](_0x672960[_0x76f4('0x17')],_0x38450e[_0x76f4('0x19')]),_0x397360);if(_0x672960[_0x76f4('0x17')][_0x76f4('0x2d')]){_0x214bef[_0x76f4('0x2e')]=_['merge'](_0x214bef[_0x76f4('0x2e')],{'$or':_[_0x76f4('0x11')](_0x397360,function(_0x37a233){if(_0x37a233[_0x76f4('0x15')]!==_0x76f4('0x2f')){var _0x23278f={};_0x23278f[_0x37a233[_0x76f4('0xe')]]={'$like':'%'+_0x672960[_0x76f4('0x17')][_0x76f4('0x2d')]+'%'};return _0x23278f;}})});}_0x214bef=_[_0x76f4('0x30')]({},_0x214bef,_0x672960[_0x76f4('0x31')]);var _0x244607={'where':_0x214bef[_0x76f4('0x2e')]};return db[_0x76f4('0x12')][_0x76f4('0x8')](_0x244607)[_0x76f4('0x32')](function(_0x3308e3){_0x17625e[_0x76f4('0x8')]=_0x3308e3;if(_0x672960['query'][_0x76f4('0x33')]){_0x214bef[_0x76f4('0x34')]=[{'all':!![]}];}return db[_0x76f4('0x12')]['findAll'](_0x214bef);})['then'](function(_0x237fba){_0x17625e['rows']=_0x237fba;return _0x17625e;})[_0x76f4('0x32')](respondWithFilteredResult(_0x2d4bd1,_0x214bef))['catch'](handleError(_0x2d4bd1,null));};exports[_0x76f4('0x35')]=function(_0x16f36d,_0x312243){var _0x378675={'raw':!![],'where':{'id':_0x16f36d[_0x76f4('0x36')]['id']}},_0x2c0b76={};_0x2c0b76[_0x76f4('0x16')]=_[_0x76f4('0x18')](db[_0x76f4('0x12')][_0x76f4('0x13')]);_0x2c0b76['query']=_['keys'](_0x16f36d[_0x76f4('0x17')]);_0x2c0b76[_0x76f4('0x19')]=_[_0x76f4('0x27')](_0x2c0b76[_0x76f4('0x16')],_0x2c0b76[_0x76f4('0x17')]);_0x378675[_0x76f4('0x26')]=_[_0x76f4('0x27')](_0x2c0b76[_0x76f4('0x16')],qs[_0x76f4('0x37')](_0x16f36d['query'][_0x76f4('0x37')]));_0x378675[_0x76f4('0x26')]=_0x378675['attributes']['length']?_0x378675[_0x76f4('0x26')]:_0x2c0b76[_0x76f4('0x16')];if(_0x16f36d[_0x76f4('0x17')][_0x76f4('0x33')]){_0x378675[_0x76f4('0x34')]=[{'all':!![]}];}_0x378675=_['merge']({},_0x378675,_0x16f36d[_0x76f4('0x31')]);return db[_0x76f4('0x12')][_0x76f4('0x38')](_0x378675)[_0x76f4('0x32')](handleEntityNotFound(_0x312243,null))[_0x76f4('0x32')](respondWithResult(_0x312243,null))[_0x76f4('0x39')](handleError(_0x312243,null));};exports['create']=function(_0x317c91,_0x2795db){return db[_0x76f4('0x12')]['create'](_0x317c91['body'],{})[_0x76f4('0x32')](respondWithResult(_0x2795db,0xc9))[_0x76f4('0x39')](handleError(_0x2795db,null));};exports[_0x76f4('0xb')]=function(_0x2bea6d,_0x36fa03){if(_0x2bea6d['body']['id']){delete _0x2bea6d['body']['id'];}return db[_0x76f4('0x12')]['find']({'where':{'id':_0x2bea6d[_0x76f4('0x36')]['id']}})[_0x76f4('0x32')](handleEntityNotFound(_0x36fa03,null))['then'](saveUpdates(_0x2bea6d['body'],null))[_0x76f4('0x32')](respondWithResult(_0x36fa03,null))[_0x76f4('0x39')](handleError(_0x36fa03,null));};exports[_0x76f4('0x3a')]=function(_0x217d3a,_0x55e4cc){return db[_0x76f4('0x12')][_0x76f4('0x3a')]()[_0x76f4('0x32')](respondWithResult(_0x55e4cc,null))['catch'](handleError(_0x55e4cc,null));};exports[_0x76f4('0x3b')]=function(_0x6bbcf2,_0x535eca){var _0x56d905;var _0x4ab620=_0x6bbcf2[_0x76f4('0x36')]['id'];return db[_0x76f4('0x12')][_0x76f4('0x38')]({'where':{'id':_0x6bbcf2[_0x76f4('0x36')]['id']}})['then'](handleEntityNotFound(_0x535eca,null))[_0x76f4('0x32')](function(_0x597de5){if(_0x597de5){return _0x597de5[_0x76f4('0x3b')]()[_0x76f4('0x32')](function(_0x270baf){return _0x270baf;});}})['then'](function(_0x312319){_0x56d905=_0x312319;if(_0x312319){if(_0x312319[_0x76f4('0x3c')]||_0x312319['CampaignId']){return db[_0x312319[_0x76f4('0x3c')]?_0x76f4('0x3d'):_0x76f4('0x3e')][_0x76f4('0x38')]({'where':{'id':_0x312319[_0x76f4('0x3c')]?_0x312319['VoiceQueueId']:_0x312319[_0x76f4('0x3f')]},'attributes':['id','name'],'raw':!![]});}}})[_0x76f4('0x32')](function(_0x38dc69){var _0x154ba={};if(_0x38dc69){_['merge'](_0x154ba,_[_0x76f4('0x40')](_0x56d905[_0x76f4('0x41')],[_0x76f4('0x42'),_0x76f4('0x43'),'id']));_0x154ba['state']=0x15;_0x154ba[_0x76f4('0x44')]=_0x76f4('0x45');_0x154ba[_0x76f4('0x46')]=_0x38dc69[_0x76f4('0xe')];_0x154ba['membername']=_0x6bbcf2[_0x76f4('0x47')]['name'];_0x154ba[_0x76f4('0x48')]=_0x6bbcf2[_0x76f4('0x47')]['id'];_0x154ba['deleted']=!![];_0x154ba['deletedat']=moment()[_0x76f4('0x49')](_0x76f4('0x4a'));_0x154ba[_0x76f4('0x4b')]=_0x56d905['phone'];_0x154ba[_0x76f4('0x4c')]=_0x56d905[_0x76f4('0x3c')]?_0x76f4('0x4d'):'ivr';return db['CmContact'][_0x76f4('0x38')]({'where':{'id':_0x154ba[_0x76f4('0x4e')]},'attributes':['firstName','lastName']})[_0x76f4('0x32')](function(_0x34a5d1){if(!_[_0x76f4('0x4f')](_0x535eca)&&!_[_0x76f4('0x4f')](_0x34a5d1[_0x76f4('0x50')])){_0x154ba[_0x76f4('0x51')]=_0x34a5d1[_0x76f4('0x50')];if(!_[_0x76f4('0x4f')](_0x34a5d1[_0x76f4('0x52')])){_0x154ba['calleridname']+='\x20'+_0x34a5d1['lastName'];}}})['finally'](function(){return db[_0x76f4('0x53')][_0x76f4('0x54')](_0x154ba);});}})[_0x76f4('0x32')](function(_0x3b6c16){return db['CmHopperAdditionalPhone']['destroy']({'where':{'CmHopperId':_0x4ab620}});})[_0x76f4('0x32')](function(){return _0x535eca['status'](0xcc)[_0x76f4('0x55')]();})['catch'](handleError(_0x535eca,null));};exports[_0x76f4('0x56')]=function(_0x25e510,_0x3984d3){var _0x3317a4=[];return db['CmContact'][_0x76f4('0x3a')]()[_0x76f4('0x32')](function(_0x22a0cc){_0x3317a4=_[_0x76f4('0x18')](_0x22a0cc);return _0x25e510[_0x76f4('0x47')][_0x76f4('0x57')]({'where':{'type':_0x76f4('0x58'),'dialActive':!![],'dialMethod':'preview'},'attributes':['id',_0x76f4('0x59'),_0x76f4('0x5a')],'raw':!![]});})[_0x76f4('0x32')](function(_0x320a87){if(_0x320a87&&_0x320a87[_0x76f4('0x28')]){return db[_0x76f4('0x5b')][_0x76f4('0x5c')](function(_0x551d38){var _0x5724c3={'active':![],'recallme':![],'scheduledAt':{'$lte':moment()['format'](_0x76f4('0x4a'))},'VoiceQueueId':{'$in':_[_0x76f4('0x11')](_0x320a87,'id')},'$or':[{'UserId':null},{'UserId':_0x25e510[_0x76f4('0x47')]['id']}]};var _0x5f0dc2={'active':![],'recallme':!![],'VoiceQueueId':{'$in':_(_0x320a87)[_0x76f4('0x2d')](['dialPreviewAutoRecallMe',0x0])[_0x76f4('0x11')]('id')[_0x76f4('0x5d')]()},'$or':[{'UserId':null},{'UserId':_0x25e510['user']['id']}]};var _0xda0ac2={'$or':[_0x5724c3,_0x5f0dc2]};var _0x37b7f7=[];if(_0x25e510[_0x76f4('0x5e')][_0x76f4('0x5f')]&&_0x25e510[_0x76f4('0x5e')][_0x76f4('0x5f')]===_0x76f4('0x60')){if(!_[_0x76f4('0x61')](_0x25e510[_0x76f4('0x5e')]['hopperIds'])){_0xda0ac2['id']={'$in':_0x25e510[_0x76f4('0x5e')]['hopperIds']};}_0x37b7f7=[[_0x76f4('0x62'),_0x76f4('0x63')],[_0x76f4('0x64'),_0x320a87[0x0][_0x76f4('0x59')]===_0x76f4('0x63')?_0x76f4('0x65'):_0x76f4('0x63')],db[_0x76f4('0x5b')][_0x76f4('0x66')](_0x76f4('0x67')),['id','DESC']];}else{if(!_[_0x76f4('0x61')](_0x25e510[_0x76f4('0x5e')]['hopperIds'])){_0xda0ac2['id']={'$notIn':_0x25e510[_0x76f4('0x5e')][_0x76f4('0x68')]};}_0x37b7f7=[[_0x76f4('0x62'),'DESC'],[_0x76f4('0x64'),_0x320a87[0x0][_0x76f4('0x59')]],db[_0x76f4('0x5b')]['literal'](_0x76f4('0x69')),['id',_0x76f4('0x63')]];}return db[_0x76f4('0x12')][_0x76f4('0x6a')]({'attributes':['id',_0x76f4('0x6b'),_0x76f4('0x6c'),_0x76f4('0x6d')],'where':_0xda0ac2,'order':_0x37b7f7,'transaction':_0x551d38,'lock':_0x551d38[_0x76f4('0x6e')][_0x76f4('0x6f')],'include':[{'model':db['CmContact'],'as':_0x76f4('0x70'),'attributes':_0x3317a4,'include':[{'model':db[_0x76f4('0x71')],'as':_0x76f4('0x72'),'attributes':['id',_0x76f4('0xe')]}]},{'model':db['CmList'],'as':_0x76f4('0x73'),'attributes':['id',_0x76f4('0xe')]},{'model':db[_0x76f4('0x3d')],'as':'Queue','attributes':['id',_0x76f4('0xe'),_0x76f4('0x74')]}]})[_0x76f4('0x32')](function(_0x99fbd6){if(_0x99fbd6){return _0x99fbd6[_0x76f4('0xb')]({'UserId':_0x25e510['user']['id']},{'transaction':_0x551d38});}});});}})[_0x76f4('0x32')](handleEntityNotFound(_0x3984d3,null))['then'](respondWithResult(_0x3984d3,null))[_0x76f4('0x39')](handleError(_0x3984d3,null));};exports[_0x76f4('0x75')]=function(_0x5e6df9,_0x53cb70,_0x58251e){var _0x3aa958=[];var _0x462f3e=_0x5e6df9[_0x76f4('0x36')]['id'];var _0x3e2a07=_0x5e6df9[_0x76f4('0x47')]['id'];return db[_0x76f4('0x76')]['describe']()[_0x76f4('0x32')](function(_0x1bb9b3){_0x3aa958=_[_0x76f4('0x18')](_0x1bb9b3);return db[_0x76f4('0x5b')][_0x76f4('0x5c')](function(_0x1c8973){const _0x307060={'id':_0x462f3e};return db[_0x76f4('0x12')]['findOne']({'attributes':['id',_0x76f4('0x6b'),'recallme'],'where':_0x307060,'transaction':_0x1c8973,'lock':_0x1c8973[_0x76f4('0x6e')][_0x76f4('0x6f')],'include':[{'model':db[_0x76f4('0x76')],'as':_0x76f4('0x70'),'attributes':_0x3aa958,'include':[{'model':db[_0x76f4('0x71')],'as':_0x76f4('0x72'),'attributes':['id',_0x76f4('0xe')]}]},{'model':db[_0x76f4('0x77')],'as':'List','attributes':['id',_0x76f4('0xe')]},{'model':db['VoiceQueue'],'as':'Queue','attributes':['id','name',_0x76f4('0x74')]}]})[_0x76f4('0x32')](function(_0x279040){if(_0x279040){return _0x279040[_0x76f4('0xb')]({'UserId':_0x3e2a07},{'transaction':_0x1c8973});}});});})['then'](handleEntityNotFound(_0x53cb70,null))[_0x76f4('0x32')](respondWithResult(_0x53cb70,null))[_0x76f4('0x39')](handleError(_0x53cb70,null));};exports[_0x76f4('0x78')]=function(_0x5f5c24,_0x12f16e){return _0x5f5c24[_0x76f4('0x47')][_0x76f4('0x57')]({'where':{'type':_0x76f4('0x58'),'dialActive':!![],'dialMethod':_0x76f4('0x79')},'attributes':['id'],'raw':!![]})[_0x76f4('0x32')](function(_0x3b5e15){if(_0x3b5e15&&_0x3b5e15['length']){return db[_0x76f4('0x12')][_0x76f4('0x8')]({'where':{'active':![],'recallme':![],'scheduledAt':{'$lte':moment()['format'](_0x76f4('0x4a'))},'VoiceQueueId':{'$in':_[_0x76f4('0x11')](_0x3b5e15,'id')},'$or':[{'UserId':null},{'UserId':_0x5f5c24[_0x76f4('0x47')]['id']}]}});}return 0x0;})[_0x76f4('0x32')](function(_0x36d95c){if(!_[_0x76f4('0x4f')](_0x36d95c)&&_[_0x76f4('0x7a')](_0x36d95c)){return _0x12f16e[_0x76f4('0x4')](0xc8)[_0x76f4('0x5')]({'contacts':_0x36d95c});}else{logger['error'](_0x76f4('0x7b'),_0x76f4('0x78'),0x194,_0x76f4('0x7c'));_0x12f16e[_0x76f4('0x7d')](0x194);}})['catch'](handleError(_0x12f16e,null));};exports[_0x76f4('0x7e')]=function(_0x5df706,_0x420281){var _0x4a7a98=shared[_0x76f4('0x7f')];var _0x7380f=[];_['map'](_0x4a7a98,function(_0x5a3239){_0x7380f[_0x76f4('0x80')]({'id':_0x5a3239[_0x76f4('0xe')],'name':_0x5a3239[_0x76f4('0xe')],'utcOffset':_0x5a3239['utcOffset']});});return _0x420281['status'](0xc8)[_0x76f4('0x5')]({'tz':_0x7380f});};exports[_0x76f4('0x81')]=function(_0x52453,_0x36ab57){var _0x291b87=shared[_0x76f4('0x7f')];var _0x98a269={};if(!_[_0x76f4('0x4f')](_0x291b87[_0x52453['body']['id']]))_0x98a269=_0x291b87[_0x52453['body']['id']];return _0x36ab57[_0x76f4('0x4')](0xc8)[_0x76f4('0x5')](_0x98a269);};
\ No newline at end of file