Built motion from commit d1eab355.|2.6.28
[motion2.git] / server / api / whatsappQueue / whatsappQueue.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 _0x4c37=['emit','userWhatsappQueue:save','removeTeams','select','field','tq.TeamId','from','join','user_has_teams','WhatsappQueueId\x20=\x20?','push','sequelize','toString','QueryTypes','SELECT','every','includes','all','union','compact','removeAgents','userWhatsappQueue:remove','omit','spread','isArray','getAgents','bluebird','util','lodash','squel','ioredis','../../components/parsers/qs','../../config/logger','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./whatsappQueue.socket','register','status','end','offset','undefined','count','limit','json','update','destroy','get','UserProfileResource','then','sendStatus','error','stack','name','index','map','WhatsappQueue','type','where','include','query','findAll','rows','catch','show','params','model','keys','rawAttributes','filters','intersection','attributes','fields','length','includeAll','merge','options','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','WhatsappQueues','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','getMembers','nolimit','order','sort','pick','WhatsappQueueId','filter','UserWhatsappQueue','User','UserId','whatsappPause','updatedAt','createdAt','format','%s/%s','getTeams','findOne','hasOwnProperty','addTeams','ids','Team','Agents','flatMap','transaction','forEach'];(function(_0x4864ad,_0x4c865b){var _0x2c7f82=function(_0xea17a2){while(--_0xea17a2){_0x4864ad['push'](_0x4864ad['shift']());}};_0x2c7f82(++_0x4c865b);}(_0x4c37,0x102));var _0x74c3=function(_0x526e11,_0xc10269){_0x526e11=_0x526e11-0x0;var _0x139780=_0x4c37[_0x526e11];return _0x139780;};'use strict';var BPromise=require(_0x74c3('0x0'));var util=require(_0x74c3('0x1'));var _=require(_0x74c3('0x2'));var squel=require(_0x74c3('0x3'));var Redis=require(_0x74c3('0x4'));var qs=require(_0x74c3('0x5'));var logger=require(_0x74c3('0x6'))('api');var config=require('../../config/environment');var db=require(_0x74c3('0x7'))['db'];config['redis']=_[_0x74c3('0x8')](config[_0x74c3('0x9')],{'host':_0x74c3('0xa'),'port':0x18eb});var socket=require(_0x74c3('0xb'))(new Redis(config[_0x74c3('0x9')]));require(_0x74c3('0xc'))[_0x74c3('0xd')](socket);function respondWithStatusCode(_0x437258,_0x483676){_0x483676=_0x483676||0xcc;return function(_0x2dce82){if(_0x2dce82){return _0x437258['sendStatus'](_0x483676);}return _0x437258[_0x74c3('0xe')](_0x483676)[_0x74c3('0xf')]();};}function respondWithResult(_0x2cac2f,_0x363546){_0x363546=_0x363546||0xc8;return function(_0x6c2b78){if(_0x6c2b78){return _0x2cac2f[_0x74c3('0xe')](_0x363546)['json'](_0x6c2b78);}};}function respondWithFilteredResult(_0x305f62,_0x658f9b){return function(_0xb7449e){if(_0xb7449e){var _0x51cf91=typeof _0x658f9b[_0x74c3('0x10')]==='undefined'&&typeof _0x658f9b['limit']===_0x74c3('0x11');var _0x64e9bf=_0xb7449e['count'];var _0x4881d5=_0x51cf91?0x0:_0x658f9b[_0x74c3('0x10')];var _0x197e1c=_0x51cf91?_0xb7449e[_0x74c3('0x12')]:_0x658f9b[_0x74c3('0x10')]+_0x658f9b[_0x74c3('0x13')];var _0x18c22a;if(_0x197e1c>=_0x64e9bf){_0x197e1c=_0x64e9bf;_0x18c22a=0xc8;}else{_0x18c22a=0xce;}_0x305f62[_0x74c3('0xe')](_0x18c22a);return _0x305f62['set']('Content-Range',_0x4881d5+'-'+_0x197e1c+'/'+_0x64e9bf)[_0x74c3('0x14')](_0xb7449e);}return null;};}function saveUpdates(_0x4dcb7){return function(_0x261747){if(_0x261747){return _0x261747[_0x74c3('0x15')](_0x4dcb7)['then'](function(_0x112531){return _0x112531;});}return null;};}function removeEntity(_0x12904e){return function(_0x554a41){if(_0x554a41){return _0x554a41[_0x74c3('0x16')]()['then'](function(){var _0x504619=_0x554a41[_0x74c3('0x17')]({'plain':!![]});var _0x16f069='WhatsappQueues';return db[_0x74c3('0x18')][_0x74c3('0x16')]({'where':{'type':_0x16f069,'resourceId':_0x504619['id']}})[_0x74c3('0x19')](function(){return _0x554a41;});})[_0x74c3('0x19')](function(){_0x12904e[_0x74c3('0xe')](0xcc)[_0x74c3('0xf')]();});}};}function handleEntityNotFound(_0x3645f3){return function(_0x419be2){if(!_0x419be2){_0x3645f3[_0x74c3('0x1a')](0x194);}return _0x419be2;};}function handleError(_0x4706e0,_0xdfeb86){_0xdfeb86=_0xdfeb86||0x1f4;return function(_0x333718){logger[_0x74c3('0x1b')](_0x333718[_0x74c3('0x1c')]);if(_0x333718['name']){delete _0x333718[_0x74c3('0x1d')];}_0x4706e0[_0x74c3('0xe')](_0xdfeb86)['send'](_0x333718);};}exports[_0x74c3('0x1e')]=function(_0x50ee31,_0x27146b){var _0x34e946={};var _0x21cbd6={'count':0x0,'rows':[]};var _0x1ac08a=_[_0x74c3('0x1f')](db[_0x74c3('0x20')]['rawAttributes'],function(_0x598992){return{'name':_0x598992['fieldName'],'type':_0x598992[_0x74c3('0x21')]['key']};});_0x34e946=qs['getOptions'](_0x1ac08a,_0x50ee31);var _0x161833={'where':_0x34e946[_0x74c3('0x22')]};return db[_0x74c3('0x20')]['count'](_0x161833)[_0x74c3('0x19')](function(_0x1db18a){_0x21cbd6[_0x74c3('0x12')]=_0x1db18a;_0x34e946['include']=qs[_0x74c3('0x23')](_0x50ee31[_0x74c3('0x24')]);return db[_0x74c3('0x20')][_0x74c3('0x25')](_0x34e946);})[_0x74c3('0x19')](function(_0x841b5d){_0x21cbd6[_0x74c3('0x26')]=_0x841b5d;return _0x21cbd6;})[_0x74c3('0x19')](respondWithFilteredResult(_0x27146b,_0x34e946))[_0x74c3('0x27')](handleError(_0x27146b,null));};exports[_0x74c3('0x28')]=function(_0x55ef6e,_0x4ef533){var _0x1d08af={'raw':!![],'where':{'id':_0x55ef6e[_0x74c3('0x29')]['id']}},_0x23632f={};_0x23632f[_0x74c3('0x2a')]=_[_0x74c3('0x2b')](db['WhatsappQueue'][_0x74c3('0x2c')]);_0x23632f[_0x74c3('0x24')]=_[_0x74c3('0x2b')](_0x55ef6e[_0x74c3('0x24')]);_0x23632f[_0x74c3('0x2d')]=_[_0x74c3('0x2e')](_0x23632f['model'],_0x23632f['query']);_0x1d08af[_0x74c3('0x2f')]=_['intersection'](_0x23632f[_0x74c3('0x2a')],qs[_0x74c3('0x30')](_0x55ef6e[_0x74c3('0x24')][_0x74c3('0x30')]));_0x1d08af[_0x74c3('0x2f')]=_0x1d08af[_0x74c3('0x2f')][_0x74c3('0x31')]?_0x1d08af[_0x74c3('0x2f')]:_0x23632f[_0x74c3('0x2a')];if(_0x55ef6e[_0x74c3('0x24')][_0x74c3('0x32')]){_0x1d08af[_0x74c3('0x23')]=[{'all':!![]}];}_0x1d08af=_[_0x74c3('0x33')]({},_0x1d08af,_0x55ef6e[_0x74c3('0x34')]);return db['WhatsappQueue'][_0x74c3('0x35')](_0x1d08af)[_0x74c3('0x19')](handleEntityNotFound(_0x4ef533,null))['then'](respondWithResult(_0x4ef533,null))[_0x74c3('0x27')](handleError(_0x4ef533,null));};exports[_0x74c3('0x36')]=function(_0x2d33ce,_0x3aaf07){return db[_0x74c3('0x20')]['create'](_0x2d33ce[_0x74c3('0x37')],{})[_0x74c3('0x19')](function(_0x206763){var _0x27d703=_0x2d33ce['user'][_0x74c3('0x17')]({'plain':!![]});if(!_0x27d703)throw new Error(_0x74c3('0x38'));if(_0x27d703[_0x74c3('0x39')]===_0x74c3('0x3a')){var _0x2c8470=_0x206763[_0x74c3('0x17')]({'plain':!![]});var _0x5c751d=_0x74c3('0x3b');return db[_0x74c3('0x3c')][_0x74c3('0x35')]({'where':{'name':_0x5c751d,'userProfileId':_0x27d703[_0x74c3('0x3d')]},'raw':!![]})[_0x74c3('0x19')](function(_0x567bb9){if(_0x567bb9&&_0x567bb9[_0x74c3('0x3e')]===0x0){return db['UserProfileResource']['create']({'name':_0x2c8470[_0x74c3('0x1d')],'resourceId':_0x2c8470['id'],'type':_0x567bb9[_0x74c3('0x1d')],'sectionId':_0x567bb9['id']},{})[_0x74c3('0x19')](function(){return _0x206763;});}else{return _0x206763;}})[_0x74c3('0x27')](function(_0x4a08ca){logger[_0x74c3('0x1b')](_0x74c3('0x3f'),_0x4a08ca);throw _0x4a08ca;});}return _0x206763;})[_0x74c3('0x19')](respondWithResult(_0x3aaf07,0xc9))[_0x74c3('0x27')](handleError(_0x3aaf07,null));};exports[_0x74c3('0x15')]=function(_0x30e874,_0x19670b){if(_0x30e874[_0x74c3('0x37')]['id']){delete _0x30e874[_0x74c3('0x37')]['id'];}return db[_0x74c3('0x20')][_0x74c3('0x35')]({'where':{'id':_0x30e874[_0x74c3('0x29')]['id']}})[_0x74c3('0x19')](handleEntityNotFound(_0x19670b,null))[_0x74c3('0x19')](saveUpdates(_0x30e874[_0x74c3('0x37')],null))[_0x74c3('0x19')](respondWithResult(_0x19670b,null))[_0x74c3('0x27')](handleError(_0x19670b,null));};exports['destroy']=function(_0x3c6564,_0xb66a0e){return db[_0x74c3('0x20')][_0x74c3('0x35')]({'where':{'id':_0x3c6564[_0x74c3('0x29')]['id']}})[_0x74c3('0x19')](handleEntityNotFound(_0xb66a0e,null))['then'](removeEntity(_0xb66a0e,null))[_0x74c3('0x27')](handleError(_0xb66a0e,null));};exports['describe']=function(_0x520e3f,_0x18cb36){return db[_0x74c3('0x20')][_0x74c3('0x40')]()[_0x74c3('0x19')](respondWithResult(_0x18cb36,null))[_0x74c3('0x27')](handleError(_0x18cb36,null));};exports[_0x74c3('0x41')]=function(_0xc37263,_0x544144){var _0x495204={'raw':!![],'where':{}},_0x2957f9={},_0x4cd9a8;return db['WhatsappQueue']['findOne']({'where':{'id':_0xc37263[_0x74c3('0x29')]['id']}})[_0x74c3('0x19')](handleEntityNotFound(_0x544144,null))[_0x74c3('0x19')](function(_0x192533){if(_0x192533){_0x4cd9a8=_0x192533['get']({'plain':!![]});_0x2957f9[_0x74c3('0x2a')]=_[_0x74c3('0x2b')](db['UserWhatsappQueue'][_0x74c3('0x2c')]);_0x2957f9[_0x74c3('0x24')]=_[_0x74c3('0x2b')](_0xc37263[_0x74c3('0x24')]);_0x2957f9[_0x74c3('0x2d')]=_['intersection'](_0x2957f9['model'],_0x2957f9[_0x74c3('0x24')]);_0x495204[_0x74c3('0x2f')]=_[_0x74c3('0x2e')](_0x2957f9[_0x74c3('0x2a')],qs['fields'](_0xc37263[_0x74c3('0x24')][_0x74c3('0x30')]));_0x495204[_0x74c3('0x2f')]=_0x495204[_0x74c3('0x2f')][_0x74c3('0x31')]?_0x495204[_0x74c3('0x2f')]:_0x2957f9[_0x74c3('0x2a')];if(!_0xc37263['query']['hasOwnProperty'](_0x74c3('0x42'))){_0x495204[_0x74c3('0x13')]=qs['limit'](_0xc37263[_0x74c3('0x24')]['limit']);_0x495204[_0x74c3('0x10')]=qs['offset'](_0xc37263[_0x74c3('0x24')][_0x74c3('0x10')]);}_0x495204[_0x74c3('0x43')]=qs[_0x74c3('0x44')](_0xc37263[_0x74c3('0x24')]['sort']);_0x495204[_0x74c3('0x22')]=qs[_0x74c3('0x2d')](_[_0x74c3('0x45')](_0xc37263[_0x74c3('0x24')],_0x2957f9['filters']));_0x495204[_0x74c3('0x22')][_0x74c3('0x46')]=_0x192533['id'];if(_0xc37263[_0x74c3('0x24')][_0x74c3('0x47')]){_0x495204[_0x74c3('0x22')]=_['merge'](_0x495204['where'],{'$or':_[_0x74c3('0x1f')](_0x495204['attributes'],function(_0x42f21f){var _0x872346={};_0x872346[_0x42f21f]={'$like':'%'+_0xc37263[_0x74c3('0x24')][_0x74c3('0x47')]+'%'};return _0x872346;})});}_0x495204=_[_0x74c3('0x33')]({},_0x495204,_0xc37263[_0x74c3('0x34')]);return db[_0x74c3('0x48')]['findAll'](_0x495204);}})[_0x74c3('0x19')](function(_0x1d00e9){if(_0x1d00e9){return db[_0x74c3('0x49')]['findAndCountAll']({'where':{'id':_[_0x74c3('0x1f')](_0x1d00e9,_0x74c3('0x4a')),'role':'agent'},'attributes':['id',_0x74c3('0x1d'),_0x74c3('0x4b'),_0x74c3('0x4c'),_0x74c3('0x4d')]});}})[_0x74c3('0x19')](function(_0x430daf){if(_0x430daf){return{'count':_0x430daf[_0x74c3('0x12')],'rows':_['map'](_0x430daf[_0x74c3('0x26')],function(_0x4f8543){return{'membername':_0x4f8543[_0x74c3('0x1d')],'UserId':_0x4f8543['id'],'queue_name':_0x4cd9a8['name'],'WhatsappQueueId':_0x4cd9a8['id'],'interface':util[_0x74c3('0x4e')](_0x74c3('0x4f'),'SIP',_0x4f8543[_0x74c3('0x1d')]),'penalty':0x0,'paused':_0x4f8543[_0x74c3('0x4b')],'createdAt':_0x4f8543[_0x74c3('0x4d')],'updatedAt':_0x4f8543[_0x74c3('0x4c')]};})};}else{return{'count':0x0,'rows':[]};}})['then'](respondWithFilteredResult(_0x544144,_0x495204))[_0x74c3('0x27')](handleError(_0x544144,null));};exports[_0x74c3('0x50')]=function(_0x48241c,_0x2130dc){var _0x53e451={};var _0x4d9f2={};var _0x324149;var _0x55154d;return db['WhatsappQueue'][_0x74c3('0x51')]({'where':{'id':_0x48241c[_0x74c3('0x29')]['id']}})['then'](handleEntityNotFound(_0x2130dc,null))[_0x74c3('0x19')](function(_0x23e284){if(_0x23e284){_0x324149=_0x23e284;_0x4d9f2[_0x74c3('0x2a')]=_[_0x74c3('0x2b')](db['Team'][_0x74c3('0x2c')]);_0x4d9f2['query']=_[_0x74c3('0x2b')](_0x48241c[_0x74c3('0x24')]);_0x4d9f2['filters']=_[_0x74c3('0x2e')](_0x4d9f2[_0x74c3('0x2a')],_0x4d9f2[_0x74c3('0x24')]);_0x53e451[_0x74c3('0x2f')]=_[_0x74c3('0x2e')](_0x4d9f2[_0x74c3('0x2a')],qs[_0x74c3('0x30')](_0x48241c[_0x74c3('0x24')][_0x74c3('0x30')]));_0x53e451[_0x74c3('0x2f')]=_0x53e451[_0x74c3('0x2f')][_0x74c3('0x31')]?_0x53e451[_0x74c3('0x2f')]:_0x4d9f2[_0x74c3('0x2a')];_0x53e451['order']=qs['sort'](_0x48241c[_0x74c3('0x24')][_0x74c3('0x44')]);_0x53e451[_0x74c3('0x22')]=qs['filters'](_[_0x74c3('0x45')](_0x48241c[_0x74c3('0x24')],_0x4d9f2[_0x74c3('0x2d')]));if(_0x48241c[_0x74c3('0x24')][_0x74c3('0x47')]){_0x53e451[_0x74c3('0x22')]=_[_0x74c3('0x33')](_0x53e451[_0x74c3('0x22')],{'$or':_['map'](_0x53e451[_0x74c3('0x2f')],function(_0x1cf8b3){var _0x3e8820={};_0x3e8820[_0x1cf8b3]={'$like':'%'+_0x48241c['query'][_0x74c3('0x47')]+'%'};return _0x3e8820;})});}_0x53e451=_['merge']({},_0x53e451,_0x48241c['options']);return _0x324149[_0x74c3('0x50')](_0x53e451);}})[_0x74c3('0x19')](function(_0x242926){if(_0x242926){_0x55154d=_0x242926['length'];if(!_0x48241c[_0x74c3('0x24')][_0x74c3('0x52')](_0x74c3('0x42'))){_0x53e451['limit']=qs[_0x74c3('0x13')](_0x48241c[_0x74c3('0x24')]['limit']);_0x53e451[_0x74c3('0x10')]=qs[_0x74c3('0x10')](_0x48241c[_0x74c3('0x24')][_0x74c3('0x10')]);}return _0x324149['getTeams'](_0x53e451);}})[_0x74c3('0x19')](function(_0x1645f0){if(_0x1645f0){return _0x1645f0?{'count':_0x55154d,'rows':_0x1645f0}:null;}})[_0x74c3('0x19')](respondWithResult(_0x2130dc,null))['catch'](handleError(_0x2130dc,null));};exports[_0x74c3('0x53')]=function(_0xdb2c21,_0x270bae){var _0x31d3f7=_0xdb2c21[_0x74c3('0x37')][_0x74c3('0x54')];return db[_0x74c3('0x55')]['findAll']({'where':{'id':_0x31d3f7},'attributes':['id'],'include':[{'model':db['User'],'as':_0x74c3('0x56'),'attributes':['id',_0x74c3('0x1d'),'online','voicePause','interface'],'raw':!![]}]})[_0x74c3('0x19')](function(_0x5266cb){if(_0x5266cb){var _0x4166f0=_[_0x74c3('0x57')](_0x5266cb,function(_0x421a0a){var _0x308fc3=_0x421a0a[_0x74c3('0x17')]({'plain':!![]});return _0x308fc3[_0x74c3('0x56')];});return db[_0x74c3('0x20')][_0x74c3('0x35')]({'where':{'id':_0xdb2c21[_0x74c3('0x29')]['id']}})[_0x74c3('0x19')](function(_0x2e635d){return db['sequelize'][_0x74c3('0x58')](function(_0x3df44b){return _0x2e635d['addTeams'](_0x31d3f7,{'transaction':_0x3df44b})['then'](function(){return BPromise['each'](_0x4166f0,function(_0xf241d){return db[_0x74c3('0x48')]['findOrCreate']({'where':{'UserId':_0xf241d['id'],'WhatsappQueueId':_0xdb2c21[_0x74c3('0x29')]['id']},'transaction':_0x3df44b});});})[_0x74c3('0x19')](function(){_0x4166f0[_0x74c3('0x59')](function(_0x4cbabc){socket[_0x74c3('0x5a')](_0x74c3('0x5b'),{'UserId':_0x4cbabc['id'],'WhatsappQueueId':_0x2e635d['id']});});});});});}})[_0x74c3('0x19')](respondWithStatusCode(_0x270bae,null))[_0x74c3('0x27')](handleError(_0x270bae,null));};exports[_0x74c3('0x5c')]=function(_0x235fa8,_0x4219e4){return db[_0x74c3('0x55')][_0x74c3('0x25')]({'where':{'id':_0x235fa8[_0x74c3('0x24')][_0x74c3('0x54')]},'attributes':['id'],'include':[{'model':db[_0x74c3('0x49')],'as':_0x74c3('0x56'),'attributes':['id'],'raw':!![]}]})['then'](handleEntityNotFound(_0x4219e4,null))['then'](function(_0x1586b8){var _0x3e220c=_[_0x74c3('0x1f')](_0x1586b8,'id');var _0x2061cb=[];var _0x4c7840=[];var _0x1f2d09=squel[_0x74c3('0x5d')]();_0x1f2d09[_0x74c3('0x5e')](_0x74c3('0x5f'))[_0x74c3('0x60')]('team_has_whatsapp_queues','tq')[_0x74c3('0x61')](_0x74c3('0x62'),'ut','ut.TeamId\x20=\x20tq.TeamId')[_0x74c3('0x22')](_0x74c3('0x63'),_0x235fa8[_0x74c3('0x29')]['id']);for(var _0x45675d=0x0;_0x45675d<_0x1586b8[_0x74c3('0x31')];_0x45675d+=0x1){let _0x112cae=_0x1586b8[_0x45675d];for(var _0x44aa0e=0x0;_0x44aa0e<_0x112cae[_0x74c3('0x56')][_0x74c3('0x31')];_0x44aa0e+=0x1){let _0x53cb94=_0x112cae[_0x74c3('0x56')][_0x44aa0e];var _0x2f9e4a=_0x1f2d09['clone']();_0x2f9e4a[_0x74c3('0x22')]('ut.UserId\x20=\x20?',_0x53cb94['id']);_0x4c7840[_0x74c3('0x64')](db[_0x74c3('0x65')][_0x74c3('0x24')](_0x2f9e4a[_0x74c3('0x66')](),{'type':db[_0x74c3('0x65')][_0x74c3('0x67')][_0x74c3('0x68')]})[_0x74c3('0x19')](function(_0x1efe16){if(_0x1efe16[_0x74c3('0x31')]===0x1){return _0x53cb94['id'];}else{var _0xb4e03f=_[_0x74c3('0x69')](_['map'](_0x1efe16,'TeamId'),function(_0x26d32a){return _[_0x74c3('0x6a')](_0x3e220c,_0x26d32a);});if(_0xb4e03f){return _0x53cb94['id'];}}}));}}return BPromise[_0x74c3('0x6b')](_0x4c7840)[_0x74c3('0x19')](function(_0x1fcc10){_0x2061cb=_(_0x2061cb)[_0x74c3('0x6c')](_0x1fcc10)[_0x74c3('0x6d')]()['value']();return db[_0x74c3('0x20')][_0x74c3('0x35')]({'where':{'id':_0x235fa8[_0x74c3('0x29')]['id']}})['then'](function(_0x839158){return db[_0x74c3('0x65')][_0x74c3('0x58')](function(_0x46cc9d){return _0x839158[_0x74c3('0x5c')](_0x235fa8['query'][_0x74c3('0x54')],{'transaction':_0x46cc9d})['then'](function(){if(!_['isEmpty'](_0x2061cb)){return _0x839158[_0x74c3('0x6e')](_0x2061cb,{'transaction':_0x46cc9d});}})[_0x74c3('0x19')](function(){_0x2061cb[_0x74c3('0x59')](function(_0xe6a11a){socket['emit'](_0x74c3('0x6f'),{'UserId':_0xe6a11a,'WhatsappQueueId':_0x839158['id']});});});});});});})[_0x74c3('0x19')](respondWithStatusCode(_0x4219e4,null))[_0x74c3('0x27')](handleError(_0x4219e4,null));};exports['addAgents']=function(_0x49ae86,_0x579f0e){return db['WhatsappQueue'][_0x74c3('0x35')]({'where':{'id':_0x49ae86['params']['id']}})[_0x74c3('0x19')](handleEntityNotFound(_0x579f0e,null))[_0x74c3('0x19')](function(_0x5aadd6){if(_0x5aadd6){return _0x5aadd6['addAgents'](_0x49ae86[_0x74c3('0x37')][_0x74c3('0x54')],_[_0x74c3('0x70')](_0x49ae86[_0x74c3('0x37')],[_0x74c3('0x54'),'id'])||{})[_0x74c3('0x71')](function(_0x5986ad){for(var _0x38c278=0x0;_0x38c278<_0x49ae86['body'][_0x74c3('0x54')]['length'];_0x38c278+=0x1){socket[_0x74c3('0x5a')](_0x74c3('0x5b'),{'UserId':Number(_0x49ae86[_0x74c3('0x37')][_0x74c3('0x54')][_0x38c278]),'WhatsappQueueId':Number(_0x49ae86[_0x74c3('0x29')]['id'])});}return _0x5986ad;});}})[_0x74c3('0x19')](respondWithResult(_0x579f0e,null))[_0x74c3('0x27')](handleError(_0x579f0e,null));};exports[_0x74c3('0x6e')]=function(_0x44bba8,_0x3d565b){return db[_0x74c3('0x20')][_0x74c3('0x35')]({'where':{'id':_0x44bba8['params']['id']}})[_0x74c3('0x19')](handleEntityNotFound(_0x3d565b,null))[_0x74c3('0x19')](function(_0x140afc){if(_0x140afc){return _0x140afc['removeAgents'](_0x44bba8[_0x74c3('0x24')][_0x74c3('0x54')])['then'](function(){if(_[_0x74c3('0x72')](_0x44bba8[_0x74c3('0x24')][_0x74c3('0x54')])){for(var _0x53906b=0x0;_0x53906b<_0x44bba8[_0x74c3('0x24')][_0x74c3('0x54')]['length'];_0x53906b+=0x1){socket['emit'](_0x74c3('0x6f'),{'UserId':Number(_0x44bba8['query'][_0x74c3('0x54')][_0x53906b]),'WhatsappQueueId':Number(_0x44bba8['params']['id'])});}}else{socket[_0x74c3('0x5a')](_0x74c3('0x6f'),{'UserId':Number(_0x44bba8[_0x74c3('0x24')][_0x74c3('0x54')]),'WhatsappQueueId':Number(_0x44bba8[_0x74c3('0x29')]['id'])});}});}})[_0x74c3('0x19')](respondWithStatusCode(_0x3d565b,null))[_0x74c3('0x27')](handleError(_0x3d565b,null));};exports['getAgents']=function(_0x89e670,_0x2322fc){var _0x46047a={};var _0x219b2c={};var _0x222e52;var _0x1ff3a6;return db[_0x74c3('0x20')][_0x74c3('0x51')]({'where':{'id':_0x89e670[_0x74c3('0x29')]['id']}})['then'](handleEntityNotFound(_0x2322fc,null))[_0x74c3('0x19')](function(_0x282e34){if(_0x282e34){_0x222e52=_0x282e34;_0x219b2c[_0x74c3('0x2a')]=_[_0x74c3('0x2b')](db[_0x74c3('0x49')]['rawAttributes']);_0x219b2c['query']=_[_0x74c3('0x2b')](_0x89e670[_0x74c3('0x24')]);_0x219b2c[_0x74c3('0x2d')]=_[_0x74c3('0x2e')](_0x219b2c[_0x74c3('0x2a')],_0x219b2c[_0x74c3('0x24')]);_0x46047a['attributes']=_[_0x74c3('0x2e')](_0x219b2c['model'],qs[_0x74c3('0x30')](_0x89e670[_0x74c3('0x24')][_0x74c3('0x30')]));_0x46047a[_0x74c3('0x2f')]=_0x46047a[_0x74c3('0x2f')][_0x74c3('0x31')]?_0x46047a[_0x74c3('0x2f')]:_0x219b2c[_0x74c3('0x2a')];_0x46047a[_0x74c3('0x43')]=qs[_0x74c3('0x44')](_0x89e670['query'][_0x74c3('0x44')]);_0x46047a['where']=qs[_0x74c3('0x2d')](_['pick'](_0x89e670[_0x74c3('0x24')],_0x219b2c['filters']));if(_0x89e670[_0x74c3('0x24')][_0x74c3('0x47')]){_0x46047a['where']=_[_0x74c3('0x33')](_0x46047a['where'],{'$or':_[_0x74c3('0x1f')](_0x46047a['attributes'],function(_0xb826ae){var _0x351e42={};_0x351e42[_0xb826ae]={'$like':'%'+_0x89e670[_0x74c3('0x24')][_0x74c3('0x47')]+'%'};return _0x351e42;})});}_0x46047a=_['merge']({},_0x46047a,_0x89e670[_0x74c3('0x34')]);return _0x222e52[_0x74c3('0x73')](_0x46047a);}})[_0x74c3('0x19')](function(_0x3f1a6e){if(_0x3f1a6e){_0x1ff3a6=_0x3f1a6e[_0x74c3('0x31')];if(!_0x89e670[_0x74c3('0x24')][_0x74c3('0x52')]('nolimit')){_0x46047a[_0x74c3('0x13')]=qs['limit'](_0x89e670['query'][_0x74c3('0x13')]);_0x46047a['offset']=qs[_0x74c3('0x10')](_0x89e670[_0x74c3('0x24')][_0x74c3('0x10')]);}return _0x222e52['getAgents'](_0x46047a);}})['then'](function(_0x57c99a){if(_0x57c99a){return _0x57c99a?{'count':_0x1ff3a6,'rows':_0x57c99a}:null;}})['then'](respondWithResult(_0x2322fc,null))[_0x74c3('0x27')](handleError(_0x2322fc,null));};