6c541e20f905a9e011ffe8cd54fcc0559550c62b
[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 _0xed21=['sendStatus','error','stack','name','send','map','Team','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','order','sort','where','pick','filter','merge','options','includeAll','include','findAll','rows','catch','params','rawAttributes','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','getQueues','findOne','channel','Sequelize','ValidationError','Queue','length','capitalize','toLowerCase','Queues','addQueues','isValidChannel','Unknown\x20channel','removeQueues','remove','Voice','Chat','Mail','Sms','Whatsapp','each','ids','User','online','voicePause','isNil','SIP/%s','interface','addAgents','spread','emit','userTeam:save','removeAgents','chat','mail','sms','openchannel','UserVoiceQueueRt','isArray','userTeam:remove','getAgents','nolimit','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','util','path','sox','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','register','end','status','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','get','UserProfileResource'];(function(_0x56fb5e,_0x1f08a5){var _0x49c705=function(_0x96d1ae){while(--_0x96d1ae){_0x56fb5e['push'](_0x56fb5e['shift']());}};_0x49c705(++_0x1f08a5);}(_0xed21,0x14d));var _0x1ed2=function(_0x909030,_0x175d21){_0x909030=_0x909030-0x0;var _0x238cdd=_0xed21[_0x909030];return _0x238cdd;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x1ed2('0x0'));var rimraf=require(_0x1ed2('0x1'));var zipdir=require(_0x1ed2('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x1ed2('0x3'));var moment=require(_0x1ed2('0x4'));var BPromise=require(_0x1ed2('0x5'));var Mustache=require('mustache');var util=require(_0x1ed2('0x6'));var path=require(_0x1ed2('0x7'));var sox=require(_0x1ed2('0x8'));var csv=require('to-csv');var ejs=require(_0x1ed2('0x9'));var fs=require('fs');var _=require(_0x1ed2('0xa'));var squel=require(_0x1ed2('0xb'));var crypto=require(_0x1ed2('0xc'));var jsforce=require(_0x1ed2('0xd'));var deskjs=require(_0x1ed2('0xe'));var toCsv=require('to-csv');var querystring=require(_0x1ed2('0xf'));var Papa=require(_0x1ed2('0x10'));var Redis=require(_0x1ed2('0x11'));var authService=require(_0x1ed2('0x12'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x1ed2('0x13'));var logger=require(_0x1ed2('0x14'))('api');var utils=require(_0x1ed2('0x15'));var config=require(_0x1ed2('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0x1ed2('0x17'))['db'];config[_0x1ed2('0x18')]=_[_0x1ed2('0x19')](config[_0x1ed2('0x18')],{'host':_0x1ed2('0x1a'),'port':0x18eb});var socket=require(_0x1ed2('0x1b'))(new Redis(config[_0x1ed2('0x18')]));require('./team.socket')[_0x1ed2('0x1c')](socket);function respondWithStatusCode(_0x4c2c1d,_0x964dc5){_0x964dc5=_0x964dc5||0xcc;return function(_0x41845a){if(_0x41845a){return _0x4c2c1d['sendStatus'](_0x964dc5);}return _0x4c2c1d['status'](_0x964dc5)[_0x1ed2('0x1d')]();};}function respondWithResult(_0x778370,_0x77d90a){_0x77d90a=_0x77d90a||0xc8;return function(_0x2fd1cc){if(_0x2fd1cc){return _0x778370[_0x1ed2('0x1e')](_0x77d90a)[_0x1ed2('0x1f')](_0x2fd1cc);}};}function respondWithFilteredResult(_0x6c7878,_0x559c25){return function(_0x559903){if(_0x559903){var _0x52fb81=_0x559903[_0x1ed2('0x20')],_0x5ac5a5=_0x559c25['offset'],_0x2f8bd6=_0x559c25[_0x1ed2('0x21')]+_0x559c25[_0x1ed2('0x22')],_0x1ac1c4;if(_0x2f8bd6>=_0x52fb81){_0x2f8bd6=_0x52fb81;_0x1ac1c4=0xc8;}else{_0x1ac1c4=0xce;}_0x6c7878[_0x1ed2('0x1e')](_0x1ac1c4);return _0x6c7878[_0x1ed2('0x23')](_0x1ed2('0x24'),_0x5ac5a5+'-'+_0x2f8bd6+'/'+_0x52fb81)['json'](_0x559903);}return null;};}function patchUpdates(_0x37707f){return function(_0x43193c){try{jsonpatch[_0x1ed2('0x25')](_0x43193c,_0x37707f,!![]);}catch(_0x2d0aaf){return BPromise[_0x1ed2('0x26')](_0x2d0aaf);}return _0x43193c[_0x1ed2('0x27')]();};}function saveUpdates(_0x1f928a,_0x3a6194){return function(_0x44a10b){if(_0x44a10b){return _0x44a10b[_0x1ed2('0x28')](_0x1f928a)[_0x1ed2('0x29')](function(_0x2c1891){return _0x2c1891;});}return null;};}function removeEntity(_0x3c3084,_0x1445c1){return function(_0x58e6b8){if(_0x58e6b8){return _0x58e6b8[_0x1ed2('0x2a')]()[_0x1ed2('0x29')](function(){var _0x588512=_0x58e6b8[_0x1ed2('0x2b')]({'plain':!![]});var _0x180243='Teams';return db[_0x1ed2('0x2c')][_0x1ed2('0x2a')]({'where':{'type':_0x180243,'resourceId':_0x588512['id']}})[_0x1ed2('0x29')](function(){return _0x58e6b8;});})[_0x1ed2('0x29')](function(){_0x3c3084[_0x1ed2('0x1e')](0xcc)[_0x1ed2('0x1d')]();});}};}function handleEntityNotFound(_0x53ba41,_0x133ef2){return function(_0x378ed8){if(!_0x378ed8){_0x53ba41[_0x1ed2('0x2d')](0x194);}return _0x378ed8;};}function handleError(_0x20d628,_0x16619e){_0x16619e=_0x16619e||0x1f4;return function(_0x55e44f){logger[_0x1ed2('0x2e')](_0x55e44f[_0x1ed2('0x2f')]);if(_0x55e44f[_0x1ed2('0x30')]){delete _0x55e44f[_0x1ed2('0x30')];}_0x20d628[_0x1ed2('0x1e')](_0x16619e)[_0x1ed2('0x31')](_0x55e44f);};}exports['index']=function(_0x2c666c,_0x189de9){var _0x40fb02={},_0x4966ac={},_0x1c1450={'count':0x0,'rows':[]};var _0x12b11d=_[_0x1ed2('0x32')](db[_0x1ed2('0x33')]['rawAttributes'],function(_0x45383e){return{'name':_0x45383e[_0x1ed2('0x34')],'type':_0x45383e[_0x1ed2('0x35')][_0x1ed2('0x36')]};});_0x4966ac[_0x1ed2('0x37')]=_[_0x1ed2('0x32')](_0x12b11d,_0x1ed2('0x30'));_0x4966ac[_0x1ed2('0x38')]=_[_0x1ed2('0x39')](_0x2c666c[_0x1ed2('0x38')]);_0x4966ac[_0x1ed2('0x3a')]=_[_0x1ed2('0x3b')](_0x4966ac[_0x1ed2('0x37')],_0x4966ac[_0x1ed2('0x38')]);_0x40fb02[_0x1ed2('0x3c')]=_[_0x1ed2('0x3b')](_0x4966ac['model'],qs[_0x1ed2('0x3d')](_0x2c666c[_0x1ed2('0x38')][_0x1ed2('0x3d')]));_0x40fb02[_0x1ed2('0x3c')]=_0x40fb02[_0x1ed2('0x3c')]['length']?_0x40fb02[_0x1ed2('0x3c')]:_0x4966ac[_0x1ed2('0x37')];if(!_0x2c666c[_0x1ed2('0x38')][_0x1ed2('0x3e')]('nolimit')){_0x40fb02[_0x1ed2('0x22')]=qs[_0x1ed2('0x22')](_0x2c666c[_0x1ed2('0x38')][_0x1ed2('0x22')]);_0x40fb02[_0x1ed2('0x21')]=qs['offset'](_0x2c666c[_0x1ed2('0x38')][_0x1ed2('0x21')]);}_0x40fb02[_0x1ed2('0x3f')]=qs['sort'](_0x2c666c[_0x1ed2('0x38')][_0x1ed2('0x40')]);_0x40fb02[_0x1ed2('0x41')]=qs['filters'](_[_0x1ed2('0x42')](_0x2c666c[_0x1ed2('0x38')],_0x4966ac[_0x1ed2('0x3a')]),_0x12b11d);if(_0x2c666c[_0x1ed2('0x38')][_0x1ed2('0x43')]){_0x40fb02['where']=_['merge'](_0x40fb02[_0x1ed2('0x41')],{'$or':_[_0x1ed2('0x32')](_0x12b11d,function(_0x5ce84f){if(_0x5ce84f['type']!=='VIRTUAL'){var _0x4bbee1={};_0x4bbee1[_0x5ce84f[_0x1ed2('0x30')]]={'$like':'%'+_0x2c666c['query'][_0x1ed2('0x43')]+'%'};return _0x4bbee1;}})});}_0x40fb02=_[_0x1ed2('0x44')]({},_0x40fb02,_0x2c666c[_0x1ed2('0x45')]);var _0x204314={'where':_0x40fb02[_0x1ed2('0x41')]};return db['Team'][_0x1ed2('0x20')](_0x204314)[_0x1ed2('0x29')](function(_0x3c4044){_0x1c1450[_0x1ed2('0x20')]=_0x3c4044;if(_0x2c666c[_0x1ed2('0x38')][_0x1ed2('0x46')]){_0x40fb02[_0x1ed2('0x47')]=[{'all':!![]}];}return db[_0x1ed2('0x33')][_0x1ed2('0x48')](_0x40fb02);})[_0x1ed2('0x29')](function(_0x1a8853){_0x1c1450[_0x1ed2('0x49')]=_0x1a8853;return _0x1c1450;})[_0x1ed2('0x29')](respondWithFilteredResult(_0x189de9,_0x40fb02))[_0x1ed2('0x4a')](handleError(_0x189de9,null));};exports['show']=function(_0x34393e,_0x4e4c90){var _0x4f2adb={'raw':![],'where':{'id':_0x34393e[_0x1ed2('0x4b')]['id']}},_0x1909c8={};_0x1909c8[_0x1ed2('0x37')]=_[_0x1ed2('0x39')](db['Team'][_0x1ed2('0x4c')]);_0x1909c8['query']=_[_0x1ed2('0x39')](_0x34393e['query']);_0x1909c8['filters']=_[_0x1ed2('0x3b')](_0x1909c8['model'],_0x1909c8[_0x1ed2('0x38')]);_0x4f2adb[_0x1ed2('0x3c')]=_[_0x1ed2('0x3b')](_0x1909c8[_0x1ed2('0x37')],qs['fields'](_0x34393e[_0x1ed2('0x38')]['fields']));_0x4f2adb['attributes']=_0x4f2adb['attributes']['length']?_0x4f2adb[_0x1ed2('0x3c')]:_0x1909c8[_0x1ed2('0x37')];if(_0x34393e['query'][_0x1ed2('0x46')]){_0x4f2adb[_0x1ed2('0x47')]=[{'all':!![]}];}_0x4f2adb=_[_0x1ed2('0x44')]({},_0x4f2adb,_0x34393e[_0x1ed2('0x45')]);return db[_0x1ed2('0x33')][_0x1ed2('0x4d')](_0x4f2adb)['then'](handleEntityNotFound(_0x4e4c90,null))[_0x1ed2('0x29')](respondWithResult(_0x4e4c90,null))['catch'](handleError(_0x4e4c90,null));};exports[_0x1ed2('0x4e')]=function(_0x3f1cb3,_0x54c666){return db[_0x1ed2('0x33')][_0x1ed2('0x4e')](_0x3f1cb3[_0x1ed2('0x4f')],{})['then'](function(_0xda0703){var _0x39d59c=_0x3f1cb3[_0x1ed2('0x50')][_0x1ed2('0x2b')]({'plain':!![]});if(!_0x39d59c)throw new Error(_0x1ed2('0x51'));if(_0x39d59c['role']===_0x1ed2('0x50')){var _0x10ecb2=_0xda0703['get']({'plain':!![]});var _0x5c1612='Teams';return db['UserProfileSection'][_0x1ed2('0x4d')]({'where':{'name':_0x5c1612,'userProfileId':_0x39d59c['userProfileId']},'raw':!![]})['then'](function(_0x593451){if(_0x593451&&_0x593451[_0x1ed2('0x52')]===0x0){return db[_0x1ed2('0x2c')][_0x1ed2('0x4e')]({'name':_0x10ecb2[_0x1ed2('0x30')],'resourceId':_0x10ecb2['id'],'type':_0x593451['name'],'sectionId':_0x593451['id']},{})[_0x1ed2('0x29')](function(){return _0xda0703;});}else{return _0xda0703;}})[_0x1ed2('0x4a')](function(_0x5f175d){logger[_0x1ed2('0x2e')](_0x1ed2('0x53'),_0x5f175d);throw _0x5f175d;});}return _0xda0703;})[_0x1ed2('0x29')](respondWithResult(_0x54c666,0xc9))[_0x1ed2('0x4a')](handleError(_0x54c666,null));};exports['update']=function(_0x46d8d4,_0x59bfa9){if(_0x46d8d4['body']['id']){delete _0x46d8d4[_0x1ed2('0x4f')]['id'];}return db[_0x1ed2('0x33')][_0x1ed2('0x4d')]({'where':{'id':_0x46d8d4[_0x1ed2('0x4b')]['id']}})[_0x1ed2('0x29')](handleEntityNotFound(_0x59bfa9,null))['then'](saveUpdates(_0x46d8d4['body'],null))[_0x1ed2('0x29')](respondWithResult(_0x59bfa9,null))[_0x1ed2('0x4a')](handleError(_0x59bfa9,null));};exports[_0x1ed2('0x2a')]=function(_0x36a74d,_0x5681d9){return db[_0x1ed2('0x33')][_0x1ed2('0x4d')]({'where':{'id':_0x36a74d[_0x1ed2('0x4b')]['id']}})[_0x1ed2('0x29')](handleEntityNotFound(_0x5681d9,null))[_0x1ed2('0x29')](removeEntity(_0x5681d9,null))['catch'](handleError(_0x5681d9,null));};exports[_0x1ed2('0x54')]=function(_0xa8e836,_0x2c9ed1,_0xda8511){return db['Team'][_0x1ed2('0x55')]({'where':{'id':_0xa8e836[_0x1ed2('0x4b')]['id']}})[_0x1ed2('0x29')](handleEntityNotFound(_0x2c9ed1,null))[_0x1ed2('0x29')](function(_0x59fce6){if(!_0xa8e836['query'][_0x1ed2('0x56')]||!utils['isValidChannel'](_0xa8e836[_0x1ed2('0x38')][_0x1ed2('0x56')])){throw new db[(_0x1ed2('0x57'))][(_0x1ed2('0x58'))]('Unknown\x20channel');}var _0x1b7e39={};var _0x143b49={};_0x143b49[_0x1ed2('0x37')]=_[_0x1ed2('0x39')](db[_['capitalize'](_0xa8e836['query'][_0x1ed2('0x56')]['toLowerCase']())+_0x1ed2('0x59')]['rawAttributes']);_0x143b49[_0x1ed2('0x38')]=_[_0x1ed2('0x39')](_0xa8e836[_0x1ed2('0x38')]);_0x143b49['filters']=_['intersection'](_0x143b49['model'],_0x143b49[_0x1ed2('0x38')]);_0x1b7e39[_0x1ed2('0x3c')]=_[_0x1ed2('0x3b')](_0x143b49[_0x1ed2('0x37')],qs[_0x1ed2('0x3d')](_0xa8e836[_0x1ed2('0x38')][_0x1ed2('0x3d')]));_0x1b7e39[_0x1ed2('0x3c')]=_0x1b7e39[_0x1ed2('0x3c')][_0x1ed2('0x5a')]?_0x1b7e39[_0x1ed2('0x3c')]:_0x143b49[_0x1ed2('0x37')];_0x1b7e39[_0x1ed2('0x22')]=qs[_0x1ed2('0x22')](_0xa8e836[_0x1ed2('0x38')][_0x1ed2('0x22')]);_0x1b7e39[_0x1ed2('0x21')]=qs[_0x1ed2('0x21')](_0xa8e836[_0x1ed2('0x38')][_0x1ed2('0x21')]);_0x1b7e39['order']=qs[_0x1ed2('0x40')](_0xa8e836[_0x1ed2('0x38')]['sort']);_0x1b7e39[_0x1ed2('0x41')]=qs[_0x1ed2('0x3a')](_[_0x1ed2('0x42')](_0xa8e836[_0x1ed2('0x38')],_0x143b49['filters']));_0x1b7e39=_[_0x1ed2('0x44')]({},_0x1b7e39,_0xa8e836[_0x1ed2('0x45')]);return _0x59fce6[_0x1ed2('0x2b')+_[_0x1ed2('0x5b')](_0xa8e836['query'][_0x1ed2('0x56')][_0x1ed2('0x5c')]())+_0x1ed2('0x5d')](_0x1b7e39);})[_0x1ed2('0x29')](respondWithResult(_0x2c9ed1,null))[_0x1ed2('0x4a')](handleError(_0x2c9ed1,null));};exports[_0x1ed2('0x5e')]=function(_0x23c445,_0x12e336,_0x5f4b2d){return db[_0x1ed2('0x33')]['findOne']({'where':{'id':_0x23c445[_0x1ed2('0x4b')]['id']}})[_0x1ed2('0x29')](function(_0x38ecce){if(_0x38ecce){if(!_0x23c445[_0x1ed2('0x4f')][_0x1ed2('0x56')]||!utils[_0x1ed2('0x5f')](_0x23c445[_0x1ed2('0x4f')][_0x1ed2('0x56')])){throw new db[(_0x1ed2('0x57'))]['ValidationError'](_0x1ed2('0x60'));}return _0x38ecce['add'+_[_0x1ed2('0x5b')](_0x23c445[_0x1ed2('0x4f')][_0x1ed2('0x56')][_0x1ed2('0x5c')]())+'Queues'](_0x23c445[_0x1ed2('0x4f')]['ids']);}return null;})[_0x1ed2('0x29')](handleEntityNotFound(_0x12e336,null))[_0x1ed2('0x29')](respondWithStatusCode(_0x12e336,null))[_0x1ed2('0x4a')](handleError(_0x12e336,null));};exports[_0x1ed2('0x61')]=function(_0x19a3e9,_0x35d3d9,_0x41466f){return db[_0x1ed2('0x33')][_0x1ed2('0x55')]({'where':{'id':_0x19a3e9[_0x1ed2('0x4b')]['id']}})[_0x1ed2('0x29')](function(_0x3cf7e1){if(_0x3cf7e1){if(!_0x19a3e9[_0x1ed2('0x38')][_0x1ed2('0x56')]||!utils['isValidChannel'](_0x19a3e9[_0x1ed2('0x38')]['channel'])){throw new db[(_0x1ed2('0x57'))][(_0x1ed2('0x58'))](_0x1ed2('0x60'));}return _0x3cf7e1[_0x1ed2('0x62')+_['capitalize'](_0x19a3e9['query']['channel'][_0x1ed2('0x5c')]())+_0x1ed2('0x5d')](_0x19a3e9['query']['ids']);}return null;})[_0x1ed2('0x29')](handleEntityNotFound(_0x35d3d9,null))[_0x1ed2('0x29')](respondWithStatusCode(_0x35d3d9,null))[_0x1ed2('0x4a')](handleError(_0x35d3d9,null));};exports['addAgents']=function(_0x42957a,_0x5d3f51,_0xb6fe36){return db[_0x1ed2('0x33')][_0x1ed2('0x4d')]({'where':{'id':_0x42957a[_0x1ed2('0x4b')]['id']}})[_0x1ed2('0x29')](handleEntityNotFound(_0x5d3f51,null))[_0x1ed2('0x29')](function(_0x21c49c){if(_0x21c49c){var _0x4bae59=[_0x1ed2('0x63'),_0x1ed2('0x64'),_0x1ed2('0x65'),_0x1ed2('0x66'),'Fax','Openchannel',_0x1ed2('0x67')];return BPromise[_0x1ed2('0x68')](_0x4bae59,function(_0x2f1f70){return _0x21c49c[_0x1ed2('0x2b')+_0x2f1f70+_0x1ed2('0x5d')]({'attributes':['id',_0x1ed2('0x30')]})[_0x1ed2('0x29')](function(_0x4b4e35){return BPromise['each'](_0x4b4e35,function(_0x64d54e){return _0x64d54e['addAgents'](_0x42957a['body'][_0x1ed2('0x69')])['then'](function(){if(_0x2f1f70===_0x1ed2('0x63')){return db[_0x1ed2('0x6a')][_0x1ed2('0x48')]({'where':{'id':_0x42957a['body']['ids']},'attributes':['id',_0x1ed2('0x30'),_0x1ed2('0x6b'),_0x1ed2('0x6c'),'interface'],'raw':!![]})[_0x1ed2('0x29')](function(_0x40eb30){return BPromise['each'](_[_0x1ed2('0x43')](_0x40eb30,{'online':0x1}),function(_0x53c6d2){return db['UserVoiceQueueRt']['upsert']({'membername':_0x53c6d2[_0x1ed2('0x30')],'UserId':_0x53c6d2['id'],'queue_name':_0x64d54e[_0x1ed2('0x30')],'VoiceQueueId':_0x64d54e['id'],'interface':_[_0x1ed2('0x6d')](_0x53c6d2['interface'])?util['format'](_0x1ed2('0x6e'),_0x53c6d2[_0x1ed2('0x30')]):_0x53c6d2[_0x1ed2('0x6f')],'paused':_0x53c6d2[_0x1ed2('0x6c')]||![],'penalty':0x0});});});}});});})[_0x1ed2('0x29')](function(){return _0x21c49c;});})[_0x1ed2('0x29')](function(){return _0x21c49c;});}})[_0x1ed2('0x29')](function(_0x3af8f0){if(_0x3af8f0){return _0x3af8f0[_0x1ed2('0x70')](_0x42957a['body']['ids'],_['omit'](_0x42957a[_0x1ed2('0x4f')],[_0x1ed2('0x69'),'id'])||{})[_0x1ed2('0x71')](function(_0x259136){for(var _0x476e05=0x0;_0x476e05<_0x42957a['body'][_0x1ed2('0x69')][_0x1ed2('0x5a')];_0x476e05+=0x1){socket[_0x1ed2('0x72')](_0x1ed2('0x73'),{'UserId':_0x42957a[_0x1ed2('0x4f')]['ids'][_0x476e05],'TeamId':_0x42957a['params']['id']});}return _0x259136;});}})[_0x1ed2('0x29')](respondWithResult(_0x5d3f51,null))[_0x1ed2('0x4a')](handleError(_0x5d3f51,null));};exports[_0x1ed2('0x74')]=function(_0x54ee6b,_0x39e984,_0x5c6f56){return db[_0x1ed2('0x33')][_0x1ed2('0x4d')]({'where':{'id':_0x54ee6b[_0x1ed2('0x4b')]['id']}})['then'](handleEntityNotFound(_0x39e984,null))[_0x1ed2('0x29')](function(_0x472a5b){if(_0x472a5b){return BPromise['each'](['voice',_0x1ed2('0x75'),_0x1ed2('0x76'),_0x1ed2('0x77'),'fax',_0x1ed2('0x78'),'whatsapp'],function(_0x50e704){return _0x472a5b[_0x1ed2('0x2b')+_['capitalize'](_0x50e704)+_0x1ed2('0x5d')]({'attributes':['id',_0x1ed2('0x30')]})['then'](function(_0x34e3d3){return BPromise[_0x1ed2('0x68')](_0x34e3d3,function(_0x18a07d){return _0x18a07d[_0x1ed2('0x74')](_0x54ee6b[_0x1ed2('0x38')][_0x1ed2('0x69')])[_0x1ed2('0x29')](function(){if(_0x50e704==='voice'){return db[_0x1ed2('0x79')]['destroy']({'where':{'VoiceQueueId':_0x18a07d['id'],'UserId':_0x54ee6b['query'][_0x1ed2('0x69')]}});}});});})['then'](function(){return _0x472a5b;});})[_0x1ed2('0x29')](function(){return _0x472a5b;});}})['then'](function(_0x5e7c91){if(_0x5e7c91){return _0x5e7c91['removeAgents'](_0x54ee6b[_0x1ed2('0x38')][_0x1ed2('0x69')])[_0x1ed2('0x29')](function(){if(_[_0x1ed2('0x7a')](_0x54ee6b[_0x1ed2('0x38')][_0x1ed2('0x69')])){for(var _0x4762fd=0x0;_0x4762fd<_0x54ee6b['query'][_0x1ed2('0x69')][_0x1ed2('0x5a')];_0x4762fd+=0x1){socket[_0x1ed2('0x72')](_0x1ed2('0x7b'),{'UserId':Number(_0x54ee6b[_0x1ed2('0x38')][_0x1ed2('0x69')][_0x4762fd]),'TeamId':Number(_0x54ee6b[_0x1ed2('0x4b')]['id'])});}}else{socket[_0x1ed2('0x72')](_0x1ed2('0x7b'),{'UserId':Number(_0x54ee6b[_0x1ed2('0x38')][_0x1ed2('0x69')]),'TeamId':Number(_0x54ee6b[_0x1ed2('0x4b')]['id'])});}});}})[_0x1ed2('0x29')](respondWithStatusCode(_0x39e984,null))[_0x1ed2('0x4a')](handleError(_0x39e984,null));};exports['getAgents']=function(_0x5d50b2,_0x1f77b5,_0x2520ff){var _0x50b9ca={};var _0x20c2f9={};var _0x55cf5c;var _0x301a50;return db[_0x1ed2('0x33')][_0x1ed2('0x55')]({'where':{'id':_0x5d50b2[_0x1ed2('0x4b')]['id']}})[_0x1ed2('0x29')](handleEntityNotFound(_0x1f77b5,null))['then'](function(_0x524de4){if(_0x524de4){_0x55cf5c=_0x524de4;_0x20c2f9['model']=_[_0x1ed2('0x39')](db[_0x1ed2('0x6a')][_0x1ed2('0x4c')]);_0x20c2f9[_0x1ed2('0x38')]=_[_0x1ed2('0x39')](_0x5d50b2['query']);_0x20c2f9[_0x1ed2('0x3a')]=_[_0x1ed2('0x3b')](_0x20c2f9[_0x1ed2('0x37')],_0x20c2f9['query']);_0x50b9ca['attributes']=_['intersection'](_0x20c2f9[_0x1ed2('0x37')],qs[_0x1ed2('0x3d')](_0x5d50b2['query']['fields']));_0x50b9ca['attributes']=_0x50b9ca['attributes'][_0x1ed2('0x5a')]?_0x50b9ca[_0x1ed2('0x3c')]:_0x20c2f9['model'];_0x50b9ca[_0x1ed2('0x3f')]=qs['sort'](_0x5d50b2['query'][_0x1ed2('0x40')]);_0x50b9ca[_0x1ed2('0x41')]=qs[_0x1ed2('0x3a')](_['pick'](_0x5d50b2[_0x1ed2('0x38')],_0x20c2f9[_0x1ed2('0x3a')]));if(_0x5d50b2[_0x1ed2('0x38')][_0x1ed2('0x43')]){_0x50b9ca[_0x1ed2('0x41')]=_[_0x1ed2('0x44')](_0x50b9ca[_0x1ed2('0x41')],{'$or':_[_0x1ed2('0x32')](_0x50b9ca[_0x1ed2('0x3c')],function(_0xf2cd7c){var _0x5b9c5d={};_0x5b9c5d[_0xf2cd7c]={'$like':'%'+_0x5d50b2[_0x1ed2('0x38')][_0x1ed2('0x43')]+'%'};return _0x5b9c5d;})});}_0x50b9ca=_[_0x1ed2('0x44')]({},_0x50b9ca,_0x5d50b2[_0x1ed2('0x45')]);return _0x55cf5c[_0x1ed2('0x7c')](_0x50b9ca);}})[_0x1ed2('0x29')](function(_0x34f397){if(_0x34f397){_0x301a50=_0x34f397['length'];if(!_0x5d50b2[_0x1ed2('0x38')]['hasOwnProperty'](_0x1ed2('0x7d'))){_0x50b9ca[_0x1ed2('0x22')]=qs[_0x1ed2('0x22')](_0x5d50b2[_0x1ed2('0x38')][_0x1ed2('0x22')]);_0x50b9ca[_0x1ed2('0x21')]=qs[_0x1ed2('0x21')](_0x5d50b2[_0x1ed2('0x38')]['offset']);}return _0x55cf5c[_0x1ed2('0x7c')](_0x50b9ca);}})[_0x1ed2('0x29')](function(_0x5d7564){if(_0x5d7564){return _0x5d7564?{'count':_0x301a50,'rows':_0x5d7564}:null;}})['then'](respondWithResult(_0x1f77b5,null))['catch'](handleError(_0x1f77b5,null));};