bd935080aedd1cff589c985a088fffda961d8224
[motion2.git] / server / api / team / team.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 _0xb589=['papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','socket.io-emitter','./team.socket','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','update','then','destroy','get','Teams','error','name','send','index','map','Team','rawAttributes','type','key','model','query','keys','intersection','fields','attributes','length','hasOwnProperty','order','sort','where','filters','filter','merge','VIRTUAL','includeAll','include','findAll','rows','catch','show','params','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','getQueues','channel','ValidationError','Unknown\x20channel','capitalize','pick','toLowerCase','Queues','addQueues','findOne','ids','removeQueues','Sequelize','remove','addAgents','Voice','Chat','Mail','Sms','Fax','sequelize','transaction','through','penalty','TeamVoiceQueue','User','Queue','findOrCreate','emit','Queue:save','QueueId','online','voicePause','interface','UserVoiceQueueRt','upsert','isNil','format','SIP/%s','all','spread','removeAgents','Openchannel','Whatsapp','parse','Queue:remove','getAgents','nolimit','rimraf','fast-json-patch','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring'];(function(_0x14c702,_0x5c2e21){var _0x276559=function(_0x438344){while(--_0x438344){_0x14c702['push'](_0x14c702['shift']());}};_0x276559(++_0x5c2e21);}(_0xb589,0x102));var _0x9b58=function(_0x5d8631,_0x44944b){_0x5d8631=_0x5d8631-0x0;var _0x34c15e=_0xb589[_0x5d8631];return _0x34c15e;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x9b58('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x9b58('0x1'));var rp=require('request-promise');var moment=require(_0x9b58('0x2'));var BPromise=require(_0x9b58('0x3'));var Mustache=require(_0x9b58('0x4'));var util=require(_0x9b58('0x5'));var path=require('path');var sox=require(_0x9b58('0x6'));var csv=require(_0x9b58('0x7'));var ejs=require(_0x9b58('0x8'));var fs=require('fs');var fs_extra=require(_0x9b58('0x9'));var _=require(_0x9b58('0xa'));var squel=require(_0x9b58('0xb'));var crypto=require(_0x9b58('0xc'));var jsforce=require(_0x9b58('0xd'));var deskjs=require(_0x9b58('0xe'));var toCsv=require(_0x9b58('0x7'));var querystring=require(_0x9b58('0xf'));var Papa=require(_0x9b58('0x10'));var Redis=require(_0x9b58('0x11'));var authService=require('../../components/auth/service');var qs=require(_0x9b58('0x12'));var as=require(_0x9b58('0x13'));var hardwareService=require(_0x9b58('0x14'));var logger=require(_0x9b58('0x15'))(_0x9b58('0x16'));var utils=require(_0x9b58('0x17'));var config=require(_0x9b58('0x18'));var licenseUtil=require(_0x9b58('0x19'));var db=require(_0x9b58('0x1a'))['db'];config[_0x9b58('0x1b')]=_[_0x9b58('0x1c')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x9b58('0x1d'))(new Redis(config['redis']));require(_0x9b58('0x1e'))['register'](socket);function respondWithStatusCode(_0x151cee,_0x102f52){_0x102f52=_0x102f52||0xcc;return function(_0x607fc5){if(_0x607fc5){return _0x151cee[_0x9b58('0x1f')](_0x102f52);}return _0x151cee[_0x9b58('0x20')](_0x102f52)[_0x9b58('0x21')]();};}function respondWithResult(_0x31b4c6,_0x591e8d){_0x591e8d=_0x591e8d||0xc8;return function(_0x9d7527){if(_0x9d7527){return _0x31b4c6['status'](_0x591e8d)[_0x9b58('0x22')](_0x9d7527);}};}function respondWithFilteredResult(_0x5cf3f9,_0x31d620){return function(_0x3ebc3f){if(_0x3ebc3f){var _0x5f18d8=_0x3ebc3f[_0x9b58('0x23')],_0x313288=_0x31d620[_0x9b58('0x24')],_0x8e2243=_0x31d620[_0x9b58('0x24')]+_0x31d620[_0x9b58('0x25')],_0x30d376;if(_0x8e2243>=_0x5f18d8){_0x8e2243=_0x5f18d8;_0x30d376=0xc8;}else{_0x30d376=0xce;}_0x5cf3f9['status'](_0x30d376);return _0x5cf3f9[_0x9b58('0x26')](_0x9b58('0x27'),_0x313288+'-'+_0x8e2243+'/'+_0x5f18d8)[_0x9b58('0x22')](_0x3ebc3f);}return null;};}function patchUpdates(_0x42e2f7){return function(_0x10c3d9){try{jsonpatch[_0x9b58('0x28')](_0x10c3d9,_0x42e2f7,!![]);}catch(_0x70e233){return BPromise['reject'](_0x70e233);}return _0x10c3d9['save']();};}function saveUpdates(_0x1eb435,_0x4d673d){return function(_0x1e2c0b){if(_0x1e2c0b){return _0x1e2c0b[_0x9b58('0x29')](_0x1eb435)[_0x9b58('0x2a')](function(_0x546790){return _0x546790;});}return null;};}function removeEntity(_0x1372bd,_0x2fbb44){return function(_0x1618c6){if(_0x1618c6){return _0x1618c6[_0x9b58('0x2b')]()[_0x9b58('0x2a')](function(){var _0x4af26a=_0x1618c6[_0x9b58('0x2c')]({'plain':!![]});var _0x101b0d=_0x9b58('0x2d');return db['UserProfileResource'][_0x9b58('0x2b')]({'where':{'type':_0x101b0d,'resourceId':_0x4af26a['id']}})[_0x9b58('0x2a')](function(){return _0x1618c6;});})['then'](function(){_0x1372bd[_0x9b58('0x20')](0xcc)[_0x9b58('0x21')]();});}};}function handleEntityNotFound(_0x1c25c7,_0x54fb4e){return function(_0x5c9ee5){if(!_0x5c9ee5){_0x1c25c7[_0x9b58('0x1f')](0x194);}return _0x5c9ee5;};}function handleError(_0x8b5858,_0x19b6bf){_0x19b6bf=_0x19b6bf||0x1f4;return function(_0x92a5ab){logger[_0x9b58('0x2e')](_0x92a5ab['stack']);if(_0x92a5ab['name']){delete _0x92a5ab[_0x9b58('0x2f')];}_0x8b5858[_0x9b58('0x20')](_0x19b6bf)[_0x9b58('0x30')](_0x92a5ab);};}exports[_0x9b58('0x31')]=function(_0xd941c,_0x224d7e){var _0x394bdc={},_0x274239={},_0x4fc38a={'count':0x0,'rows':[]};var _0x4cc743=_[_0x9b58('0x32')](db[_0x9b58('0x33')][_0x9b58('0x34')],function(_0x1f27fa){return{'name':_0x1f27fa['fieldName'],'type':_0x1f27fa[_0x9b58('0x35')][_0x9b58('0x36')]};});_0x274239[_0x9b58('0x37')]=_[_0x9b58('0x32')](_0x4cc743,_0x9b58('0x2f'));_0x274239[_0x9b58('0x38')]=_[_0x9b58('0x39')](_0xd941c[_0x9b58('0x38')]);_0x274239['filters']=_['intersection'](_0x274239[_0x9b58('0x37')],_0x274239['query']);_0x394bdc['attributes']=_[_0x9b58('0x3a')](_0x274239[_0x9b58('0x37')],qs[_0x9b58('0x3b')](_0xd941c['query'][_0x9b58('0x3b')]));_0x394bdc[_0x9b58('0x3c')]=_0x394bdc[_0x9b58('0x3c')][_0x9b58('0x3d')]?_0x394bdc[_0x9b58('0x3c')]:_0x274239[_0x9b58('0x37')];if(!_0xd941c['query'][_0x9b58('0x3e')]('nolimit')){_0x394bdc[_0x9b58('0x25')]=qs['limit'](_0xd941c['query']['limit']);_0x394bdc[_0x9b58('0x24')]=qs[_0x9b58('0x24')](_0xd941c[_0x9b58('0x38')][_0x9b58('0x24')]);}_0x394bdc[_0x9b58('0x3f')]=qs[_0x9b58('0x40')](_0xd941c[_0x9b58('0x38')][_0x9b58('0x40')]);_0x394bdc[_0x9b58('0x41')]=qs['filters'](_['pick'](_0xd941c[_0x9b58('0x38')],_0x274239[_0x9b58('0x42')]),_0x4cc743);if(_0xd941c[_0x9b58('0x38')][_0x9b58('0x43')]){_0x394bdc[_0x9b58('0x41')]=_[_0x9b58('0x44')](_0x394bdc[_0x9b58('0x41')],{'$or':_[_0x9b58('0x32')](_0x4cc743,function(_0x43e08c){if(_0x43e08c[_0x9b58('0x35')]!==_0x9b58('0x45')){var _0x511651={};_0x511651[_0x43e08c['name']]={'$like':'%'+_0xd941c[_0x9b58('0x38')]['filter']+'%'};return _0x511651;}})});}_0x394bdc=_['merge']({},_0x394bdc,_0xd941c['options']);var _0x385e80={'where':_0x394bdc[_0x9b58('0x41')]};return db[_0x9b58('0x33')][_0x9b58('0x23')](_0x385e80)['then'](function(_0x2094c4){_0x4fc38a['count']=_0x2094c4;if(_0xd941c[_0x9b58('0x38')][_0x9b58('0x46')]){_0x394bdc[_0x9b58('0x47')]=[{'all':!![]}];}return db[_0x9b58('0x33')][_0x9b58('0x48')](_0x394bdc);})[_0x9b58('0x2a')](function(_0x328384){_0x4fc38a[_0x9b58('0x49')]=_0x328384;return _0x4fc38a;})['then'](respondWithFilteredResult(_0x224d7e,_0x394bdc))[_0x9b58('0x4a')](handleError(_0x224d7e,null));};exports[_0x9b58('0x4b')]=function(_0x133d08,_0x413cbd){var _0x4d67a1={'raw':![],'where':{'id':_0x133d08[_0x9b58('0x4c')]['id']}},_0x38f243={};_0x38f243[_0x9b58('0x37')]=_[_0x9b58('0x39')](db[_0x9b58('0x33')][_0x9b58('0x34')]);_0x38f243[_0x9b58('0x38')]=_[_0x9b58('0x39')](_0x133d08['query']);_0x38f243['filters']=_[_0x9b58('0x3a')](_0x38f243[_0x9b58('0x37')],_0x38f243[_0x9b58('0x38')]);_0x4d67a1['attributes']=_[_0x9b58('0x3a')](_0x38f243['model'],qs[_0x9b58('0x3b')](_0x133d08[_0x9b58('0x38')]['fields']));_0x4d67a1['attributes']=_0x4d67a1['attributes']['length']?_0x4d67a1[_0x9b58('0x3c')]:_0x38f243[_0x9b58('0x37')];if(_0x133d08[_0x9b58('0x38')][_0x9b58('0x46')]){_0x4d67a1[_0x9b58('0x47')]=[{'all':!![]}];}_0x4d67a1=_[_0x9b58('0x44')]({},_0x4d67a1,_0x133d08[_0x9b58('0x4d')]);return db['Team'][_0x9b58('0x4e')](_0x4d67a1)['then'](handleEntityNotFound(_0x413cbd,null))[_0x9b58('0x2a')](respondWithResult(_0x413cbd,null))[_0x9b58('0x4a')](handleError(_0x413cbd,null));};exports[_0x9b58('0x4f')]=function(_0x557dd9,_0xee94b3){return db[_0x9b58('0x33')][_0x9b58('0x4f')](_0x557dd9[_0x9b58('0x50')],{})[_0x9b58('0x2a')](function(_0x117110){var _0x269bbc=_0x557dd9[_0x9b58('0x51')][_0x9b58('0x2c')]({'plain':!![]});if(!_0x269bbc)throw new Error(_0x9b58('0x52'));if(_0x269bbc[_0x9b58('0x53')]===_0x9b58('0x51')){var _0x29f330=_0x117110[_0x9b58('0x2c')]({'plain':!![]});var _0x10e0d8=_0x9b58('0x2d');return db[_0x9b58('0x54')][_0x9b58('0x4e')]({'where':{'name':_0x10e0d8,'userProfileId':_0x269bbc[_0x9b58('0x55')]},'raw':!![]})[_0x9b58('0x2a')](function(_0x38d8e1){if(_0x38d8e1&&_0x38d8e1[_0x9b58('0x56')]===0x0){return db[_0x9b58('0x57')][_0x9b58('0x4f')]({'name':_0x29f330[_0x9b58('0x2f')],'resourceId':_0x29f330['id'],'type':_0x38d8e1[_0x9b58('0x2f')],'sectionId':_0x38d8e1['id']},{})[_0x9b58('0x2a')](function(){return _0x117110;});}else{return _0x117110;}})[_0x9b58('0x4a')](function(_0x12e488){logger[_0x9b58('0x2e')](_0x9b58('0x58'),_0x12e488);throw _0x12e488;});}return _0x117110;})[_0x9b58('0x2a')](respondWithResult(_0xee94b3,0xc9))[_0x9b58('0x4a')](handleError(_0xee94b3,null));};exports['update']=function(_0x4caf73,_0x5308b3){if(_0x4caf73[_0x9b58('0x50')]['id']){delete _0x4caf73[_0x9b58('0x50')]['id'];}return db['Team'][_0x9b58('0x4e')]({'where':{'id':_0x4caf73[_0x9b58('0x4c')]['id']}})[_0x9b58('0x2a')](handleEntityNotFound(_0x5308b3,null))[_0x9b58('0x2a')](saveUpdates(_0x4caf73['body'],null))[_0x9b58('0x2a')](respondWithResult(_0x5308b3,null))[_0x9b58('0x4a')](handleError(_0x5308b3,null));};exports[_0x9b58('0x2b')]=function(_0x22b9e7,_0x3502a7){return db['Team']['find']({'where':{'id':_0x22b9e7[_0x9b58('0x4c')]['id']}})[_0x9b58('0x2a')](handleEntityNotFound(_0x3502a7,null))['then'](removeEntity(_0x3502a7,null))[_0x9b58('0x4a')](handleError(_0x3502a7,null));};exports[_0x9b58('0x59')]=function(_0x2fe974,_0x51971a,_0xa912fc){return db[_0x9b58('0x33')]['findOne']({'where':{'id':_0x2fe974[_0x9b58('0x4c')]['id']}})[_0x9b58('0x2a')](handleEntityNotFound(_0x51971a,null))[_0x9b58('0x2a')](function(_0x2085c2){if(!_0x2fe974[_0x9b58('0x38')]['channel']||!utils['isValidChannel'](_0x2fe974[_0x9b58('0x38')][_0x9b58('0x5a')])){throw new db['Sequelize'][(_0x9b58('0x5b'))](_0x9b58('0x5c'));}var _0x24592e={};var _0x4a1603={};_0x4a1603[_0x9b58('0x37')]=_[_0x9b58('0x39')](db[_[_0x9b58('0x5d')](_0x2fe974[_0x9b58('0x38')][_0x9b58('0x5a')]['toLowerCase']())+'Queue'][_0x9b58('0x34')]);_0x4a1603[_0x9b58('0x38')]=_[_0x9b58('0x39')](_0x2fe974[_0x9b58('0x38')]);_0x4a1603['filters']=_[_0x9b58('0x3a')](_0x4a1603[_0x9b58('0x37')],_0x4a1603[_0x9b58('0x38')]);_0x24592e['attributes']=_['intersection'](_0x4a1603[_0x9b58('0x37')],qs[_0x9b58('0x3b')](_0x2fe974[_0x9b58('0x38')][_0x9b58('0x3b')]));_0x24592e[_0x9b58('0x3c')]=_0x24592e[_0x9b58('0x3c')]['length']?_0x24592e[_0x9b58('0x3c')]:_0x4a1603['model'];_0x24592e[_0x9b58('0x25')]=qs['limit'](_0x2fe974[_0x9b58('0x38')]['limit']);_0x24592e[_0x9b58('0x24')]=qs['offset'](_0x2fe974[_0x9b58('0x38')]['offset']);_0x24592e['order']=qs[_0x9b58('0x40')](_0x2fe974[_0x9b58('0x38')][_0x9b58('0x40')]);_0x24592e['where']=qs[_0x9b58('0x42')](_[_0x9b58('0x5e')](_0x2fe974[_0x9b58('0x38')],_0x4a1603[_0x9b58('0x42')]));_0x24592e=_[_0x9b58('0x44')]({},_0x24592e,_0x2fe974['options']);return _0x2085c2[_0x9b58('0x2c')+_[_0x9b58('0x5d')](_0x2fe974[_0x9b58('0x38')][_0x9b58('0x5a')][_0x9b58('0x5f')]())+_0x9b58('0x60')](_0x24592e);})['then'](respondWithResult(_0x51971a,null))[_0x9b58('0x4a')](handleError(_0x51971a,null));};exports[_0x9b58('0x61')]=function(_0x139b94,_0x2911c9,_0x1b9974){return db[_0x9b58('0x33')][_0x9b58('0x62')]({'where':{'id':_0x139b94[_0x9b58('0x4c')]['id']}})[_0x9b58('0x2a')](function(_0x33d369){if(_0x33d369){if(!_0x139b94['body']['channel']||!utils['isValidChannel'](_0x139b94[_0x9b58('0x50')][_0x9b58('0x5a')])){throw new db['Sequelize'][(_0x9b58('0x5b'))](_0x9b58('0x5c'));}return _0x33d369['add'+_[_0x9b58('0x5d')](_0x139b94[_0x9b58('0x50')][_0x9b58('0x5a')][_0x9b58('0x5f')]())+_0x9b58('0x60')](_0x139b94[_0x9b58('0x50')][_0x9b58('0x63')]);}return null;})[_0x9b58('0x2a')](handleEntityNotFound(_0x2911c9,null))['then'](respondWithStatusCode(_0x2911c9,null))[_0x9b58('0x4a')](handleError(_0x2911c9,null));};exports[_0x9b58('0x64')]=function(_0x53273c,_0x37b6a1,_0x5ab681){return db['Team'][_0x9b58('0x62')]({'where':{'id':_0x53273c['params']['id']}})[_0x9b58('0x2a')](function(_0x23a24c){if(_0x23a24c){if(!_0x53273c[_0x9b58('0x38')]['channel']||!utils['isValidChannel'](_0x53273c[_0x9b58('0x38')][_0x9b58('0x5a')])){throw new db[(_0x9b58('0x65'))][(_0x9b58('0x5b'))]('Unknown\x20channel');}return _0x23a24c[_0x9b58('0x66')+_[_0x9b58('0x5d')](_0x53273c[_0x9b58('0x38')][_0x9b58('0x5a')][_0x9b58('0x5f')]())+'Queues'](_0x53273c[_0x9b58('0x38')]['ids']);}return null;})[_0x9b58('0x2a')](handleEntityNotFound(_0x37b6a1,null))['then'](respondWithStatusCode(_0x37b6a1,null))[_0x9b58('0x4a')](handleError(_0x37b6a1,null));};exports[_0x9b58('0x67')]=function(_0x5296cb,_0x4a85a3){return db[_0x9b58('0x33')][_0x9b58('0x4e')]({'where':{'id':_0x5296cb['params']['id']}})[_0x9b58('0x2a')](handleEntityNotFound(_0x4a85a3,null))[_0x9b58('0x2a')](function(_0x5053be){if(_0x5053be){var _0x47351b=[_0x9b58('0x68'),_0x9b58('0x69'),_0x9b58('0x6a'),_0x9b58('0x6b'),_0x9b58('0x6c'),'Openchannel','Whatsapp'];return db[_0x9b58('0x6d')][_0x9b58('0x6e')](function(_0x37fc26){var _0x4b45b8=_['map'](_0x47351b,function(_0xcb5caf){var _0x39553d={'attributes':['id','name']};if(_0xcb5caf===_0x9b58('0x68')){_0x39553d[_0x9b58('0x6f')]={'attributes':[_0x9b58('0x70')]};}return _0x5053be['get'+_0xcb5caf+_0x9b58('0x60')](_0x39553d)[_0x9b58('0x2a')](function(_0x25a5ed){var _0x52b4da=_[_0x9b58('0x32')](_0x25a5ed,function(_0x153ff2){var _0x4ccfff=_[_0x9b58('0x32')](_0x5296cb[_0x9b58('0x50')][_0x9b58('0x63')],function(_0x5a29a5){var _0x35e30e={'where':{'UserId':_0x5a29a5,[_0xcb5caf+'QueueId']:_0x153ff2['id']},'transaction':_0x37fc26};if(_0xcb5caf===_0x9b58('0x68')){_0x35e30e[_0x9b58('0x1c')]={'penalty':_0x153ff2[_0x9b58('0x71')]['penalty']};}return db[_0x9b58('0x72')+_0xcb5caf+_0x9b58('0x73')][_0x9b58('0x74')](_0x35e30e)[_0x9b58('0x2a')](function(){socket[_0x9b58('0x75')](_0x9b58('0x51')+_0xcb5caf+_0x9b58('0x76'),{'UserId':_0x5a29a5,[_0xcb5caf+_0x9b58('0x77')]:_0x153ff2['id']});if(_0xcb5caf!==_0x9b58('0x68'))return;return db[_0x9b58('0x72')][_0x9b58('0x48')]({'where':{'id':_0x5296cb[_0x9b58('0x50')]['ids'],'online':0x1},'attributes':['id','name',_0x9b58('0x78'),_0x9b58('0x79'),_0x9b58('0x7a')],'raw':!![]})[_0x9b58('0x2a')](function(_0x4ad51d){var _0x595393=_[_0x9b58('0x32')](_0x4ad51d,function(_0x5d6eae){return db[_0x9b58('0x7b')][_0x9b58('0x7c')]({'membername':_0x5d6eae['name'],'UserId':_0x5d6eae['id'],'queue_name':_0x153ff2[_0x9b58('0x2f')],'VoiceQueueId':_0x153ff2['id'],'interface':_[_0x9b58('0x7d')](_0x5d6eae[_0x9b58('0x7a')])?util[_0x9b58('0x7e')](_0x9b58('0x7f'),_0x5d6eae[_0x9b58('0x2f')]):_0x5d6eae['interface'],'paused':_0x5d6eae[_0x9b58('0x79')]||![],'penalty':_0x153ff2['TeamVoiceQueue'][_0x9b58('0x70')]},{'transaction':_0x37fc26});});return Promise[_0x9b58('0x80')](_0x595393);});});});return Promise[_0x9b58('0x80')](_0x4ccfff);});return Promise[_0x9b58('0x80')](_0x52b4da);});});return Promise['all'](_0x4b45b8)[_0x9b58('0x2a')](function(){return _0x5053be[_0x9b58('0x67')](_0x5296cb[_0x9b58('0x50')][_0x9b58('0x63')],{'transaction':_0x37fc26})[_0x9b58('0x81')](function(_0x58a3fb){return _0x58a3fb;});});});}})[_0x9b58('0x2a')](respondWithResult(_0x4a85a3,null))[_0x9b58('0x4a')](handleError(_0x4a85a3,null));};exports[_0x9b58('0x82')]=function(_0x1a5306,_0x20205f){return db[_0x9b58('0x33')]['find']({'where':{'id':_0x1a5306[_0x9b58('0x4c')]['id']}})[_0x9b58('0x2a')](handleEntityNotFound(_0x20205f,null))[_0x9b58('0x2a')](function(_0xfc0f39){if(_0xfc0f39){var _0x460cbf=[_0x9b58('0x68'),_0x9b58('0x69'),_0x9b58('0x6a'),_0x9b58('0x6b'),_0x9b58('0x6c'),_0x9b58('0x83'),_0x9b58('0x84')];return db[_0x9b58('0x6d')]['transaction'](function(_0x172d59){var _0x5e6a4d=_['map'](_0x460cbf,function(_0xd6c0a6){var _0x3430b6={'attributes':['id',_0x9b58('0x2f')]};return _0xfc0f39[_0x9b58('0x2c')+_0xd6c0a6+'Queues'](_0x3430b6)['then'](function(_0x1b775a){var _0x515ab4=_[_0x9b58('0x32')](_0x1b775a,function(_0x214fb6){return _0x214fb6[_0x9b58('0x82')](_0x1a5306[_0x9b58('0x38')][_0x9b58('0x63')],{'transaction':_0x172d59})['then'](function(){var _0xa2d373=JSON[_0x9b58('0x85')]('['+_0x1a5306[_0x9b58('0x38')][_0x9b58('0x63')]+']');var _0x580c84=_['map'](_0xa2d373,function(_0x4aab5c){socket[_0x9b58('0x75')]('user'+_0xd6c0a6+_0x9b58('0x86'),{'UserId':Number(_0x4aab5c),[_0xd6c0a6+'QueueId']:_0x214fb6['id']});if(_0xd6c0a6!==_0x9b58('0x68'))return;return db[_0x9b58('0x7b')][_0x9b58('0x2b')]({'where':{'VoiceQueueId':_0x214fb6['id'],'UserId':_0x4aab5c},'transaction':_0x172d59});});return Promise[_0x9b58('0x80')](_0x580c84);});});return Promise[_0x9b58('0x80')](_0x515ab4);});});return Promise[_0x9b58('0x80')](_0x5e6a4d)[_0x9b58('0x2a')](function(){return _0xfc0f39['removeAgents'](_0x1a5306['query']['ids'],{'transaction':_0x172d59});});});}})[_0x9b58('0x2a')](respondWithStatusCode(_0x20205f,null))[_0x9b58('0x4a')](handleError(_0x20205f,null));};exports[_0x9b58('0x87')]=function(_0x403c22,_0x33b08d,_0x1dd207){var _0x4e0926={};var _0xca2a80={};var _0x2f55e1;var _0x37498f;return db[_0x9b58('0x33')][_0x9b58('0x62')]({'where':{'id':_0x403c22['params']['id']}})[_0x9b58('0x2a')](handleEntityNotFound(_0x33b08d,null))[_0x9b58('0x2a')](function(_0x156650){if(_0x156650){_0x2f55e1=_0x156650;_0xca2a80[_0x9b58('0x37')]=_['keys'](db[_0x9b58('0x72')]['rawAttributes']);_0xca2a80['query']=_[_0x9b58('0x39')](_0x403c22[_0x9b58('0x38')]);_0xca2a80['filters']=_['intersection'](_0xca2a80['model'],_0xca2a80['query']);_0x4e0926[_0x9b58('0x3c')]=_[_0x9b58('0x3a')](_0xca2a80['model'],qs['fields'](_0x403c22[_0x9b58('0x38')][_0x9b58('0x3b')]));_0x4e0926[_0x9b58('0x3c')]=_0x4e0926[_0x9b58('0x3c')]['length']?_0x4e0926[_0x9b58('0x3c')]:_0xca2a80[_0x9b58('0x37')];_0x4e0926[_0x9b58('0x3f')]=qs['sort'](_0x403c22['query']['sort']);_0x4e0926['where']=qs[_0x9b58('0x42')](_[_0x9b58('0x5e')](_0x403c22[_0x9b58('0x38')],_0xca2a80[_0x9b58('0x42')]));if(_0x403c22[_0x9b58('0x38')]['filter']){_0x4e0926['where']=_[_0x9b58('0x44')](_0x4e0926[_0x9b58('0x41')],{'$or':_[_0x9b58('0x32')](_0x4e0926[_0x9b58('0x3c')],function(_0x571011){var _0x1cb032={};_0x1cb032[_0x571011]={'$like':'%'+_0x403c22['query'][_0x9b58('0x43')]+'%'};return _0x1cb032;})});}_0x4e0926=_['merge']({},_0x4e0926,_0x403c22[_0x9b58('0x4d')]);return _0x2f55e1[_0x9b58('0x87')](_0x4e0926);}})[_0x9b58('0x2a')](function(_0x573f80){if(_0x573f80){_0x37498f=_0x573f80[_0x9b58('0x3d')];if(!_0x403c22['query'][_0x9b58('0x3e')](_0x9b58('0x88'))){_0x4e0926[_0x9b58('0x25')]=qs['limit'](_0x403c22[_0x9b58('0x38')][_0x9b58('0x25')]);_0x4e0926[_0x9b58('0x24')]=qs[_0x9b58('0x24')](_0x403c22[_0x9b58('0x38')]['offset']);}return _0x2f55e1[_0x9b58('0x87')](_0x4e0926);}})['then'](function(_0x3ff157){if(_0x3ff157){return _0x3ff157?{'count':_0x37498f,'rows':_0x3ff157}:null;}})[_0x9b58('0x2a')](respondWithResult(_0x33b08d,null))[_0x9b58('0x4a')](handleError(_0x33b08d,null));};