Built motion from commit 5b761a7b.|2.5.36
[motion2.git] / server / api / voiceQueue / voiceQueue.controller.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 _0x3542=['Team','addTeams','teams','voicePause','interface','flatMap','Agents','forEach','penalty','transaction','each','TeamVoiceQueue','upsert','UserVoiceQueue','findOrCreate','UserVoiceQueueRt','format','SIP/%s','emit','userVoiceQueue:save','removeTeams','select','field','tq.TeamId','from','team_has_voice_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','sequelize','toString','QueryTypes','SELECT','every','includes','union','compact','ids','userVoiceQueue:remove','addAgents','spread','isEmpty','online','isNil','all','removeAgents','isArray','User','getAgents','getMembers','getLists','addLists','dialCheckDuplicateType','always','insert','into','cm_hopper','phone','scheduledAt','ContactId','ListId','CmListId','NOW()','cm_contacts','phone\x20IS\x20NOT\x20NULL','phone\x20NOT\x20IN\x20(?)','COALESCE(calleridnum,\x27\x27)','cm_hopper_final','VoiceQueueId\x20=\x20?','COALESCE(phone,\x27\x27)','deletedAt\x20IS\x20NULL','ListId\x20=\x20?','fromQuery','push','removeLists','getBlackLists','cm_hopper_black','removeBlackLists','eml-format','rimraf','zip-dir','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','redis','socket.io-emitter','./voiceQueue.socket','status','end','json','undefined','count','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','get','VoiceQueues','inbound','QueueCampaigns','outbound','filter','ignore','value','type','find','error','stack','name','send','index','map','VoiceQueue','rawAttributes','fieldName','key','keys','intersection','model','attributes','fields','query','hasOwnProperty','nolimit','order','sort','filters','merge','options','where','includeAll','include','catch','show','params','create','body','user','UserProfileSection','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','clone','omit','createdAt','updatedAt','role','getHoppers','findOne','pick','CmHopper','findAll','rows','getHopperHistories','CmHopperHistory','length','VoiceQueueId','getHopperFinals','CmHopperFinal','CmHopperBlack','getTeams'];(function(_0x2c14ec,_0x464b23){var _0x22960c=function(_0xdd2c69){while(--_0xdd2c69){_0x2c14ec['push'](_0x2c14ec['shift']());}};_0x22960c(++_0x464b23);}(_0x3542,0x1c8));var _0x2354=function(_0x25f9dc,_0x36c8e1){_0x25f9dc=_0x25f9dc-0x0;var _0x4213ec=_0x3542[_0x25f9dc];return _0x4213ec;};'use strict';var emlformat=require(_0x2354('0x0'));var rimraf=require(_0x2354('0x1'));var zipdir=require(_0x2354('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x2354('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x2354('0x4'));var util=require(_0x2354('0x5'));var path=require(_0x2354('0x6'));var sox=require(_0x2354('0x7'));var csv=require(_0x2354('0x8'));var ejs=require(_0x2354('0x9'));var fs=require('fs');var fs_extra=require(_0x2354('0xa'));var _=require(_0x2354('0xb'));var squel=require(_0x2354('0xc'));var crypto=require(_0x2354('0xd'));var jsforce=require(_0x2354('0xe'));var deskjs=require(_0x2354('0xf'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x2354('0x10'));var Redis=require(_0x2354('0x11'));var authService=require(_0x2354('0x12'));var qs=require(_0x2354('0x13'));var as=require(_0x2354('0x14'));var hardwareService=require(_0x2354('0x15'));var logger=require(_0x2354('0x16'))(_0x2354('0x17'));var utils=require('../../config/utils');var config=require(_0x2354('0x18'));var licenseUtil=require(_0x2354('0x19'));var db=require(_0x2354('0x1a'))['db'];config[_0x2354('0x1b')]=_['defaults'](config[_0x2354('0x1b')],{'host':'localhost','port':0x18eb});var socket=require(_0x2354('0x1c'))(new Redis(config['redis']));require(_0x2354('0x1d'))['register'](socket);function respondWithStatusCode(_0x450997,_0x58f678){_0x58f678=_0x58f678||0xcc;return function(_0x1e23d9){if(_0x1e23d9){return _0x450997['sendStatus'](_0x58f678);}return _0x450997[_0x2354('0x1e')](_0x58f678)[_0x2354('0x1f')]();};}function respondWithResult(_0x5f3498,_0x4970bc){_0x4970bc=_0x4970bc||0xc8;return function(_0x1064d0){if(_0x1064d0){return _0x5f3498[_0x2354('0x1e')](_0x4970bc)[_0x2354('0x20')](_0x1064d0);}};}function respondWithFilteredResult(_0x344c67,_0x41939a){return function(_0x2b88eb){if(_0x2b88eb){var _0xc856a7=typeof _0x41939a['offset']==='undefined'&&typeof _0x41939a['limit']===_0x2354('0x21');var _0x2b0621=_0x2b88eb[_0x2354('0x22')];var _0x1dfb64=_0xc856a7?0x0:_0x41939a[_0x2354('0x23')];var _0x34eb74=_0xc856a7?_0x2b88eb[_0x2354('0x22')]:_0x41939a[_0x2354('0x23')]+_0x41939a[_0x2354('0x24')];var _0x3fd7d8;if(_0x34eb74>=_0x2b0621){_0x34eb74=_0x2b0621;_0x3fd7d8=0xc8;}else{_0x3fd7d8=0xce;}_0x344c67[_0x2354('0x1e')](_0x3fd7d8);return _0x344c67[_0x2354('0x25')](_0x2354('0x26'),_0x1dfb64+'-'+_0x34eb74+'/'+_0x2b0621)['json'](_0x2b88eb);}return null;};}function patchUpdates(_0x44c01c){return function(_0x5e6b09){try{jsonpatch[_0x2354('0x27')](_0x5e6b09,_0x44c01c,!![]);}catch(_0x3a4ade){return BPromise[_0x2354('0x28')](_0x3a4ade);}return _0x5e6b09[_0x2354('0x29')]();};}function saveUpdates(_0x2a0ee8,_0x3c5ade){return function(_0x5cfb53){if(_0x5cfb53){return _0x5cfb53[_0x2354('0x2a')](_0x2a0ee8)[_0x2354('0x2b')](function(_0x2c61fe){return _0x2c61fe;});}return null;};}function removeEntity(_0x41b93d,_0x5e74ca){return function(_0x10f602){if(_0x10f602){return _0x10f602[_0x2354('0x2c')]()[_0x2354('0x2b')](function(){var _0x22ccbf=_0x10f602[_0x2354('0x2d')]({'plain':!![]});var _0x563386=[{'name':_0x2354('0x2e'),'value':_0x2354('0x2f'),'ignore':![]},{'name':_0x2354('0x30'),'value':_0x2354('0x31'),'ignore':![]}];var _0x58c05f=_(_0x563386)[_0x2354('0x32')](_0x2354('0x33'))['map']('value')[_0x2354('0x34')]();if(_['includes'](_0x58c05f,_0x22ccbf[_0x2354('0x35')])){return;}var _0x4e62bf=_[_0x2354('0x36')](_0x563386,[_0x2354('0x34'),_0x22ccbf[_0x2354('0x35')]])['name'];return db['UserProfileResource']['destroy']({'where':{'type':_0x4e62bf,'resourceId':_0x22ccbf['id']}})[_0x2354('0x2b')](function(){return _0x10f602;});})['then'](function(){_0x41b93d[_0x2354('0x1e')](0xcc)[_0x2354('0x1f')]();});}};}function handleEntityNotFound(_0x339ad6,_0x32921c){return function(_0x31684b){if(!_0x31684b){_0x339ad6['sendStatus'](0x194);}return _0x31684b;};}function handleError(_0x390ac2,_0x985769){_0x985769=_0x985769||0x1f4;return function(_0x3173b5){logger[_0x2354('0x37')](_0x3173b5[_0x2354('0x38')]);if(_0x3173b5[_0x2354('0x39')]){delete _0x3173b5[_0x2354('0x39')];}_0x390ac2[_0x2354('0x1e')](_0x985769)[_0x2354('0x3a')](_0x3173b5);};}exports[_0x2354('0x3b')]=function(_0x39b245,_0x406f3d){var _0x39126b={},_0x18da45={},_0x423c7f={'count':0x0,'rows':[]};var _0x33c482=_[_0x2354('0x3c')](db[_0x2354('0x3d')][_0x2354('0x3e')],function(_0x5aefd8){return{'name':_0x5aefd8[_0x2354('0x3f')],'type':_0x5aefd8[_0x2354('0x35')][_0x2354('0x40')]};});_0x18da45['model']=_[_0x2354('0x3c')](_0x33c482,'name');_0x18da45['query']=_[_0x2354('0x41')](_0x39b245['query']);_0x18da45['filters']=_[_0x2354('0x42')](_0x18da45[_0x2354('0x43')],_0x18da45['query']);_0x39126b[_0x2354('0x44')]=_[_0x2354('0x42')](_0x18da45[_0x2354('0x43')],qs[_0x2354('0x45')](_0x39b245[_0x2354('0x46')][_0x2354('0x45')]));_0x39126b[_0x2354('0x44')]=_0x39126b[_0x2354('0x44')]['length']?_0x39126b[_0x2354('0x44')]:_0x18da45[_0x2354('0x43')];if(!_0x39b245[_0x2354('0x46')][_0x2354('0x47')](_0x2354('0x48'))){_0x39126b[_0x2354('0x24')]=qs['limit'](_0x39b245[_0x2354('0x46')]['limit']);_0x39126b['offset']=qs[_0x2354('0x23')](_0x39b245['query'][_0x2354('0x23')]);}_0x39126b[_0x2354('0x49')]=qs[_0x2354('0x4a')](_0x39b245['query'][_0x2354('0x4a')]);_0x39126b['where']=qs[_0x2354('0x4b')](_['pick'](_0x39b245['query'],_0x18da45[_0x2354('0x4b')]),_0x33c482);if(_0x39b245['query'][_0x2354('0x32')]){_0x39126b['where']=_[_0x2354('0x4c')](_0x39126b['where'],{'$or':_[_0x2354('0x3c')](_0x33c482,function(_0x740125){if(_0x740125['type']!=='VIRTUAL'){var _0x17cab7={};_0x17cab7[_0x740125[_0x2354('0x39')]]={'$like':'%'+_0x39b245[_0x2354('0x46')][_0x2354('0x32')]+'%'};return _0x17cab7;}})});}_0x39126b=_[_0x2354('0x4c')]({},_0x39126b,_0x39b245[_0x2354('0x4d')]);var _0x1c3179={'where':_0x39126b[_0x2354('0x4e')]};return db[_0x2354('0x3d')][_0x2354('0x22')](_0x1c3179)['then'](function(_0x1390f5){_0x423c7f[_0x2354('0x22')]=_0x1390f5;if(_0x39b245[_0x2354('0x46')][_0x2354('0x4f')]){_0x39126b[_0x2354('0x50')]=[{'all':!![]}];}return db['VoiceQueue']['findAll'](_0x39126b);})[_0x2354('0x2b')](function(_0x4df6bd){_0x423c7f['rows']=_0x4df6bd;return _0x423c7f;})[_0x2354('0x2b')](respondWithFilteredResult(_0x406f3d,_0x39126b))[_0x2354('0x51')](handleError(_0x406f3d,null));};exports[_0x2354('0x52')]=function(_0x4efb23,_0x20fe77){var _0x471223={'raw':![],'where':{'id':_0x4efb23[_0x2354('0x53')]['id']}},_0x5a06c6={};_0x5a06c6['model']=_['keys'](db[_0x2354('0x3d')][_0x2354('0x3e')]);_0x5a06c6[_0x2354('0x46')]=_['keys'](_0x4efb23[_0x2354('0x46')]);_0x5a06c6[_0x2354('0x4b')]=_[_0x2354('0x42')](_0x5a06c6[_0x2354('0x43')],_0x5a06c6[_0x2354('0x46')]);_0x471223['attributes']=_['intersection'](_0x5a06c6[_0x2354('0x43')],qs[_0x2354('0x45')](_0x4efb23[_0x2354('0x46')][_0x2354('0x45')]));_0x471223[_0x2354('0x44')]=_0x471223[_0x2354('0x44')]['length']?_0x471223[_0x2354('0x44')]:_0x5a06c6['model'];if(_0x4efb23['query'][_0x2354('0x4f')]){_0x471223[_0x2354('0x50')]=[{'all':!![]}];}_0x471223=_[_0x2354('0x4c')]({},_0x471223,_0x4efb23[_0x2354('0x4d')]);return db[_0x2354('0x3d')][_0x2354('0x36')](_0x471223)[_0x2354('0x2b')](handleEntityNotFound(_0x20fe77,null))[_0x2354('0x2b')](respondWithResult(_0x20fe77,null))[_0x2354('0x51')](handleError(_0x20fe77,null));};exports[_0x2354('0x54')]=function(_0x331a90,_0xf4d690){return db[_0x2354('0x3d')][_0x2354('0x54')](_0x331a90[_0x2354('0x55')],{})[_0x2354('0x2b')](function(_0x4d9edd){var _0x2504e8=_0x331a90[_0x2354('0x56')]['get']({'plain':!![]});if(!_0x2504e8)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x2504e8['role']===_0x2354('0x56')){var _0x598cdc=_0x4d9edd[_0x2354('0x2d')]({'plain':!![]});var _0x25ff42=[{'name':_0x2354('0x2e'),'value':_0x2354('0x2f')},{'name':_0x2354('0x30'),'value':_0x2354('0x31')}];var _0x7d9050=_['find'](_0x25ff42,[_0x2354('0x34'),_0x598cdc[_0x2354('0x35')]])['name'];return db[_0x2354('0x57')]['find']({'where':{'name':_0x7d9050,'userProfileId':_0x2504e8[_0x2354('0x58')]},'raw':!![]})[_0x2354('0x2b')](function(_0x1b6c13){if(_0x1b6c13&&_0x1b6c13[_0x2354('0x59')]===0x0){return db[_0x2354('0x5a')]['create']({'name':_0x598cdc[_0x2354('0x39')],'resourceId':_0x598cdc['id'],'type':_0x1b6c13[_0x2354('0x39')],'sectionId':_0x1b6c13['id']},{})[_0x2354('0x2b')](function(){return _0x4d9edd;});}else{return _0x4d9edd;}})['catch'](function(_0x35dcee){logger[_0x2354('0x37')](_0x2354('0x5b'),_0x35dcee);throw _0x35dcee;});}return _0x4d9edd;})['then'](respondWithResult(_0xf4d690,0xc9))['catch'](handleError(_0xf4d690,null));};exports[_0x2354('0x5c')]=function(_0x48f9d2,_0x18fd2f){var _0x37524d={'where':{'id':_0x48f9d2[_0x2354('0x53')]['id']}},_0x3a77aa={};_0x3a77aa['model']=_[_0x2354('0x41')](db['VoiceQueue'][_0x2354('0x3e')]);_0x37524d['attributes']=_[_0x2354('0x42')](_0x3a77aa[_0x2354('0x43')],qs[_0x2354('0x45')](_0x48f9d2['query'][_0x2354('0x45')]));_0x37524d[_0x2354('0x44')]=_0x37524d[_0x2354('0x44')]['length']?_0x37524d[_0x2354('0x44')]:_0x3a77aa[_0x2354('0x43')];if(_0x48f9d2[_0x2354('0x46')][_0x2354('0x4f')]){_0x37524d[_0x2354('0x50')]=[{'all':!![]}];}_0x37524d=_[_0x2354('0x4c')]({},_0x37524d,_0x48f9d2['options']);return db[_0x2354('0x3d')][_0x2354('0x36')](_0x37524d)[_0x2354('0x2b')](handleEntityNotFound(_0x18fd2f,null))['then'](function(_0x474488){if(_0x474488){var _0x3fd349=_0x474488[_0x2354('0x2d')]({'plain':!![]});_0x3fd349=qs[_0x2354('0x5d')](_0x3fd349,['id',_0x2354('0x5e'),_0x2354('0x5f')]);_0x48f9d2['body']=_[_0x2354('0x5d')](_0x48f9d2[_0x2354('0x55')],['id',_0x2354('0x5e'),_0x2354('0x5f')]);return db[_0x2354('0x3d')]['create'](_['merge'](_0x3fd349,_0x48f9d2[_0x2354('0x55')]),{'include':_0x48f9d2['query'][_0x2354('0x4f')]?[{'all':!![]}]:undefined})['then'](function(_0xc24cc8){var _0x289b3b=_0x48f9d2[_0x2354('0x56')][_0x2354('0x2d')]({'plain':!![]});if(!_0x289b3b)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x289b3b[_0x2354('0x60')]===_0x2354('0x56')){var _0x4a51fa=_0xc24cc8[_0x2354('0x2d')]({'plain':!![]});var _0x171cd7=[{'name':'VoiceQueues','value':_0x2354('0x2f')},{'name':_0x2354('0x30'),'value':_0x2354('0x31')}];var _0x14272b=_['find'](_0x171cd7,['value',_0x4a51fa[_0x2354('0x35')]])[_0x2354('0x39')];return db[_0x2354('0x57')][_0x2354('0x36')]({'where':{'name':_0x14272b,'userProfileId':_0x289b3b[_0x2354('0x58')]},'raw':!![]})[_0x2354('0x2b')](function(_0x15ee9e){if(_0x15ee9e&&_0x15ee9e['autoAssociation']===0x0){return db[_0x2354('0x5a')][_0x2354('0x54')]({'name':_0x4a51fa[_0x2354('0x39')],'resourceId':_0x4a51fa['id'],'type':_0x15ee9e['name'],'sectionId':_0x15ee9e['id']},{})[_0x2354('0x2b')](function(){return _0xc24cc8;});}else{return _0xc24cc8;}})[_0x2354('0x51')](function(_0x850e36){logger[_0x2354('0x37')](_0x2354('0x5b'),_0x850e36);throw _0x850e36;});}return _0xc24cc8;});}})['then'](respondWithResult(_0x18fd2f,0xc9))[_0x2354('0x51')](handleError(_0x18fd2f,null));};exports[_0x2354('0x2a')]=function(_0x458b42,_0x34eca1){if(_0x458b42[_0x2354('0x55')]['id']){delete _0x458b42['body']['id'];}return db[_0x2354('0x3d')][_0x2354('0x36')]({'where':{'id':_0x458b42['params']['id']}})[_0x2354('0x2b')](handleEntityNotFound(_0x34eca1,null))[_0x2354('0x2b')](saveUpdates(_0x458b42['body'],null))['then'](respondWithResult(_0x34eca1,null))['catch'](handleError(_0x34eca1,null));};exports[_0x2354('0x2c')]=function(_0x581151,_0x1b46c7){return db[_0x2354('0x3d')][_0x2354('0x36')]({'where':{'id':_0x581151[_0x2354('0x53')]['id']}})['then'](handleEntityNotFound(_0x1b46c7,null))['then'](removeEntity(_0x1b46c7,null))[_0x2354('0x51')](handleError(_0x1b46c7,null));};exports[_0x2354('0x61')]=function(_0x576bda,_0x347117,_0x416eae){var _0x17d1e3={'raw':![],'where':{}};var _0x435e69={};var _0x1a8a29={'count':0x0,'rows':[]};return db[_0x2354('0x3d')][_0x2354('0x62')]({'where':{'id':_0x576bda['params']['id']}})[_0x2354('0x2b')](handleEntityNotFound(_0x347117,null))[_0x2354('0x2b')](function(_0x2c90e4){if(_0x2c90e4){_0x435e69[_0x2354('0x43')]=_[_0x2354('0x41')](db['CmHopper'][_0x2354('0x3e')]);_0x435e69[_0x2354('0x46')]=_[_0x2354('0x41')](_0x576bda[_0x2354('0x46')]);_0x435e69[_0x2354('0x4b')]=_[_0x2354('0x42')](_0x435e69['model'],_0x435e69[_0x2354('0x46')]);_0x17d1e3[_0x2354('0x44')]=_[_0x2354('0x42')](_0x435e69[_0x2354('0x43')],qs['fields'](_0x576bda['query'][_0x2354('0x45')]));_0x17d1e3['attributes']=_0x17d1e3[_0x2354('0x44')]['length']?_0x17d1e3[_0x2354('0x44')]:_0x435e69[_0x2354('0x43')];if(!_0x576bda[_0x2354('0x46')][_0x2354('0x47')]('nolimit')){_0x17d1e3['limit']=qs[_0x2354('0x24')](_0x576bda['query']['limit']);_0x17d1e3[_0x2354('0x23')]=qs['offset'](_0x576bda[_0x2354('0x46')][_0x2354('0x23')]);}_0x17d1e3[_0x2354('0x49')]=qs[_0x2354('0x4a')](_0x576bda[_0x2354('0x46')][_0x2354('0x4a')]);_0x17d1e3[_0x2354('0x4e')]=qs[_0x2354('0x4b')](_[_0x2354('0x63')](_0x576bda[_0x2354('0x46')],_0x435e69[_0x2354('0x4b')]));_0x17d1e3[_0x2354('0x4e')]['VoiceQueueId']=_0x2c90e4['id'];if(_0x576bda[_0x2354('0x46')][_0x2354('0x32')]){_0x17d1e3['where']=_[_0x2354('0x4c')](_0x17d1e3['where'],{'$or':_[_0x2354('0x3c')](_0x17d1e3[_0x2354('0x44')],function(_0x153018){var _0x5e25b3={};_0x5e25b3[_0x153018]={'$like':'%'+_0x576bda[_0x2354('0x46')][_0x2354('0x32')]+'%'};return _0x5e25b3;})});}_0x17d1e3=_['merge']({},_0x17d1e3,_0x576bda['options']);return db[_0x2354('0x64')][_0x2354('0x22')]({'where':_0x17d1e3[_0x2354('0x4e')]})[_0x2354('0x2b')](function(_0x38b83a){_0x1a8a29[_0x2354('0x22')]=_0x38b83a;if(_0x576bda[_0x2354('0x46')][_0x2354('0x4f')]){_0x17d1e3[_0x2354('0x50')]=[{'all':!![]}];}return db['CmHopper'][_0x2354('0x65')](_0x17d1e3);})[_0x2354('0x2b')](function(_0x379099){_0x1a8a29[_0x2354('0x66')]=_0x379099;return _0x1a8a29;});}})[_0x2354('0x2b')](respondWithFilteredResult(_0x347117,_0x17d1e3))[_0x2354('0x51')](handleError(_0x347117,null));};exports[_0x2354('0x67')]=function(_0x5b10d9,_0x2d80ce,_0x403864){var _0x4ed09a={'raw':!![],'where':{}};var _0x483f89={};var _0x3b0115={'count':0x0,'rows':[]};return db[_0x2354('0x3d')]['findOne']({'where':{'id':_0x5b10d9['params']['id']}})[_0x2354('0x2b')](handleEntityNotFound(_0x2d80ce,null))[_0x2354('0x2b')](function(_0x50f85f){if(_0x50f85f){_0x483f89[_0x2354('0x43')]=_[_0x2354('0x41')](db[_0x2354('0x68')][_0x2354('0x3e')]);_0x483f89[_0x2354('0x46')]=_[_0x2354('0x41')](_0x5b10d9[_0x2354('0x46')]);_0x483f89[_0x2354('0x4b')]=_['intersection'](_0x483f89[_0x2354('0x43')],_0x483f89['query']);_0x4ed09a[_0x2354('0x44')]=_[_0x2354('0x42')](_0x483f89[_0x2354('0x43')],qs[_0x2354('0x45')](_0x5b10d9[_0x2354('0x46')][_0x2354('0x45')]));_0x4ed09a['attributes']=_0x4ed09a['attributes'][_0x2354('0x69')]?_0x4ed09a[_0x2354('0x44')]:_0x483f89['model'];if(!_0x5b10d9[_0x2354('0x46')]['hasOwnProperty'](_0x2354('0x48'))){_0x4ed09a[_0x2354('0x24')]=qs[_0x2354('0x24')](_0x5b10d9[_0x2354('0x46')][_0x2354('0x24')]);_0x4ed09a[_0x2354('0x23')]=qs[_0x2354('0x23')](_0x5b10d9[_0x2354('0x46')][_0x2354('0x23')]);}_0x4ed09a[_0x2354('0x49')]=qs[_0x2354('0x4a')](_0x5b10d9['query'][_0x2354('0x4a')]);_0x4ed09a[_0x2354('0x4e')]=qs[_0x2354('0x4b')](_[_0x2354('0x63')](_0x5b10d9[_0x2354('0x46')],_0x483f89['filters']));_0x4ed09a[_0x2354('0x4e')][_0x2354('0x6a')]=_0x50f85f['id'];if(_0x5b10d9[_0x2354('0x46')][_0x2354('0x32')]){_0x4ed09a[_0x2354('0x4e')]=_[_0x2354('0x4c')](_0x4ed09a[_0x2354('0x4e')],{'$or':_['map'](_0x4ed09a[_0x2354('0x44')],function(_0xc8bc6b){var _0x5680de={};_0x5680de[_0xc8bc6b]={'$like':'%'+_0x5b10d9[_0x2354('0x46')]['filter']+'%'};return _0x5680de;})});}_0x4ed09a=_[_0x2354('0x4c')]({},_0x4ed09a,_0x5b10d9[_0x2354('0x4d')]);return db[_0x2354('0x68')][_0x2354('0x22')]({'where':_0x4ed09a[_0x2354('0x4e')]})[_0x2354('0x2b')](function(_0x5f1f74){_0x3b0115[_0x2354('0x22')]=_0x5f1f74;if(_0x5b10d9[_0x2354('0x46')][_0x2354('0x4f')]){_0x4ed09a['include']=[{'all':!![]}];}return db['CmHopperHistory'][_0x2354('0x65')](_0x4ed09a);})[_0x2354('0x2b')](function(_0x4ef83b){_0x3b0115['rows']=_0x4ef83b;return _0x3b0115;});}})[_0x2354('0x2b')](respondWithFilteredResult(_0x2d80ce,_0x4ed09a))[_0x2354('0x51')](handleError(_0x2d80ce,null));};exports[_0x2354('0x6b')]=function(_0x2f6672,_0x1e2dc8,_0x2c9a04){var _0x5708bd={'raw':!![],'where':{}};var _0x555752={};var _0x1d7bc1={'count':0x0,'rows':[]};return db[_0x2354('0x3d')][_0x2354('0x62')]({'where':{'id':_0x2f6672[_0x2354('0x53')]['id']}})['then'](handleEntityNotFound(_0x1e2dc8,null))['then'](function(_0x357c9b){if(_0x357c9b){_0x555752['model']=_['keys'](db[_0x2354('0x6c')][_0x2354('0x3e')]);_0x555752[_0x2354('0x46')]=_['keys'](_0x2f6672[_0x2354('0x46')]);_0x555752['filters']=_[_0x2354('0x42')](_0x555752['model'],_0x555752[_0x2354('0x46')]);_0x5708bd[_0x2354('0x44')]=_[_0x2354('0x42')](_0x555752[_0x2354('0x43')],qs['fields'](_0x2f6672['query'][_0x2354('0x45')]));_0x5708bd[_0x2354('0x44')]=_0x5708bd[_0x2354('0x44')][_0x2354('0x69')]?_0x5708bd[_0x2354('0x44')]:_0x555752['model'];if(!_0x2f6672[_0x2354('0x46')][_0x2354('0x47')](_0x2354('0x48'))){_0x5708bd[_0x2354('0x24')]=qs[_0x2354('0x24')](_0x2f6672[_0x2354('0x46')]['limit']);_0x5708bd['offset']=qs['offset'](_0x2f6672[_0x2354('0x46')][_0x2354('0x23')]);}_0x5708bd[_0x2354('0x49')]=qs[_0x2354('0x4a')](_0x2f6672['query'][_0x2354('0x4a')]);_0x5708bd[_0x2354('0x4e')]=qs[_0x2354('0x4b')](_[_0x2354('0x63')](_0x2f6672['query'],_0x555752[_0x2354('0x4b')]));_0x5708bd[_0x2354('0x4e')]['VoiceQueueId']=_0x357c9b['id'];if(_0x2f6672[_0x2354('0x46')][_0x2354('0x32')]){_0x5708bd[_0x2354('0x4e')]=_[_0x2354('0x4c')](_0x5708bd[_0x2354('0x4e')],{'$or':_['map'](_0x5708bd['attributes'],function(_0x5c17ef){var _0x47be98={};_0x47be98[_0x5c17ef]={'$like':'%'+_0x2f6672['query'][_0x2354('0x32')]+'%'};return _0x47be98;})});}_0x5708bd=_['merge']({},_0x5708bd,_0x2f6672[_0x2354('0x4d')]);return db['CmHopperFinal'][_0x2354('0x22')]({'where':_0x5708bd['where']})[_0x2354('0x2b')](function(_0x1e49c1){_0x1d7bc1[_0x2354('0x22')]=_0x1e49c1;if(_0x2f6672[_0x2354('0x46')][_0x2354('0x4f')]){_0x5708bd['include']=[{'all':!![]}];}return db[_0x2354('0x6c')][_0x2354('0x65')](_0x5708bd);})[_0x2354('0x2b')](function(_0x3206d0){_0x1d7bc1['rows']=_0x3206d0;return _0x1d7bc1;});}})[_0x2354('0x2b')](respondWithFilteredResult(_0x1e2dc8,_0x5708bd))[_0x2354('0x51')](handleError(_0x1e2dc8,null));};exports['getHopperBlacks']=function(_0x4b8eb0,_0x438395,_0x187bd2){var _0x41bf1b={'raw':!![],'where':{}};var _0x576ec8={};var _0x36c692={'count':0x0,'rows':[]};return db['VoiceQueue']['findOne']({'where':{'id':_0x4b8eb0[_0x2354('0x53')]['id']}})[_0x2354('0x2b')](handleEntityNotFound(_0x438395,null))[_0x2354('0x2b')](function(_0x546041){if(_0x546041){_0x576ec8[_0x2354('0x43')]=_['keys'](db[_0x2354('0x6d')]['rawAttributes']);_0x576ec8['query']=_[_0x2354('0x41')](_0x4b8eb0['query']);_0x576ec8[_0x2354('0x4b')]=_[_0x2354('0x42')](_0x576ec8['model'],_0x576ec8[_0x2354('0x46')]);_0x41bf1b[_0x2354('0x44')]=_[_0x2354('0x42')](_0x576ec8['model'],qs[_0x2354('0x45')](_0x4b8eb0['query'][_0x2354('0x45')]));_0x41bf1b[_0x2354('0x44')]=_0x41bf1b[_0x2354('0x44')][_0x2354('0x69')]?_0x41bf1b[_0x2354('0x44')]:_0x576ec8[_0x2354('0x43')];if(!_0x4b8eb0[_0x2354('0x46')][_0x2354('0x47')](_0x2354('0x48'))){_0x41bf1b[_0x2354('0x24')]=qs[_0x2354('0x24')](_0x4b8eb0[_0x2354('0x46')][_0x2354('0x24')]);_0x41bf1b[_0x2354('0x23')]=qs[_0x2354('0x23')](_0x4b8eb0['query']['offset']);}_0x41bf1b[_0x2354('0x49')]=qs[_0x2354('0x4a')](_0x4b8eb0[_0x2354('0x46')][_0x2354('0x4a')]);_0x41bf1b[_0x2354('0x4e')]=qs[_0x2354('0x4b')](_[_0x2354('0x63')](_0x4b8eb0['query'],_0x576ec8['filters']));_0x41bf1b[_0x2354('0x4e')][_0x2354('0x6a')]=_0x546041['id'];if(_0x4b8eb0[_0x2354('0x46')][_0x2354('0x32')]){_0x41bf1b[_0x2354('0x4e')]=_[_0x2354('0x4c')](_0x41bf1b[_0x2354('0x4e')],{'$or':_['map'](_0x41bf1b[_0x2354('0x44')],function(_0x2e121f){var _0x377527={};_0x377527[_0x2e121f]={'$like':'%'+_0x4b8eb0[_0x2354('0x46')][_0x2354('0x32')]+'%'};return _0x377527;})});}_0x41bf1b=_['merge']({},_0x41bf1b,_0x4b8eb0[_0x2354('0x4d')]);return db[_0x2354('0x6d')][_0x2354('0x22')]({'where':_0x41bf1b['where']})[_0x2354('0x2b')](function(_0x3a3090){_0x36c692[_0x2354('0x22')]=_0x3a3090;if(_0x4b8eb0['query'][_0x2354('0x4f')]){_0x41bf1b[_0x2354('0x50')]=[{'all':!![]}];}return db[_0x2354('0x6d')]['findAll'](_0x41bf1b);})[_0x2354('0x2b')](function(_0x2e5a8f){_0x36c692['rows']=_0x2e5a8f;return _0x36c692;});}})[_0x2354('0x2b')](respondWithFilteredResult(_0x438395,_0x41bf1b))[_0x2354('0x51')](handleError(_0x438395,null));};exports[_0x2354('0x6e')]=function(_0x4fda61,_0x165b6d,_0x3ad27a){var _0x1103de={};var _0x431a73={};var _0x2b5c3b;var _0x21b6e8;return db[_0x2354('0x3d')][_0x2354('0x62')]({'where':{'id':_0x4fda61['params']['id']}})[_0x2354('0x2b')](handleEntityNotFound(_0x165b6d,null))[_0x2354('0x2b')](function(_0x4097de){if(_0x4097de){_0x2b5c3b=_0x4097de;_0x431a73[_0x2354('0x43')]=_['keys'](db[_0x2354('0x6f')]['rawAttributes']);_0x431a73[_0x2354('0x46')]=_[_0x2354('0x41')](_0x4fda61['query']);_0x431a73[_0x2354('0x4b')]=_[_0x2354('0x42')](_0x431a73['model'],_0x431a73[_0x2354('0x46')]);_0x1103de[_0x2354('0x44')]=_[_0x2354('0x42')](_0x431a73['model'],qs[_0x2354('0x45')](_0x4fda61['query']['fields']));_0x1103de[_0x2354('0x44')]=_0x1103de[_0x2354('0x44')][_0x2354('0x69')]?_0x1103de[_0x2354('0x44')]:_0x431a73[_0x2354('0x43')];_0x1103de[_0x2354('0x49')]=qs[_0x2354('0x4a')](_0x4fda61[_0x2354('0x46')][_0x2354('0x4a')]);_0x1103de[_0x2354('0x4e')]=qs[_0x2354('0x4b')](_['pick'](_0x4fda61[_0x2354('0x46')],_0x431a73[_0x2354('0x4b')]));if(_0x4fda61[_0x2354('0x46')][_0x2354('0x32')]){_0x1103de[_0x2354('0x4e')]=_[_0x2354('0x4c')](_0x1103de[_0x2354('0x4e')],{'$or':_[_0x2354('0x3c')](_0x1103de['attributes'],function(_0x5ce5a1){var _0x4b1381={};_0x4b1381[_0x5ce5a1]={'$like':'%'+_0x4fda61[_0x2354('0x46')]['filter']+'%'};return _0x4b1381;})});}_0x1103de=_[_0x2354('0x4c')]({},_0x1103de,_0x4fda61['options']);return _0x2b5c3b[_0x2354('0x6e')](_0x1103de);}})[_0x2354('0x2b')](function(_0x2b34e5){if(_0x2b34e5){_0x21b6e8=_0x2b34e5[_0x2354('0x69')];if(!_0x4fda61[_0x2354('0x46')][_0x2354('0x47')](_0x2354('0x48'))){_0x1103de['limit']=qs['limit'](_0x4fda61['query'][_0x2354('0x24')]);_0x1103de[_0x2354('0x23')]=qs['offset'](_0x4fda61[_0x2354('0x46')][_0x2354('0x23')]);}return _0x2b5c3b[_0x2354('0x6e')](_0x1103de);}})[_0x2354('0x2b')](function(_0x2e0f86){if(_0x2e0f86){return _0x2e0f86?{'count':_0x21b6e8,'rows':_0x2e0f86}:null;}})[_0x2354('0x2b')](respondWithResult(_0x165b6d,null))[_0x2354('0x51')](handleError(_0x165b6d,null));};exports[_0x2354('0x70')]=function(_0x269784,_0x4f08a6,_0x14721b){var _0x18963f=_0x269784[_0x2354('0x55')][_0x2354('0x71')];var _0x1e12a8=_[_0x2354('0x3c')](_0x18963f,'id');return db['Team']['findAll']({'where':{'id':_0x1e12a8},'attributes':['id'],'include':[{'model':db['User'],'as':'Agents','attributes':['id',_0x2354('0x39'),'online',_0x2354('0x72'),_0x2354('0x73')],'raw':!![]}]})['then'](function(_0x26fa64){if(_0x26fa64){var _0x3093eb=_[_0x2354('0x74')](_0x26fa64,function(_0x6f1c70){var _0x85f5fb=_0x6f1c70['get']({'plain':!![]});_0x85f5fb[_0x2354('0x75')][_0x2354('0x76')](function(_0x108391){_0x108391['penalty']=_[_0x2354('0x36')](_0x18963f,{'id':_0x85f5fb['id']})[_0x2354('0x77')];});return _0x85f5fb[_0x2354('0x75')];});return db[_0x2354('0x3d')][_0x2354('0x36')]({'where':{'id':_0x269784['params']['id']}})[_0x2354('0x2b')](function(_0x36e41f){return db['sequelize'][_0x2354('0x78')](function(_0x47db58){return _0x36e41f[_0x2354('0x70')](_0x1e12a8,{'transaction':_0x47db58})[_0x2354('0x2b')](function(){return BPromise[_0x2354('0x79')](_0x18963f,function(_0x3dcccb){return db[_0x2354('0x7a')][_0x2354('0x7b')]({'TeamId':_0x3dcccb['id'],'VoiceQueueId':_0x269784['params']['id'],'penalty':_0x3dcccb[_0x2354('0x77')]},{'transaction':_0x47db58});});})[_0x2354('0x2b')](function(){return BPromise[_0x2354('0x79')](_0x3093eb,function(_0x484d7c){return db[_0x2354('0x7c')][_0x2354('0x7d')]({'where':{'UserId':_0x484d7c['id'],'VoiceQueueId':_0x269784[_0x2354('0x53')]['id']},'defaults':{'penalty':_0x484d7c['penalty']},'transaction':_0x47db58});});})['then'](function(){return BPromise[_0x2354('0x79')](_['filter'](_0x3093eb,{'online':!![]}),function(_0x48926f){return db[_0x2354('0x7e')][_0x2354('0x7b')]({'membername':_0x48926f[_0x2354('0x39')],'UserId':_0x48926f['id'],'queue_name':_0x36e41f['name'],'VoiceQueueId':_0x36e41f['id'],'interface':_['isNil'](_0x48926f[_0x2354('0x73')])?util[_0x2354('0x7f')](_0x2354('0x80'),_0x48926f['name']):_0x48926f[_0x2354('0x73')],'paused':_0x48926f[_0x2354('0x72')]||![],'penalty':_0x48926f[_0x2354('0x77')]},{'transaction':_0x47db58});});})[_0x2354('0x2b')](function(){_0x3093eb[_0x2354('0x76')](function(_0x4c1265){socket[_0x2354('0x81')](_0x2354('0x82'),{'UserId':_0x4c1265['id'],'VoiceQueueId':_0x36e41f['id']});});});});});}})[_0x2354('0x2b')](respondWithStatusCode(_0x4f08a6,null))[_0x2354('0x51')](handleError(_0x4f08a6,null));};exports[_0x2354('0x83')]=function(_0x4b960f,_0x2c51c5,_0x23d13d){return db[_0x2354('0x6f')][_0x2354('0x65')]({'where':{'id':_0x4b960f['query']['ids']},'attributes':['id'],'include':[{'model':db['User'],'as':'Agents','attributes':['id'],'raw':!![]}]})[_0x2354('0x2b')](handleEntityNotFound(_0x2c51c5,null))[_0x2354('0x2b')](function(_0x23dd16){var _0x101ca5=_[_0x2354('0x3c')](_0x23dd16,'id');var _0x76bb92=[];var _0x20aa59=[];var _0x45e853=squel[_0x2354('0x84')]();_0x45e853[_0x2354('0x85')](_0x2354('0x86'))[_0x2354('0x87')](_0x2354('0x88'),'tq')[_0x2354('0x89')](_0x2354('0x8a'),'ut',_0x2354('0x8b'))['where']('VoiceQueueId\x20=\x20?',_0x4b960f[_0x2354('0x53')]['id']);for(var _0x335c8a=0x0;_0x335c8a<_0x23dd16[_0x2354('0x69')];_0x335c8a+=0x1){let _0xf19925=_0x23dd16[_0x335c8a];for(var _0x522ab1=0x0;_0x522ab1<_0xf19925[_0x2354('0x75')][_0x2354('0x69')];_0x522ab1+=0x1){let _0x5d24ce=_0xf19925[_0x2354('0x75')][_0x522ab1];var _0x46302b=_0x45e853['clone']();_0x46302b[_0x2354('0x4e')]('ut.UserId\x20=\x20?',_0x5d24ce['id']);_0x20aa59['push'](db[_0x2354('0x8c')]['query'](_0x46302b[_0x2354('0x8d')](),{'type':db[_0x2354('0x8c')][_0x2354('0x8e')][_0x2354('0x8f')]})[_0x2354('0x2b')](function(_0x27eff4){if(_0x27eff4[_0x2354('0x69')]===0x1){return _0x5d24ce['id'];}else{var _0x31dfa7=_[_0x2354('0x90')](_[_0x2354('0x3c')](_0x27eff4,'TeamId'),function(_0xca8797){return _[_0x2354('0x91')](_0x101ca5,_0xca8797);});if(_0x31dfa7){return _0x5d24ce['id'];}}}));}}return BPromise['all'](_0x20aa59)[_0x2354('0x2b')](function(_0x1d9952){_0x76bb92=_(_0x76bb92)[_0x2354('0x92')](_0x1d9952)[_0x2354('0x93')]()[_0x2354('0x34')]();return db[_0x2354('0x3d')][_0x2354('0x36')]({'where':{'id':_0x4b960f[_0x2354('0x53')]['id']}})[_0x2354('0x2b')](function(_0x2a70f0){return db['sequelize'][_0x2354('0x78')](function(_0x184a37){return _0x2a70f0['removeTeams'](_0x4b960f[_0x2354('0x46')][_0x2354('0x94')],{'transaction':_0x184a37})[_0x2354('0x2b')](function(){if(!_['isEmpty'](_0x76bb92)){return _0x2a70f0['removeAgents'](_0x76bb92,{'transaction':_0x184a37})[_0x2354('0x2b')](function(){return db[_0x2354('0x7e')][_0x2354('0x2c')]({'where':{'VoiceQueueId':_0x4b960f[_0x2354('0x53')]['id'],'UserId':_0x76bb92},'transaction':_0x184a37});});}})[_0x2354('0x2b')](function(){_0x76bb92[_0x2354('0x76')](function(_0x4f062c){socket['emit'](_0x2354('0x95'),{'UserId':_0x4f062c,'VoiceQueueId':_0x2a70f0['id']});});});});});});})[_0x2354('0x2b')](respondWithStatusCode(_0x2c51c5,null))[_0x2354('0x51')](handleError(_0x2c51c5,null));};exports['addAgents']=function(_0x2de06b,_0xf6cc0b,_0x2d2b87){var _0x1b0158,_0x15a6c2;return db[_0x2354('0x3d')][_0x2354('0x36')]({'where':{'id':_0x2de06b[_0x2354('0x53')]['id']}})[_0x2354('0x2b')](handleEntityNotFound(_0xf6cc0b,null))[_0x2354('0x2b')](function(_0x2a9573){if(_0x2a9573){_0x15a6c2=_0x2a9573;return _0x2a9573[_0x2354('0x96')](_0x2de06b['body'][_0x2354('0x94')],_['omit'](_0x2de06b['body'],['ids','id'])||{})[_0x2354('0x97')](function(_0x381751){for(var _0x2edaa4=0x0;_0x2edaa4<_0x2de06b[_0x2354('0x55')][_0x2354('0x94')]['length'];_0x2edaa4+=0x1){socket['emit'](_0x2354('0x82'),{'UserId':Number(_0x2de06b[_0x2354('0x55')][_0x2354('0x94')][_0x2edaa4]),'VoiceQueueId':Number(_0x2de06b[_0x2354('0x53')]['id'])});}return _0x381751;});}})['then'](function(_0x39e82c){_0x1b0158=_0x39e82c||[];if(_0x15a6c2){return db['User'][_0x2354('0x65')]({'where':{'id':_0x2de06b[_0x2354('0x55')][_0x2354('0x94')]},'attributes':['id',_0x2354('0x39'),'online','voicePause',_0x2354('0x73')],'raw':!![]});}})[_0x2354('0x2b')](function(_0x3b6b28){if(!_[_0x2354('0x98')](_0x3b6b28)){var _0x1ecea9=[];for(var _0xce5317=0x0;_0xce5317<_0x3b6b28[_0x2354('0x69')];_0xce5317++){if(_0x3b6b28[_0xce5317][_0x2354('0x99')]){_0x1ecea9['push'](db[_0x2354('0x7e')][_0x2354('0x7b')]({'membername':_0x3b6b28[_0xce5317]['name'],'UserId':_0x3b6b28[_0xce5317]['id'],'queue_name':_0x15a6c2[_0x2354('0x39')],'VoiceQueueId':_0x15a6c2['id'],'interface':_[_0x2354('0x9a')](_0x3b6b28[_0xce5317][_0x2354('0x73')])?util[_0x2354('0x7f')](_0x2354('0x80'),_0x3b6b28[_0xce5317][_0x2354('0x39')]):_0x3b6b28[_0xce5317][_0x2354('0x73')],'paused':_0x3b6b28[_0xce5317][_0x2354('0x72')]||![],'penalty':_0x2de06b[_0x2354('0x55')][_0x2354('0x77')]||0x0}));}}return BPromise[_0x2354('0x9b')](_0x1ecea9);}})[_0x2354('0x2b')](function(){return _0x1b0158;})[_0x2354('0x2b')](respondWithResult(_0xf6cc0b,null))[_0x2354('0x51')](handleError(_0xf6cc0b,null));};exports['removeAgents']=function(_0x5bbeb2,_0x52eb3a,_0x3a3e3f){return db[_0x2354('0x3d')][_0x2354('0x36')]({'where':{'id':_0x5bbeb2['params']['id']}})[_0x2354('0x2b')](handleEntityNotFound(_0x52eb3a,null))['then'](function(_0x524362){if(_0x524362){return _0x524362[_0x2354('0x9c')](_0x5bbeb2[_0x2354('0x46')]['ids'])['then'](function(){if(_[_0x2354('0x9d')](_0x5bbeb2[_0x2354('0x46')]['ids'])){for(var _0x1019ff=0x0;_0x1019ff<_0x5bbeb2['query'][_0x2354('0x94')]['length'];_0x1019ff+=0x1){socket['emit']('userVoiceQueue:remove',{'UserId':Number(_0x5bbeb2[_0x2354('0x46')][_0x2354('0x94')][_0x1019ff]),'VoiceQueueId':Number(_0x5bbeb2[_0x2354('0x53')]['id'])});}}else{socket[_0x2354('0x81')](_0x2354('0x95'),{'UserId':Number(_0x5bbeb2['query'][_0x2354('0x94')]),'VoiceQueueId':Number(_0x5bbeb2[_0x2354('0x53')]['id'])});}});}})['then'](function(_0x4b3459){return db[_0x2354('0x7e')][_0x2354('0x2c')]({'where':{'VoiceQueueId':_0x5bbeb2['params']['id'],'UserId':_0x5bbeb2[_0x2354('0x46')][_0x2354('0x94')]}})['then'](function(){return _0x4b3459;});})[_0x2354('0x2b')](respondWithStatusCode(_0x52eb3a,null))[_0x2354('0x51')](handleError(_0x52eb3a,null));};exports['getAgents']=function(_0x225454,_0x59047c,_0x1e77bf){var _0x479cd6={};var _0x1c9bfa={};var _0x5ff88a;var _0x5db209;return db[_0x2354('0x3d')][_0x2354('0x62')]({'where':{'id':_0x225454['params']['id']}})[_0x2354('0x2b')](handleEntityNotFound(_0x59047c,null))['then'](function(_0x245cd5){if(_0x245cd5){_0x5ff88a=_0x245cd5;_0x1c9bfa[_0x2354('0x43')]=_[_0x2354('0x41')](db[_0x2354('0x9e')][_0x2354('0x3e')]);_0x1c9bfa['query']=_['keys'](_0x225454['query']);_0x1c9bfa[_0x2354('0x4b')]=_[_0x2354('0x42')](_0x1c9bfa[_0x2354('0x43')],_0x1c9bfa[_0x2354('0x46')]);_0x479cd6[_0x2354('0x44')]=_[_0x2354('0x42')](_0x1c9bfa[_0x2354('0x43')],qs[_0x2354('0x45')](_0x225454[_0x2354('0x46')][_0x2354('0x45')]));_0x479cd6[_0x2354('0x44')]=_0x479cd6[_0x2354('0x44')][_0x2354('0x69')]?_0x479cd6['attributes']:_0x1c9bfa[_0x2354('0x43')];_0x479cd6['order']=qs[_0x2354('0x4a')](_0x225454['query'][_0x2354('0x4a')]);_0x479cd6[_0x2354('0x4e')]=qs[_0x2354('0x4b')](_['pick'](_0x225454[_0x2354('0x46')],_0x1c9bfa[_0x2354('0x4b')]));if(_0x225454[_0x2354('0x46')][_0x2354('0x32')]){_0x479cd6['where']=_[_0x2354('0x4c')](_0x479cd6[_0x2354('0x4e')],{'$or':_[_0x2354('0x3c')](_0x479cd6[_0x2354('0x44')],function(_0x386f24){var _0x5ebf74={};_0x5ebf74[_0x386f24]={'$like':'%'+_0x225454[_0x2354('0x46')][_0x2354('0x32')]+'%'};return _0x5ebf74;})});}_0x479cd6=_[_0x2354('0x4c')]({},_0x479cd6,_0x225454[_0x2354('0x4d')]);return _0x5ff88a[_0x2354('0x9f')](_0x479cd6);}})['then'](function(_0x2cd9e7){if(_0x2cd9e7){_0x5db209=_0x2cd9e7['length'];if(!_0x225454[_0x2354('0x46')][_0x2354('0x47')](_0x2354('0x48'))){_0x479cd6['limit']=qs['limit'](_0x225454[_0x2354('0x46')][_0x2354('0x24')]);_0x479cd6[_0x2354('0x23')]=qs['offset'](_0x225454[_0x2354('0x46')][_0x2354('0x23')]);}return _0x5ff88a[_0x2354('0x9f')](_0x479cd6);}})[_0x2354('0x2b')](function(_0x2152f7){if(_0x2152f7){return _0x2152f7?{'count':_0x5db209,'rows':_0x2152f7}:null;}})[_0x2354('0x2b')](respondWithResult(_0x59047c,null))[_0x2354('0x51')](handleError(_0x59047c,null));};exports['getMembers']=function(_0x420cb3,_0x19d8d7,_0x4654b6){var _0x454071={};var _0x3d82a4={};var _0x341567;var _0x3e70b5;return db[_0x2354('0x3d')][_0x2354('0x62')]({'where':{'id':_0x420cb3['params']['id']}})[_0x2354('0x2b')](handleEntityNotFound(_0x19d8d7,null))[_0x2354('0x2b')](function(_0xd2ead5){if(_0xd2ead5){_0x341567=_0xd2ead5;_0x3d82a4['model']=_[_0x2354('0x41')](db[_0x2354('0x7e')][_0x2354('0x3e')]);_0x3d82a4['query']=_[_0x2354('0x41')](_0x420cb3[_0x2354('0x46')]);_0x3d82a4['filters']=_[_0x2354('0x42')](_0x3d82a4[_0x2354('0x43')],_0x3d82a4['query']);_0x454071['attributes']=_[_0x2354('0x42')](_0x3d82a4['model'],qs[_0x2354('0x45')](_0x420cb3['query'][_0x2354('0x45')]));_0x454071[_0x2354('0x44')]=_0x454071[_0x2354('0x44')][_0x2354('0x69')]?_0x454071[_0x2354('0x44')]:_0x3d82a4['model'];_0x454071[_0x2354('0x49')]=qs[_0x2354('0x4a')](_0x420cb3[_0x2354('0x46')][_0x2354('0x4a')]);_0x454071[_0x2354('0x4e')]=qs[_0x2354('0x4b')](_[_0x2354('0x63')](_0x420cb3[_0x2354('0x46')],_0x3d82a4[_0x2354('0x4b')]));if(_0x420cb3[_0x2354('0x46')]['filter']){_0x454071[_0x2354('0x4e')]=_[_0x2354('0x4c')](_0x454071[_0x2354('0x4e')],{'$or':_[_0x2354('0x3c')](_0x454071[_0x2354('0x44')],function(_0x3ff7b5){var _0x4fb834={};_0x4fb834[_0x3ff7b5]={'$like':'%'+_0x420cb3['query']['filter']+'%'};return _0x4fb834;})});}_0x454071=_[_0x2354('0x4c')]({},_0x454071,_0x420cb3[_0x2354('0x4d')]);return _0x341567[_0x2354('0xa0')](_0x454071);}})['then'](function(_0x3c5867){if(_0x3c5867){_0x3e70b5=_0x3c5867[_0x2354('0x69')];if(!_0x420cb3['query'][_0x2354('0x47')](_0x2354('0x48'))){_0x454071[_0x2354('0x24')]=qs[_0x2354('0x24')](_0x420cb3['query'][_0x2354('0x24')]);_0x454071[_0x2354('0x23')]=qs['offset'](_0x420cb3[_0x2354('0x46')]['offset']);}return _0x341567['getMembers'](_0x454071);}})[_0x2354('0x2b')](function(_0x311e59){return _0x311e59?{'count':_0x3e70b5,'rows':_0x311e59}:null;})[_0x2354('0x2b')](respondWithResult(_0x19d8d7,null))[_0x2354('0x51')](handleError(_0x19d8d7,null));};exports[_0x2354('0xa1')]=function(_0x5e2c90,_0x2e18ff,_0x50678d){var _0x7aef2a={};var _0x4b23bf={};var _0x45f2c5;var _0xbe6a6f;return db[_0x2354('0x3d')][_0x2354('0x62')]({'where':{'id':_0x5e2c90[_0x2354('0x53')]['id']}})[_0x2354('0x2b')](handleEntityNotFound(_0x2e18ff,null))['then'](function(_0x1b1127){if(_0x1b1127){_0x45f2c5=_0x1b1127;_0x4b23bf[_0x2354('0x43')]=_['keys'](db['CmList']['rawAttributes']);_0x4b23bf['query']=_[_0x2354('0x41')](_0x5e2c90['query']);_0x4b23bf[_0x2354('0x4b')]=_[_0x2354('0x42')](_0x4b23bf[_0x2354('0x43')],_0x4b23bf[_0x2354('0x46')]);_0x7aef2a[_0x2354('0x44')]=_[_0x2354('0x42')](_0x4b23bf[_0x2354('0x43')],qs['fields'](_0x5e2c90['query']['fields']));_0x7aef2a[_0x2354('0x44')]=_0x7aef2a[_0x2354('0x44')][_0x2354('0x69')]?_0x7aef2a[_0x2354('0x44')]:_0x4b23bf[_0x2354('0x43')];_0x7aef2a[_0x2354('0x49')]=qs[_0x2354('0x4a')](_0x5e2c90[_0x2354('0x46')][_0x2354('0x4a')]);_0x7aef2a[_0x2354('0x4e')]=qs[_0x2354('0x4b')](_['pick'](_0x5e2c90[_0x2354('0x46')],_0x4b23bf['filters']));if(_0x5e2c90[_0x2354('0x46')][_0x2354('0x32')]){_0x7aef2a['where']=_[_0x2354('0x4c')](_0x7aef2a[_0x2354('0x4e')],{'$or':_[_0x2354('0x3c')](_0x7aef2a[_0x2354('0x44')],function(_0x4ea3b2){var _0x5daad8={};_0x5daad8[_0x4ea3b2]={'$like':'%'+_0x5e2c90[_0x2354('0x46')]['filter']+'%'};return _0x5daad8;})});}_0x7aef2a=_['merge']({},_0x7aef2a,_0x5e2c90[_0x2354('0x4d')]);return _0x45f2c5['getLists'](_0x7aef2a);}})[_0x2354('0x2b')](function(_0x183261){if(_0x183261){_0xbe6a6f=_0x183261[_0x2354('0x69')];if(!_0x5e2c90[_0x2354('0x46')][_0x2354('0x47')](_0x2354('0x48'))){_0x7aef2a[_0x2354('0x24')]=qs['limit'](_0x5e2c90[_0x2354('0x46')]['limit']);_0x7aef2a[_0x2354('0x23')]=qs[_0x2354('0x23')](_0x5e2c90[_0x2354('0x46')][_0x2354('0x23')]);}return _0x45f2c5['getLists'](_0x7aef2a);}})[_0x2354('0x2b')](function(_0x54a50c){if(_0x54a50c){return _0x54a50c?{'count':_0xbe6a6f,'rows':_0x54a50c}:null;}})[_0x2354('0x2b')](respondWithResult(_0x2e18ff,null))[_0x2354('0x51')](handleError(_0x2e18ff,null));};exports['addLists']=function(_0xaff739,_0x3f95a1,_0x56e842){var _0x3ac35c,_0xe078e9;return db[_0x2354('0x3d')]['find']({'where':{'id':_0xaff739[_0x2354('0x53')]['id']}})[_0x2354('0x2b')](handleEntityNotFound(_0x3f95a1,null))[_0x2354('0x2b')](function(_0x922875){if(_0x922875){_0xe078e9=_0x922875;return _0x922875[_0x2354('0xa2')](_0xaff739['body'][_0x2354('0x94')],_[_0x2354('0x5d')](_0xaff739[_0x2354('0x55')],[_0x2354('0x94'),'id'])||{});}return null;})[_0x2354('0x97')](function(_0x21f540){var _0x3f7d6d;_0x3ac35c=_0x21f540||[];var _0x75b24=[];if(_0x21f540){for(var _0x149809=0x0;_0x149809<_0x21f540[_0x2354('0x69')];_0x149809+=0x1){var _0x523ce0=_0x21f540[_0x149809][_0x2354('0x2d')]({'plain':!![]});_0xe078e9[_0x2354('0xa3')]=_0xaff739[_0x2354('0x55')][_0x2354('0xa3')]?_0xaff739[_0x2354('0x55')][_0x2354('0xa3')]:_0xe078e9[_0x2354('0xa3')];switch(_0xe078e9[_0x2354('0xa3')]){case _0x2354('0xa4'):_0x3f7d6d=squel[_0x2354('0xa5')]()[_0x2354('0xa6')](_0x2354('0xa7'))['fromQuery']([_0x2354('0xa8'),_0x2354('0xa9'),_0x2354('0xaa'),_0x2354('0xab'),_0x2354('0x6a'),_0x2354('0x5e'),_0x2354('0x5f')],squel[_0x2354('0x84')]()['field'](_0x2354('0xa8'),_0x2354('0xa8'))[_0x2354('0x85')]('NOW()','scheduledAt')[_0x2354('0x85')]('id',_0x2354('0xaa'))[_0x2354('0x85')](_0x523ce0[_0x2354('0xac')][_0x2354('0x8d')](),_0x2354('0xab'))[_0x2354('0x85')](_0xaff739[_0x2354('0x53')]['id']['toString'](),_0x2354('0x6a'))['field'](_0x2354('0xad'),_0x2354('0x5e'))[_0x2354('0x85')](_0x2354('0xad'),_0x2354('0x5f'))[_0x2354('0x87')](_0x2354('0xae'))[_0x2354('0x4e')]('deletedAt\x20IS\x20NULL')[_0x2354('0x4e')]('ListId\x20=\x20?',_0x523ce0[_0x2354('0xac')][_0x2354('0x8d')]())[_0x2354('0x4e')](_0x2354('0xaf'))['where'](_0x2354('0xb0'),squel[_0x2354('0x84')]()[_0x2354('0x85')](_0x2354('0xb1'))[_0x2354('0x87')](_0x2354('0xb2'))[_0x2354('0x4e')](_0x2354('0xb3'),_0xaff739['params']['id'][_0x2354('0x8d')]()))[_0x2354('0x4e')](_0x2354('0xb0'),squel[_0x2354('0x84')]()[_0x2354('0x85')](_0x2354('0xb4'))['from'](_0x2354('0xa7'))[_0x2354('0x4e')](_0x2354('0xb3'),_0xaff739[_0x2354('0x53')]['id'][_0x2354('0x8d')]())))[_0x2354('0x8d')]();break;case'onlyIfOpen':_0x3f7d6d=squel['insert']()['into']('cm_hopper')['fromQuery']([_0x2354('0xa8'),'scheduledAt',_0x2354('0xaa'),_0x2354('0xab'),_0x2354('0x6a'),_0x2354('0x5e'),_0x2354('0x5f')],squel[_0x2354('0x84')]()['field'](_0x2354('0xa8'),_0x2354('0xa8'))[_0x2354('0x85')](_0x2354('0xad'),_0x2354('0xa9'))['field']('id',_0x2354('0xaa'))[_0x2354('0x85')](_0x523ce0[_0x2354('0xac')][_0x2354('0x8d')](),_0x2354('0xab'))[_0x2354('0x85')](_0xaff739[_0x2354('0x53')]['id'][_0x2354('0x8d')](),_0x2354('0x6a'))['field'](_0x2354('0xad'),_0x2354('0x5e'))[_0x2354('0x85')](_0x2354('0xad'),'updatedAt')['from'](_0x2354('0xae'))[_0x2354('0x4e')](_0x2354('0xb5'))['where'](_0x2354('0xb6'),_0x523ce0[_0x2354('0xac')][_0x2354('0x8d')]())['where'](_0x2354('0xaf'))[_0x2354('0x4e')](_0x2354('0xb0'),squel[_0x2354('0x84')]()[_0x2354('0x85')]('COALESCE(phone,\x27\x27)')[_0x2354('0x87')](_0x2354('0xa7'))['where'](_0x2354('0xb3'),_0xaff739[_0x2354('0x53')]['id'][_0x2354('0x8d')]())))[_0x2354('0x8d')]();break;default:_0x3f7d6d=squel[_0x2354('0xa5')]()[_0x2354('0xa6')](_0x2354('0xa7'))[_0x2354('0xb7')]([_0x2354('0xa8'),_0x2354('0xa9'),_0x2354('0xaa'),_0x2354('0xab'),'VoiceQueueId','createdAt',_0x2354('0x5f')],squel['select']()['field']('phone',_0x2354('0xa8'))[_0x2354('0x85')](_0x2354('0xad'),_0x2354('0xa9'))[_0x2354('0x85')]('id',_0x2354('0xaa'))[_0x2354('0x85')](_0x523ce0[_0x2354('0xac')][_0x2354('0x8d')](),_0x2354('0xab'))['field'](_0xaff739[_0x2354('0x53')]['id'][_0x2354('0x8d')](),_0x2354('0x6a'))[_0x2354('0x85')](_0x2354('0xad'),_0x2354('0x5e'))[_0x2354('0x85')](_0x2354('0xad'),_0x2354('0x5f'))[_0x2354('0x87')](_0x2354('0xae'))['where'](_0x2354('0xb5'))[_0x2354('0x4e')]('ListId\x20=\x20?',_0x523ce0[_0x2354('0xac')][_0x2354('0x8d')]())['where'](_0x2354('0xaf')))['toString']();}_0x75b24[_0x2354('0xb8')](db[_0x2354('0x8c')][_0x2354('0x46')](_0x3f7d6d));}return BPromise[_0x2354('0x9b')](_0x75b24);}})[_0x2354('0x2b')](function(){return _0x3ac35c;})[_0x2354('0x2b')](respondWithResult(_0x3f95a1,null))[_0x2354('0x51')](handleError(_0x3f95a1,null));};exports[_0x2354('0xb9')]=function(_0x78a1e0,_0x11c77e,_0x453fe0){return db[_0x2354('0x3d')][_0x2354('0x36')]({'where':{'id':_0x78a1e0[_0x2354('0x53')]['id']}})['then'](handleEntityNotFound(_0x11c77e,null))[_0x2354('0x2b')](function(_0x57f7b4){if(_0x57f7b4){return _0x57f7b4[_0x2354('0xb9')](_0x78a1e0[_0x2354('0x46')][_0x2354('0x94')]);}})['then'](function(_0x54ff92){if(_0x54ff92){return db[_0x2354('0x64')]['destroy']({'where':{'ListId':_0x78a1e0['query'][_0x2354('0x94')],'VoiceQueueId':_0x78a1e0[_0x2354('0x53')]['id']}})[_0x2354('0x2b')](function(){return _0x54ff92;});}})[_0x2354('0x2b')](respondWithStatusCode(_0x11c77e,null))[_0x2354('0x51')](handleError(_0x11c77e,null));};exports['getBlackLists']=function(_0x5c91eb,_0x29dc02,_0x219663){var _0xbadced={};var _0x3b5eaa={};var _0x979076;var _0x4fe97b;return db[_0x2354('0x3d')][_0x2354('0x62')]({'where':{'id':_0x5c91eb['params']['id']}})[_0x2354('0x2b')](handleEntityNotFound(_0x29dc02,null))[_0x2354('0x2b')](function(_0x47512f){if(_0x47512f){_0x979076=_0x47512f;_0x3b5eaa[_0x2354('0x43')]=_[_0x2354('0x41')](db['CmList']['rawAttributes']);_0x3b5eaa[_0x2354('0x46')]=_['keys'](_0x5c91eb[_0x2354('0x46')]);_0x3b5eaa['filters']=_[_0x2354('0x42')](_0x3b5eaa[_0x2354('0x43')],_0x3b5eaa[_0x2354('0x46')]);_0xbadced['attributes']=_[_0x2354('0x42')](_0x3b5eaa[_0x2354('0x43')],qs[_0x2354('0x45')](_0x5c91eb['query'][_0x2354('0x45')]));_0xbadced[_0x2354('0x44')]=_0xbadced[_0x2354('0x44')][_0x2354('0x69')]?_0xbadced[_0x2354('0x44')]:_0x3b5eaa[_0x2354('0x43')];_0xbadced['order']=qs[_0x2354('0x4a')](_0x5c91eb[_0x2354('0x46')][_0x2354('0x4a')]);_0xbadced[_0x2354('0x4e')]=qs[_0x2354('0x4b')](_[_0x2354('0x63')](_0x5c91eb[_0x2354('0x46')],_0x3b5eaa[_0x2354('0x4b')]));if(_0x5c91eb[_0x2354('0x46')][_0x2354('0x32')]){_0xbadced[_0x2354('0x4e')]=_[_0x2354('0x4c')](_0xbadced[_0x2354('0x4e')],{'$or':_[_0x2354('0x3c')](_0xbadced[_0x2354('0x44')],function(_0x5e8d74){var _0x383fe4={};_0x383fe4[_0x5e8d74]={'$like':'%'+_0x5c91eb[_0x2354('0x46')]['filter']+'%'};return _0x383fe4;})});}_0xbadced=_['merge']({},_0xbadced,_0x5c91eb[_0x2354('0x4d')]);return _0x979076['getBlackLists'](_0xbadced);}})[_0x2354('0x2b')](function(_0x3d0d98){if(_0x3d0d98){_0x4fe97b=_0x3d0d98['length'];if(!_0x5c91eb[_0x2354('0x46')][_0x2354('0x47')](_0x2354('0x48'))){_0xbadced[_0x2354('0x24')]=qs[_0x2354('0x24')](_0x5c91eb['query'][_0x2354('0x24')]);_0xbadced[_0x2354('0x23')]=qs[_0x2354('0x23')](_0x5c91eb[_0x2354('0x46')][_0x2354('0x23')]);}return _0x979076[_0x2354('0xba')](_0xbadced);}})[_0x2354('0x2b')](function(_0x2343f6){if(_0x2343f6){return _0x2343f6?{'count':_0x4fe97b,'rows':_0x2343f6}:null;}})[_0x2354('0x2b')](respondWithResult(_0x29dc02,null))[_0x2354('0x51')](handleError(_0x29dc02,null));};exports['addBlackLists']=function(_0x2df699,_0x3f995f,_0x5e8eb2){var _0x34f572,_0x65fe03;return db['VoiceQueue']['find']({'where':{'id':_0x2df699[_0x2354('0x53')]['id']}})['then'](handleEntityNotFound(_0x3f995f,null))['then'](function(_0x46454d){if(_0x46454d){_0x65fe03=_0x46454d;return _0x46454d['addBlackLists'](_0x2df699['body'][_0x2354('0x94')],_[_0x2354('0x5d')](_0x2df699[_0x2354('0x55')],['ids','id'])||{});}return null;})[_0x2354('0x97')](function(_0x1aadf4){var _0x2d7e02;_0x34f572=_0x1aadf4||[];var _0x418469=[];if(_0x1aadf4){for(var _0x230ed4=0x0;_0x230ed4<_0x1aadf4['length'];_0x230ed4+=0x1){var _0x361ea9=_0x1aadf4[_0x230ed4][_0x2354('0x2d')]({'plain':!![]});_0x2d7e02=squel[_0x2354('0xa5')]()[_0x2354('0xa6')](_0x2354('0xbb'))[_0x2354('0xb7')]([_0x2354('0xa8'),_0x2354('0xaa'),'ListId','VoiceQueueId','createdAt',_0x2354('0x5f')],squel['select']()['field'](_0x2354('0xa8'),'phone')[_0x2354('0x85')]('id',_0x2354('0xaa'))['field'](_0x361ea9[_0x2354('0xac')][_0x2354('0x8d')](),_0x2354('0xab'))[_0x2354('0x85')](_0x2df699['params']['id'][_0x2354('0x8d')](),_0x2354('0x6a'))[_0x2354('0x85')](_0x2354('0xad'),'createdAt')[_0x2354('0x85')](_0x2354('0xad'),_0x2354('0x5f'))[_0x2354('0x87')](_0x2354('0xae'))['where'](_0x2354('0xb5'))[_0x2354('0x4e')](_0x2354('0xb6'),_0x361ea9['CmListId'][_0x2354('0x8d')]())['where']('phone\x20IS\x20NOT\x20NULL'))[_0x2354('0x8d')]();_0x418469[_0x2354('0xb8')](db[_0x2354('0x8c')]['query'](_0x2d7e02));}return BPromise[_0x2354('0x9b')](_0x418469);}})[_0x2354('0x2b')](function(){return _0x34f572;})[_0x2354('0x2b')](respondWithResult(_0x3f995f,null))['catch'](handleError(_0x3f995f,null));};exports[_0x2354('0xbc')]=function(_0x9c3ecb,_0x2b4424,_0x41e406){return db[_0x2354('0x3d')][_0x2354('0x36')]({'where':{'id':_0x9c3ecb[_0x2354('0x53')]['id']}})[_0x2354('0x2b')](handleEntityNotFound(_0x2b4424,null))[_0x2354('0x2b')](function(_0x2c8597){if(_0x2c8597){return _0x2c8597[_0x2354('0xbc')](_0x9c3ecb[_0x2354('0x46')][_0x2354('0x94')]);}})['then'](function(_0x123ac5){if(_0x123ac5){return db[_0x2354('0x6d')][_0x2354('0x2c')]({'where':{'ListId':_0x9c3ecb[_0x2354('0x46')][_0x2354('0x94')],'VoiceQueueId':_0x9c3ecb[_0x2354('0x53')]['id']}})[_0x2354('0x2b')](function(){return _0x123ac5;});}})['then'](respondWithStatusCode(_0x2b4424,null))[_0x2354('0x51')](handleError(_0x2b4424,null));};