Built motion from commit (unavailable).|2.5.8
[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 _0x2f6b=['filter','merge','where','VIRTUAL','options','count','includeAll','include','catch','params','fields','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','find','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','getQueues','findOne','channel','Sequelize','Unknown\x20channel','capitalize','toLowerCase','Queue','Queues','addQueues','isValidChannel','ValidationError','add','ids','removeQueues','remove','Voice','Chat','Mail','Fax','Openchannel','Whatsapp','each','addAgents','User','findAll','online','voicePause','interface','UserVoiceQueueRt','upsert','isNil','format','SIP/%s','omit','spread','emit','userTeam:save','removeAgents','voice','chat','sms','fax','userTeam:remove','getAgents','hasOwnProperty','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','path','sox','to-csv','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','./team.socket','register','sendStatus','status','end','offset','limit','set','Content-Range','json','apply','reject','update','then','destroy','get','error','stack','name','index','map','Team','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','length','nolimit','order','sort','pick'];(function(_0x105e3e,_0x4cb667){var _0x5b0125=function(_0x877866){while(--_0x877866){_0x105e3e['push'](_0x105e3e['shift']());}};_0x5b0125(++_0x4cb667);}(_0x2f6b,0xc8));var _0xb2f6=function(_0x1f4b18,_0x4e777c){_0x1f4b18=_0x1f4b18-0x0;var _0xde3957=_0x2f6b[_0x1f4b18];return _0xde3957;};'use strict';var pdf=require(_0xb2f6('0x0'));var emlformat=require(_0xb2f6('0x1'));var rimraf=require(_0xb2f6('0x2'));var zipdir=require(_0xb2f6('0x3'));var jsonpatch=require(_0xb2f6('0x4'));var rp=require('request-promise');var moment=require(_0xb2f6('0x5'));var BPromise=require(_0xb2f6('0x6'));var Mustache=require(_0xb2f6('0x7'));var util=require('util');var path=require(_0xb2f6('0x8'));var sox=require(_0xb2f6('0x9'));var csv=require(_0xb2f6('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0xb2f6('0xb'));var crypto=require('crypto');var jsforce=require(_0xb2f6('0xc'));var deskjs=require(_0xb2f6('0xd'));var toCsv=require(_0xb2f6('0xa'));var querystring=require(_0xb2f6('0xe'));var Papa=require(_0xb2f6('0xf'));var Redis=require(_0xb2f6('0x10'));var authService=require(_0xb2f6('0x11'));var qs=require(_0xb2f6('0x12'));var as=require(_0xb2f6('0x13'));var hardwareService=require(_0xb2f6('0x14'));var logger=require(_0xb2f6('0x15'))(_0xb2f6('0x16'));var utils=require(_0xb2f6('0x17'));var config=require(_0xb2f6('0x18'));var licenseUtil=require(_0xb2f6('0x19'));var db=require(_0xb2f6('0x1a'))['db'];config[_0xb2f6('0x1b')]=_[_0xb2f6('0x1c')](config[_0xb2f6('0x1b')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xb2f6('0x1b')]));require(_0xb2f6('0x1d'))[_0xb2f6('0x1e')](socket);function respondWithStatusCode(_0x1db366,_0x21885f){_0x21885f=_0x21885f||0xcc;return function(_0x180cfc){if(_0x180cfc){return _0x1db366[_0xb2f6('0x1f')](_0x21885f);}return _0x1db366[_0xb2f6('0x20')](_0x21885f)[_0xb2f6('0x21')]();};}function respondWithResult(_0x37a338,_0x4e0d05){_0x4e0d05=_0x4e0d05||0xc8;return function(_0x5c0b9b){if(_0x5c0b9b){return _0x37a338[_0xb2f6('0x20')](_0x4e0d05)['json'](_0x5c0b9b);}};}function respondWithFilteredResult(_0x3a05a5,_0x54160c){return function(_0x4f46da){if(_0x4f46da){var _0x41feae=_0x4f46da['count'],_0x3a4bbe=_0x54160c[_0xb2f6('0x22')],_0x510916=_0x54160c[_0xb2f6('0x22')]+_0x54160c[_0xb2f6('0x23')],_0x4eb51d;if(_0x510916>=_0x41feae){_0x510916=_0x41feae;_0x4eb51d=0xc8;}else{_0x4eb51d=0xce;}_0x3a05a5[_0xb2f6('0x20')](_0x4eb51d);return _0x3a05a5[_0xb2f6('0x24')](_0xb2f6('0x25'),_0x3a4bbe+'-'+_0x510916+'/'+_0x41feae)[_0xb2f6('0x26')](_0x4f46da);}return null;};}function patchUpdates(_0x2c6dfc){return function(_0x3ed91d){try{jsonpatch[_0xb2f6('0x27')](_0x3ed91d,_0x2c6dfc,!![]);}catch(_0x564baa){return BPromise[_0xb2f6('0x28')](_0x564baa);}return _0x3ed91d['save']();};}function saveUpdates(_0x5d7423,_0x3a7346){return function(_0x2f0420){if(_0x2f0420){return _0x2f0420[_0xb2f6('0x29')](_0x5d7423)[_0xb2f6('0x2a')](function(_0x5743d2){return _0x5743d2;});}return null;};}function removeEntity(_0x6af807,_0x51a18e){return function(_0x275f09){if(_0x275f09){return _0x275f09[_0xb2f6('0x2b')]()[_0xb2f6('0x2a')](function(){var _0x3ac668=_0x275f09[_0xb2f6('0x2c')]({'plain':!![]});var _0x463f9e='Teams';return db['UserProfileResource'][_0xb2f6('0x2b')]({'where':{'type':_0x463f9e,'resourceId':_0x3ac668['id']}})[_0xb2f6('0x2a')](function(){return _0x275f09;});})[_0xb2f6('0x2a')](function(){_0x6af807[_0xb2f6('0x20')](0xcc)[_0xb2f6('0x21')]();});}};}function handleEntityNotFound(_0x19dfd8,_0xd42bff){return function(_0x302817){if(!_0x302817){_0x19dfd8[_0xb2f6('0x1f')](0x194);}return _0x302817;};}function handleError(_0x545f94,_0x43dcb8){_0x43dcb8=_0x43dcb8||0x1f4;return function(_0x338c21){logger[_0xb2f6('0x2d')](_0x338c21[_0xb2f6('0x2e')]);if(_0x338c21[_0xb2f6('0x2f')]){delete _0x338c21[_0xb2f6('0x2f')];}_0x545f94[_0xb2f6('0x20')](_0x43dcb8)['send'](_0x338c21);};}exports[_0xb2f6('0x30')]=function(_0x26acdd,_0x2e9ca2){var _0x1dc599={},_0x5ebf57={},_0x2f2614={'count':0x0,'rows':[]};var _0x4779ec=_[_0xb2f6('0x31')](db[_0xb2f6('0x32')][_0xb2f6('0x33')],function(_0x251066){return{'name':_0x251066[_0xb2f6('0x34')],'type':_0x251066[_0xb2f6('0x35')][_0xb2f6('0x36')]};});_0x5ebf57[_0xb2f6('0x37')]=_[_0xb2f6('0x31')](_0x4779ec,'name');_0x5ebf57[_0xb2f6('0x38')]=_[_0xb2f6('0x39')](_0x26acdd[_0xb2f6('0x38')]);_0x5ebf57[_0xb2f6('0x3a')]=_['intersection'](_0x5ebf57['model'],_0x5ebf57[_0xb2f6('0x38')]);_0x1dc599['attributes']=_[_0xb2f6('0x3b')](_0x5ebf57[_0xb2f6('0x37')],qs['fields'](_0x26acdd[_0xb2f6('0x38')]['fields']));_0x1dc599['attributes']=_0x1dc599[_0xb2f6('0x3c')][_0xb2f6('0x3d')]?_0x1dc599[_0xb2f6('0x3c')]:_0x5ebf57[_0xb2f6('0x37')];if(!_0x26acdd[_0xb2f6('0x38')]['hasOwnProperty'](_0xb2f6('0x3e'))){_0x1dc599[_0xb2f6('0x23')]=qs[_0xb2f6('0x23')](_0x26acdd[_0xb2f6('0x38')][_0xb2f6('0x23')]);_0x1dc599[_0xb2f6('0x22')]=qs[_0xb2f6('0x22')](_0x26acdd[_0xb2f6('0x38')][_0xb2f6('0x22')]);}_0x1dc599[_0xb2f6('0x3f')]=qs[_0xb2f6('0x40')](_0x26acdd['query'][_0xb2f6('0x40')]);_0x1dc599['where']=qs['filters'](_[_0xb2f6('0x41')](_0x26acdd[_0xb2f6('0x38')],_0x5ebf57[_0xb2f6('0x3a')]),_0x4779ec);if(_0x26acdd[_0xb2f6('0x38')][_0xb2f6('0x42')]){_0x1dc599['where']=_[_0xb2f6('0x43')](_0x1dc599[_0xb2f6('0x44')],{'$or':_['map'](_0x4779ec,function(_0x5f0637){if(_0x5f0637['type']!==_0xb2f6('0x45')){var _0x3606c7={};_0x3606c7[_0x5f0637[_0xb2f6('0x2f')]]={'$like':'%'+_0x26acdd['query'][_0xb2f6('0x42')]+'%'};return _0x3606c7;}})});}_0x1dc599=_[_0xb2f6('0x43')]({},_0x1dc599,_0x26acdd[_0xb2f6('0x46')]);var _0x5484fc={'where':_0x1dc599[_0xb2f6('0x44')]};return db[_0xb2f6('0x32')]['count'](_0x5484fc)[_0xb2f6('0x2a')](function(_0x22c291){_0x2f2614[_0xb2f6('0x47')]=_0x22c291;if(_0x26acdd[_0xb2f6('0x38')][_0xb2f6('0x48')]){_0x1dc599[_0xb2f6('0x49')]=[{'all':!![]}];}return db[_0xb2f6('0x32')]['findAll'](_0x1dc599);})[_0xb2f6('0x2a')](function(_0x5b2323){_0x2f2614['rows']=_0x5b2323;return _0x2f2614;})[_0xb2f6('0x2a')](respondWithFilteredResult(_0x2e9ca2,_0x1dc599))[_0xb2f6('0x4a')](handleError(_0x2e9ca2,null));};exports['show']=function(_0x20b0d0,_0x1b4c53){var _0x506028={'raw':![],'where':{'id':_0x20b0d0[_0xb2f6('0x4b')]['id']}},_0x4d230b={};_0x4d230b['model']=_[_0xb2f6('0x39')](db['Team'][_0xb2f6('0x33')]);_0x4d230b['query']=_[_0xb2f6('0x39')](_0x20b0d0[_0xb2f6('0x38')]);_0x4d230b[_0xb2f6('0x3a')]=_[_0xb2f6('0x3b')](_0x4d230b[_0xb2f6('0x37')],_0x4d230b[_0xb2f6('0x38')]);_0x506028['attributes']=_[_0xb2f6('0x3b')](_0x4d230b[_0xb2f6('0x37')],qs[_0xb2f6('0x4c')](_0x20b0d0[_0xb2f6('0x38')][_0xb2f6('0x4c')]));_0x506028[_0xb2f6('0x3c')]=_0x506028[_0xb2f6('0x3c')][_0xb2f6('0x3d')]?_0x506028[_0xb2f6('0x3c')]:_0x4d230b[_0xb2f6('0x37')];if(_0x20b0d0[_0xb2f6('0x38')][_0xb2f6('0x48')]){_0x506028[_0xb2f6('0x49')]=[{'all':!![]}];}_0x506028=_['merge']({},_0x506028,_0x20b0d0[_0xb2f6('0x46')]);return db[_0xb2f6('0x32')]['find'](_0x506028)[_0xb2f6('0x2a')](handleEntityNotFound(_0x1b4c53,null))[_0xb2f6('0x2a')](respondWithResult(_0x1b4c53,null))[_0xb2f6('0x4a')](handleError(_0x1b4c53,null));};exports[_0xb2f6('0x4d')]=function(_0x56b870,_0xc6a967){return db[_0xb2f6('0x32')][_0xb2f6('0x4d')](_0x56b870['body'],{})[_0xb2f6('0x2a')](function(_0x37356d){var _0x53e283=_0x56b870[_0xb2f6('0x4e')]['get']({'plain':!![]});if(!_0x53e283)throw new Error(_0xb2f6('0x4f'));if(_0x53e283[_0xb2f6('0x50')]===_0xb2f6('0x4e')){var _0x4efd01=_0x37356d[_0xb2f6('0x2c')]({'plain':!![]});var _0x54ca5a='Teams';return db['UserProfileSection'][_0xb2f6('0x51')]({'where':{'name':_0x54ca5a,'userProfileId':_0x53e283[_0xb2f6('0x52')]},'raw':!![]})[_0xb2f6('0x2a')](function(_0x21d7ac){if(_0x21d7ac&&_0x21d7ac[_0xb2f6('0x53')]===0x0){return db[_0xb2f6('0x54')][_0xb2f6('0x4d')]({'name':_0x4efd01['name'],'resourceId':_0x4efd01['id'],'type':_0x21d7ac[_0xb2f6('0x2f')],'sectionId':_0x21d7ac['id']},{})[_0xb2f6('0x2a')](function(){return _0x37356d;});}else{return _0x37356d;}})['catch'](function(_0x29ac6a){logger[_0xb2f6('0x2d')](_0xb2f6('0x55'),_0x29ac6a);throw _0x29ac6a;});}return _0x37356d;})['then'](respondWithResult(_0xc6a967,0xc9))[_0xb2f6('0x4a')](handleError(_0xc6a967,null));};exports[_0xb2f6('0x29')]=function(_0x4688e2,_0x138eba){if(_0x4688e2[_0xb2f6('0x56')]['id']){delete _0x4688e2[_0xb2f6('0x56')]['id'];}return db[_0xb2f6('0x32')][_0xb2f6('0x51')]({'where':{'id':_0x4688e2['params']['id']}})[_0xb2f6('0x2a')](handleEntityNotFound(_0x138eba,null))['then'](saveUpdates(_0x4688e2[_0xb2f6('0x56')],null))[_0xb2f6('0x2a')](respondWithResult(_0x138eba,null))[_0xb2f6('0x4a')](handleError(_0x138eba,null));};exports[_0xb2f6('0x2b')]=function(_0x5b0b05,_0x3f88bf){return db['Team'][_0xb2f6('0x51')]({'where':{'id':_0x5b0b05[_0xb2f6('0x4b')]['id']}})[_0xb2f6('0x2a')](handleEntityNotFound(_0x3f88bf,null))['then'](removeEntity(_0x3f88bf,null))[_0xb2f6('0x4a')](handleError(_0x3f88bf,null));};exports[_0xb2f6('0x57')]=function(_0x12f1d1,_0x57ed27,_0x4a1dd4){return db['Team'][_0xb2f6('0x58')]({'where':{'id':_0x12f1d1[_0xb2f6('0x4b')]['id']}})[_0xb2f6('0x2a')](handleEntityNotFound(_0x57ed27,null))['then'](function(_0x924644){if(!_0x12f1d1['query'][_0xb2f6('0x59')]||!utils['isValidChannel'](_0x12f1d1['query']['channel'])){throw new db[(_0xb2f6('0x5a'))]['ValidationError'](_0xb2f6('0x5b'));}var _0x53d1b6={};var _0x3486cc={};_0x3486cc[_0xb2f6('0x37')]=_[_0xb2f6('0x39')](db[_[_0xb2f6('0x5c')](_0x12f1d1[_0xb2f6('0x38')][_0xb2f6('0x59')][_0xb2f6('0x5d')]())+_0xb2f6('0x5e')][_0xb2f6('0x33')]);_0x3486cc['query']=_[_0xb2f6('0x39')](_0x12f1d1[_0xb2f6('0x38')]);_0x3486cc[_0xb2f6('0x3a')]=_[_0xb2f6('0x3b')](_0x3486cc[_0xb2f6('0x37')],_0x3486cc[_0xb2f6('0x38')]);_0x53d1b6[_0xb2f6('0x3c')]=_['intersection'](_0x3486cc[_0xb2f6('0x37')],qs[_0xb2f6('0x4c')](_0x12f1d1[_0xb2f6('0x38')]['fields']));_0x53d1b6[_0xb2f6('0x3c')]=_0x53d1b6[_0xb2f6('0x3c')][_0xb2f6('0x3d')]?_0x53d1b6[_0xb2f6('0x3c')]:_0x3486cc[_0xb2f6('0x37')];_0x53d1b6[_0xb2f6('0x23')]=qs[_0xb2f6('0x23')](_0x12f1d1['query'][_0xb2f6('0x23')]);_0x53d1b6[_0xb2f6('0x22')]=qs[_0xb2f6('0x22')](_0x12f1d1['query'][_0xb2f6('0x22')]);_0x53d1b6[_0xb2f6('0x3f')]=qs[_0xb2f6('0x40')](_0x12f1d1[_0xb2f6('0x38')][_0xb2f6('0x40')]);_0x53d1b6[_0xb2f6('0x44')]=qs[_0xb2f6('0x3a')](_[_0xb2f6('0x41')](_0x12f1d1[_0xb2f6('0x38')],_0x3486cc[_0xb2f6('0x3a')]));_0x53d1b6=_[_0xb2f6('0x43')]({},_0x53d1b6,_0x12f1d1[_0xb2f6('0x46')]);return _0x924644[_0xb2f6('0x2c')+_[_0xb2f6('0x5c')](_0x12f1d1['query'][_0xb2f6('0x59')][_0xb2f6('0x5d')]())+_0xb2f6('0x5f')](_0x53d1b6);})[_0xb2f6('0x2a')](respondWithResult(_0x57ed27,null))['catch'](handleError(_0x57ed27,null));};exports[_0xb2f6('0x60')]=function(_0x55795e,_0x37f7ad,_0x2943c2){return db[_0xb2f6('0x32')][_0xb2f6('0x58')]({'where':{'id':_0x55795e[_0xb2f6('0x4b')]['id']}})[_0xb2f6('0x2a')](function(_0xda7ad5){if(_0xda7ad5){if(!_0x55795e[_0xb2f6('0x56')]['channel']||!utils[_0xb2f6('0x61')](_0x55795e['body'][_0xb2f6('0x59')])){throw new db[(_0xb2f6('0x5a'))][(_0xb2f6('0x62'))](_0xb2f6('0x5b'));}return _0xda7ad5[_0xb2f6('0x63')+_[_0xb2f6('0x5c')](_0x55795e[_0xb2f6('0x56')][_0xb2f6('0x59')]['toLowerCase']())+_0xb2f6('0x5f')](_0x55795e['body'][_0xb2f6('0x64')]);}return null;})[_0xb2f6('0x2a')](handleEntityNotFound(_0x37f7ad,null))[_0xb2f6('0x2a')](respondWithStatusCode(_0x37f7ad,null))['catch'](handleError(_0x37f7ad,null));};exports[_0xb2f6('0x65')]=function(_0x5b723b,_0x1d1096,_0x4acb20){return db[_0xb2f6('0x32')][_0xb2f6('0x58')]({'where':{'id':_0x5b723b[_0xb2f6('0x4b')]['id']}})['then'](function(_0x4dffbb){if(_0x4dffbb){if(!_0x5b723b[_0xb2f6('0x38')]['channel']||!utils[_0xb2f6('0x61')](_0x5b723b['query']['channel'])){throw new db[(_0xb2f6('0x5a'))][(_0xb2f6('0x62'))](_0xb2f6('0x5b'));}return _0x4dffbb[_0xb2f6('0x66')+_[_0xb2f6('0x5c')](_0x5b723b[_0xb2f6('0x38')][_0xb2f6('0x59')][_0xb2f6('0x5d')]())+_0xb2f6('0x5f')](_0x5b723b[_0xb2f6('0x38')][_0xb2f6('0x64')]);}return null;})[_0xb2f6('0x2a')](handleEntityNotFound(_0x1d1096,null))[_0xb2f6('0x2a')](respondWithStatusCode(_0x1d1096,null))[_0xb2f6('0x4a')](handleError(_0x1d1096,null));};exports['addAgents']=function(_0x3e6ec4,_0x2a88ac,_0x1766e3){return db[_0xb2f6('0x32')][_0xb2f6('0x51')]({'where':{'id':_0x3e6ec4[_0xb2f6('0x4b')]['id']}})[_0xb2f6('0x2a')](handleEntityNotFound(_0x2a88ac,null))[_0xb2f6('0x2a')](function(_0x5c24ad){if(_0x5c24ad){var _0x109c70=[_0xb2f6('0x67'),_0xb2f6('0x68'),_0xb2f6('0x69'),'Sms',_0xb2f6('0x6a'),_0xb2f6('0x6b'),_0xb2f6('0x6c')];return BPromise[_0xb2f6('0x6d')](_0x109c70,function(_0x1ec736){return _0x5c24ad['get'+_0x1ec736+_0xb2f6('0x5f')]({'attributes':['id',_0xb2f6('0x2f')]})[_0xb2f6('0x2a')](function(_0x69add){return BPromise[_0xb2f6('0x6d')](_0x69add,function(_0x12f1fe){return _0x12f1fe[_0xb2f6('0x6e')](_0x3e6ec4[_0xb2f6('0x56')][_0xb2f6('0x64')])['then'](function(){if(_0x1ec736===_0xb2f6('0x67')){return db[_0xb2f6('0x6f')][_0xb2f6('0x70')]({'where':{'id':_0x3e6ec4[_0xb2f6('0x56')][_0xb2f6('0x64')]},'attributes':['id','name',_0xb2f6('0x71'),_0xb2f6('0x72'),_0xb2f6('0x73')],'raw':!![]})[_0xb2f6('0x2a')](function(_0x41fde3){return BPromise[_0xb2f6('0x6d')](_[_0xb2f6('0x42')](_0x41fde3,{'online':0x1}),function(_0x43714d){return db[_0xb2f6('0x74')][_0xb2f6('0x75')]({'membername':_0x43714d[_0xb2f6('0x2f')],'UserId':_0x43714d['id'],'queue_name':_0x12f1fe[_0xb2f6('0x2f')],'VoiceQueueId':_0x12f1fe['id'],'interface':_[_0xb2f6('0x76')](_0x43714d['interface'])?util[_0xb2f6('0x77')](_0xb2f6('0x78'),_0x43714d[_0xb2f6('0x2f')]):_0x43714d[_0xb2f6('0x73')],'paused':_0x43714d[_0xb2f6('0x72')]||![],'penalty':0x0});});});}});});})['then'](function(){return _0x5c24ad;});})['then'](function(){return _0x5c24ad;});}})[_0xb2f6('0x2a')](function(_0x1a5043){if(_0x1a5043){return _0x1a5043[_0xb2f6('0x6e')](_0x3e6ec4[_0xb2f6('0x56')][_0xb2f6('0x64')],_[_0xb2f6('0x79')](_0x3e6ec4[_0xb2f6('0x56')],['ids','id'])||{})[_0xb2f6('0x7a')](function(_0x81b34d){for(var _0x3e8f64=0x0;_0x3e8f64<_0x3e6ec4[_0xb2f6('0x56')][_0xb2f6('0x64')][_0xb2f6('0x3d')];_0x3e8f64+=0x1){socket[_0xb2f6('0x7b')](_0xb2f6('0x7c'),{'UserId':_0x3e6ec4[_0xb2f6('0x56')]['ids'][_0x3e8f64],'TeamId':_0x3e6ec4['params']['id']});}return _0x81b34d;});}})['then'](respondWithResult(_0x2a88ac,null))[_0xb2f6('0x4a')](handleError(_0x2a88ac,null));};exports[_0xb2f6('0x7d')]=function(_0x3e075a,_0x2bea56,_0x398a00){return db[_0xb2f6('0x32')][_0xb2f6('0x51')]({'where':{'id':_0x3e075a[_0xb2f6('0x4b')]['id']}})['then'](handleEntityNotFound(_0x2bea56,null))['then'](function(_0x33aef8){if(_0x33aef8){return BPromise[_0xb2f6('0x6d')]([_0xb2f6('0x7e'),_0xb2f6('0x7f'),'mail',_0xb2f6('0x80'),_0xb2f6('0x81'),'openchannel','whatsapp'],function(_0xabe1e9){return _0x33aef8[_0xb2f6('0x2c')+_[_0xb2f6('0x5c')](_0xabe1e9)+'Queues']({'attributes':['id',_0xb2f6('0x2f')]})[_0xb2f6('0x2a')](function(_0x5c975b){return BPromise[_0xb2f6('0x6d')](_0x5c975b,function(_0x5339c8){return _0x5339c8[_0xb2f6('0x7d')](_0x3e075a[_0xb2f6('0x38')][_0xb2f6('0x64')])[_0xb2f6('0x2a')](function(){if(_0xabe1e9===_0xb2f6('0x7e')){return db[_0xb2f6('0x74')][_0xb2f6('0x2b')]({'where':{'VoiceQueueId':_0x5339c8['id'],'UserId':_0x3e075a[_0xb2f6('0x38')][_0xb2f6('0x64')]}});}});});})[_0xb2f6('0x2a')](function(){return _0x33aef8;});})[_0xb2f6('0x2a')](function(){return _0x33aef8;});}})['then'](function(_0x3fa802){if(_0x3fa802){return _0x3fa802[_0xb2f6('0x7d')](_0x3e075a[_0xb2f6('0x38')]['ids'])['then'](function(){if(_['isArray'](_0x3e075a[_0xb2f6('0x38')][_0xb2f6('0x64')])){for(var _0x3cd123=0x0;_0x3cd123<_0x3e075a['query'][_0xb2f6('0x64')][_0xb2f6('0x3d')];_0x3cd123+=0x1){socket[_0xb2f6('0x7b')](_0xb2f6('0x82'),{'UserId':Number(_0x3e075a['query'][_0xb2f6('0x64')][_0x3cd123]),'TeamId':Number(_0x3e075a['params']['id'])});}}else{socket[_0xb2f6('0x7b')](_0xb2f6('0x82'),{'UserId':Number(_0x3e075a[_0xb2f6('0x38')]['ids']),'TeamId':Number(_0x3e075a[_0xb2f6('0x4b')]['id'])});}});}})[_0xb2f6('0x2a')](respondWithStatusCode(_0x2bea56,null))['catch'](handleError(_0x2bea56,null));};exports['getAgents']=function(_0x2f6875,_0x522b42,_0xcd61f6){var _0x41b217={};var _0x11c0ef={};var _0x1e3bc7;var _0x32907e;return db[_0xb2f6('0x32')]['findOne']({'where':{'id':_0x2f6875[_0xb2f6('0x4b')]['id']}})[_0xb2f6('0x2a')](handleEntityNotFound(_0x522b42,null))[_0xb2f6('0x2a')](function(_0x4aab1c){if(_0x4aab1c){_0x1e3bc7=_0x4aab1c;_0x11c0ef['model']=_[_0xb2f6('0x39')](db[_0xb2f6('0x6f')][_0xb2f6('0x33')]);_0x11c0ef[_0xb2f6('0x38')]=_[_0xb2f6('0x39')](_0x2f6875[_0xb2f6('0x38')]);_0x11c0ef[_0xb2f6('0x3a')]=_[_0xb2f6('0x3b')](_0x11c0ef['model'],_0x11c0ef[_0xb2f6('0x38')]);_0x41b217['attributes']=_[_0xb2f6('0x3b')](_0x11c0ef[_0xb2f6('0x37')],qs['fields'](_0x2f6875['query']['fields']));_0x41b217[_0xb2f6('0x3c')]=_0x41b217['attributes'][_0xb2f6('0x3d')]?_0x41b217[_0xb2f6('0x3c')]:_0x11c0ef['model'];_0x41b217[_0xb2f6('0x3f')]=qs[_0xb2f6('0x40')](_0x2f6875['query']['sort']);_0x41b217[_0xb2f6('0x44')]=qs[_0xb2f6('0x3a')](_[_0xb2f6('0x41')](_0x2f6875[_0xb2f6('0x38')],_0x11c0ef[_0xb2f6('0x3a')]));if(_0x2f6875['query'][_0xb2f6('0x42')]){_0x41b217['where']=_['merge'](_0x41b217[_0xb2f6('0x44')],{'$or':_['map'](_0x41b217[_0xb2f6('0x3c')],function(_0x13457e){var _0x8887af={};_0x8887af[_0x13457e]={'$like':'%'+_0x2f6875[_0xb2f6('0x38')][_0xb2f6('0x42')]+'%'};return _0x8887af;})});}_0x41b217=_['merge']({},_0x41b217,_0x2f6875[_0xb2f6('0x46')]);return _0x1e3bc7[_0xb2f6('0x83')](_0x41b217);}})[_0xb2f6('0x2a')](function(_0x1faac1){if(_0x1faac1){_0x32907e=_0x1faac1['length'];if(!_0x2f6875[_0xb2f6('0x38')][_0xb2f6('0x84')](_0xb2f6('0x3e'))){_0x41b217[_0xb2f6('0x23')]=qs[_0xb2f6('0x23')](_0x2f6875[_0xb2f6('0x38')][_0xb2f6('0x23')]);_0x41b217[_0xb2f6('0x22')]=qs[_0xb2f6('0x22')](_0x2f6875[_0xb2f6('0x38')][_0xb2f6('0x22')]);}return _0x1e3bc7['getAgents'](_0x41b217);}})[_0xb2f6('0x2a')](function(_0x18532b){if(_0x18532b){return _0x18532b?{'count':_0x32907e,'rows':_0x18532b}:null;}})[_0xb2f6('0x2a')](respondWithResult(_0x522b42,null))[_0xb2f6('0x4a')](handleError(_0x522b42,null));};