Built motion from commit (unavailable).|2.2.0
[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 _0xb10b=['role','UserProfileSection','find','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','getQueues','findOne','channel','isValidChannel','ValidationError','Unknown\x20channel','capitalize','Queue','sort','toLowerCase','Queues','addQueues','Sequelize','ids','remove','each','voice','chat','mail','fax','openchannel','addAgents','voicePause','interface','upsert','isNil','format','SIP/%s','omit','spread','emit','userTeam:save','removeAgents','sms','userTeam:remove','getAgents','nolimit','html-pdf','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','ejs','lodash','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/parsers/qs','../../config/utils','../../config/environment','../../mysqldb','defaults','localhost','socket.io-emitter','redis','./team.socket','register','sendStatus','status','end','json','count','offset','limit','Content-Range','apply','save','update','then','destroy','get','Teams','error','name','send','index','Team','rawAttributes','model','query','dateStart','dateEnd','keys','filters','intersection','attributes','fields','length','order','where','pick','add','day','filter','map','type','VIRTUAL','field','merge','options','includeAll','include','findAll','rows','catch','show','params','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user'];(function(_0x5b644e,_0x2e5e07){var _0x49c6bf=function(_0x3032d9){while(--_0x3032d9){_0x5b644e['push'](_0x5b644e['shift']());}};_0x49c6bf(++_0x2e5e07);}(_0xb10b,0x12a));var _0xbb10=function(_0x188926,_0x1b2429){_0x188926=_0x188926-0x0;var _0x17f4bf=_0xb10b[_0x188926];return _0x17f4bf;};'use strict';var pdf=require(_0xbb10('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xbb10('0x1'));var zipdir=require(_0xbb10('0x2'));var jsonpatch=require(_0xbb10('0x3'));var rp=require('request-promise');var moment=require(_0xbb10('0x4'));var BPromise=require(_0xbb10('0x5'));var Mustache=require(_0xbb10('0x6'));var util=require(_0xbb10('0x7'));var path=require(_0xbb10('0x8'));var sox=require(_0xbb10('0x9'));var csv=require('to-csv');var ejs=require(_0xbb10('0xa'));var fs=require('fs');var _=require(_0xbb10('0xb'));var squel=require('squel');var crypto=require(_0xbb10('0xc'));var jsforce=require(_0xbb10('0xd'));var deskjs=require(_0xbb10('0xe'));var toCsv=require(_0xbb10('0xf'));var querystring=require(_0xbb10('0x10'));var Papa=require(_0xbb10('0x11'));var Redis=require(_0xbb10('0x12'));var qs=require(_0xbb10('0x13'));var logger=require('../../config/logger')('api');var utils=require(_0xbb10('0x14'));var config=require(_0xbb10('0x15'));var db=require(_0xbb10('0x16'))['db'];config['redis']=_[_0xbb10('0x17')](config['redis'],{'host':_0xbb10('0x18'),'port':0x18eb});var socket=require(_0xbb10('0x19'))(new Redis(config[_0xbb10('0x1a')]));require(_0xbb10('0x1b'))[_0xbb10('0x1c')](socket);function respondWithStatusCode(_0x147230,_0x58a612){_0x58a612=_0x58a612||0xcc;return function(_0x26e021){if(_0x26e021){return _0x147230[_0xbb10('0x1d')](_0x58a612);}return _0x147230[_0xbb10('0x1e')](_0x58a612)[_0xbb10('0x1f')]();};}function respondWithResult(_0x3df17b,_0x2f2ebf){_0x2f2ebf=_0x2f2ebf||0xc8;return function(_0x24a57b){if(_0x24a57b){return _0x3df17b[_0xbb10('0x1e')](_0x2f2ebf)[_0xbb10('0x20')](_0x24a57b);}};}function respondWithFilteredResult(_0x2b184e,_0x4a2bfc){return function(_0x2eca0f){if(_0x2eca0f){var _0x1145f1=_0x2eca0f[_0xbb10('0x21')],_0x133ac2=_0x4a2bfc[_0xbb10('0x22')],_0x42db98=_0x4a2bfc[_0xbb10('0x22')]+_0x4a2bfc[_0xbb10('0x23')],_0x378da8;if(_0x42db98>=_0x1145f1){_0x42db98=_0x1145f1;_0x378da8=0xc8;}else{_0x378da8=0xce;}_0x2b184e[_0xbb10('0x1e')](_0x378da8);return _0x2b184e['set'](_0xbb10('0x24'),_0x133ac2+'-'+_0x42db98+'/'+_0x1145f1)[_0xbb10('0x20')](_0x2eca0f);}return null;};}function patchUpdates(_0x388fab){return function(_0x109908){try{jsonpatch[_0xbb10('0x25')](_0x109908,_0x388fab,!![]);}catch(_0x44e563){return BPromise['reject'](_0x44e563);}return _0x109908[_0xbb10('0x26')]();};}function saveUpdates(_0x12ef77,_0x50aea1){return function(_0x4c4b0d){if(_0x4c4b0d){return _0x4c4b0d[_0xbb10('0x27')](_0x12ef77)[_0xbb10('0x28')](function(_0x2e911d){return _0x2e911d;});}return null;};}function removeEntity(_0x317da4,_0x445761){return function(_0x1824b7){if(_0x1824b7){return _0x1824b7[_0xbb10('0x29')]()[_0xbb10('0x28')](function(){var _0x7f2377=_0x1824b7[_0xbb10('0x2a')]({'plain':!![]});var _0x3ba6cd=_0xbb10('0x2b');return db['UserProfileResource']['destroy']({'where':{'type':_0x3ba6cd,'resourceId':_0x7f2377['id']}})['then'](function(){return _0x1824b7;});})[_0xbb10('0x28')](function(){_0x317da4[_0xbb10('0x1e')](0xcc)[_0xbb10('0x1f')]();});}};}function handleEntityNotFound(_0x4e25ff,_0x2fdde9){return function(_0x24d586){if(!_0x24d586){_0x4e25ff[_0xbb10('0x1d')](0x194);}return _0x24d586;};}function handleError(_0x1d5e95,_0x1acce9){_0x1acce9=_0x1acce9||0x1f4;return function(_0x20d946){logger[_0xbb10('0x2c')](_0x20d946['stack']);if(_0x20d946[_0xbb10('0x2d')]){delete _0x20d946[_0xbb10('0x2d')];}_0x1d5e95[_0xbb10('0x1e')](_0x1acce9)[_0xbb10('0x2e')](_0x20d946);};}exports[_0xbb10('0x2f')]=function(_0x2ff4c1,_0x5d5c80){var _0x221624={},_0x4ee02e={},_0x448d5c={'count':0x0,'rows':[]};var _0x56f2da=db[_0xbb10('0x30')][_0xbb10('0x31')];_0x4ee02e[_0xbb10('0x32')]=_['keys'](_0x56f2da);var _0x518d47={'dateStart':_0x2ff4c1[_0xbb10('0x33')][_0xbb10('0x34')],'dateEnd':_0x2ff4c1['query'][_0xbb10('0x35')]};delete _0x2ff4c1[_0xbb10('0x33')][_0xbb10('0x34')];delete _0x2ff4c1[_0xbb10('0x33')][_0xbb10('0x35')];_0x4ee02e[_0xbb10('0x33')]=_[_0xbb10('0x36')](_0x2ff4c1['query']);_0x4ee02e[_0xbb10('0x37')]=_[_0xbb10('0x38')](_0x4ee02e[_0xbb10('0x32')],_0x4ee02e[_0xbb10('0x33')]);_0x221624[_0xbb10('0x39')]=_[_0xbb10('0x38')](_0x4ee02e[_0xbb10('0x32')],qs[_0xbb10('0x3a')](_0x2ff4c1[_0xbb10('0x33')]['fields']));_0x221624[_0xbb10('0x39')]=_0x221624[_0xbb10('0x39')][_0xbb10('0x3b')]?_0x221624[_0xbb10('0x39')]:_0x4ee02e['model'];if(!_0x2ff4c1[_0xbb10('0x33')]['hasOwnProperty']('nolimit')){_0x221624[_0xbb10('0x23')]=qs[_0xbb10('0x23')](_0x2ff4c1[_0xbb10('0x33')][_0xbb10('0x23')]);_0x221624[_0xbb10('0x22')]=qs[_0xbb10('0x22')](_0x2ff4c1['query'][_0xbb10('0x22')]);}_0x221624[_0xbb10('0x3c')]=qs['sort'](_0x2ff4c1['query']['sort']);_0x221624[_0xbb10('0x3d')]=qs[_0xbb10('0x37')](_[_0xbb10('0x3e')](_0x2ff4c1['query'],_0x4ee02e[_0xbb10('0x37')]));if(_0x518d47[_0xbb10('0x34')]){if(_0x518d47[_0xbb10('0x35')]){_0x518d47['dateEnd']=moment(_0x518d47[_0xbb10('0x35')])[_0xbb10('0x3f')](0x1,_0xbb10('0x40'));}else{_0x518d47[_0xbb10('0x35')]=moment(_0x518d47['dateStart'])[_0xbb10('0x3f')](0x1,_0xbb10('0x40'));}_['merge'](_0x221624[_0xbb10('0x3d')],{'createdAt':{'$gte':_0x518d47[_0xbb10('0x34')],'$lte':_0x518d47[_0xbb10('0x35')]}});}if(_0x2ff4c1[_0xbb10('0x33')][_0xbb10('0x41')]){_0x221624[_0xbb10('0x3d')]=_['merge'](_0x221624[_0xbb10('0x3d')],{'$or':_[_0xbb10('0x42')](_0x56f2da,function(_0x3e7b4c){if(_0x3e7b4c[_0xbb10('0x43')]['key']!==_0xbb10('0x44')){var _0x331751={};_0x331751[_0x3e7b4c[_0xbb10('0x45')]]={'$like':'%'+_0x2ff4c1[_0xbb10('0x33')]['filter']+'%'};return _0x331751;}})});}_0x221624=_[_0xbb10('0x46')]({},_0x221624,_0x2ff4c1[_0xbb10('0x47')]);var _0x54ac18={'where':_0x221624['where']};return db[_0xbb10('0x30')]['count'](_0x54ac18)[_0xbb10('0x28')](function(_0x180933){_0x448d5c['count']=_0x180933;if(_0x2ff4c1[_0xbb10('0x33')][_0xbb10('0x48')]){_0x221624[_0xbb10('0x49')]=[{'all':!![]}];}return db['Team'][_0xbb10('0x4a')](_0x221624);})[_0xbb10('0x28')](function(_0x3b9fdf){_0x448d5c[_0xbb10('0x4b')]=_0x3b9fdf;return _0x448d5c;})[_0xbb10('0x28')](respondWithFilteredResult(_0x5d5c80,_0x221624))[_0xbb10('0x4c')](handleError(_0x5d5c80,null));};exports[_0xbb10('0x4d')]=function(_0x3efa96,_0x205bb4){var _0x43b948={'raw':![],'where':{'id':_0x3efa96[_0xbb10('0x4e')]['id']}},_0x197871={};_0x197871['model']=_[_0xbb10('0x36')](db[_0xbb10('0x30')]['rawAttributes']);_0x197871[_0xbb10('0x33')]=_[_0xbb10('0x36')](_0x3efa96[_0xbb10('0x33')]);_0x197871[_0xbb10('0x37')]=_[_0xbb10('0x38')](_0x197871[_0xbb10('0x32')],_0x197871[_0xbb10('0x33')]);_0x43b948['attributes']=_['intersection'](_0x197871[_0xbb10('0x32')],qs[_0xbb10('0x3a')](_0x3efa96[_0xbb10('0x33')]['fields']));_0x43b948['attributes']=_0x43b948[_0xbb10('0x39')][_0xbb10('0x3b')]?_0x43b948[_0xbb10('0x39')]:_0x197871[_0xbb10('0x32')];if(_0x3efa96[_0xbb10('0x33')][_0xbb10('0x48')]){_0x43b948[_0xbb10('0x49')]=[{'all':!![]}];}_0x43b948=_[_0xbb10('0x46')]({},_0x43b948,_0x3efa96[_0xbb10('0x47')]);return db[_0xbb10('0x30')]['find'](_0x43b948)['then'](handleEntityNotFound(_0x205bb4,null))[_0xbb10('0x28')](respondWithResult(_0x205bb4,null))[_0xbb10('0x4c')](handleError(_0x205bb4,null));};exports[_0xbb10('0x4f')]=function(_0xb014b0,_0x36aa7d){return db[_0xbb10('0x30')][_0xbb10('0x4f')](_0xb014b0[_0xbb10('0x50')],{})[_0xbb10('0x28')](function(_0x1214f7){var _0x19ca3e=_0xb014b0[_0xbb10('0x51')][_0xbb10('0x2a')]({'plain':!![]});if(!_0x19ca3e)throw new Error(_0xbb10('0x52'));if(_0x19ca3e[_0xbb10('0x53')]==='user'){var _0x124052=_0x1214f7['get']({'plain':!![]});var _0x33d60a=_0xbb10('0x2b');return db[_0xbb10('0x54')][_0xbb10('0x55')]({'where':{'name':_0x33d60a,'userProfileId':_0x19ca3e[_0xbb10('0x56')]},'raw':!![]})[_0xbb10('0x28')](function(_0x2e3326){if(_0x2e3326&&_0x2e3326[_0xbb10('0x57')]===0x0){return db[_0xbb10('0x58')][_0xbb10('0x4f')]({'name':_0x124052[_0xbb10('0x2d')],'resourceId':_0x124052['id'],'type':_0x2e3326[_0xbb10('0x2d')],'sectionId':_0x2e3326['id']},{})[_0xbb10('0x28')](function(){return _0x1214f7;});}else{return _0x1214f7;}})[_0xbb10('0x4c')](function(_0x4475e1){logger['error'](_0xbb10('0x59'),_0x4475e1);throw _0x4475e1;});}return _0x1214f7;})[_0xbb10('0x28')](respondWithResult(_0x36aa7d,0xc9))[_0xbb10('0x4c')](handleError(_0x36aa7d,null));};exports[_0xbb10('0x27')]=function(_0xbffa3c,_0x379d8c){if(_0xbffa3c['body']['id']){delete _0xbffa3c[_0xbb10('0x50')]['id'];}return db[_0xbb10('0x30')][_0xbb10('0x55')]({'where':{'id':_0xbffa3c[_0xbb10('0x4e')]['id']}})[_0xbb10('0x28')](handleEntityNotFound(_0x379d8c,null))[_0xbb10('0x28')](saveUpdates(_0xbffa3c[_0xbb10('0x50')],null))[_0xbb10('0x28')](respondWithResult(_0x379d8c,null))[_0xbb10('0x4c')](handleError(_0x379d8c,null));};exports[_0xbb10('0x29')]=function(_0x2eb05a,_0x2a1ce1){return db[_0xbb10('0x30')]['find']({'where':{'id':_0x2eb05a['params']['id']}})[_0xbb10('0x28')](handleEntityNotFound(_0x2a1ce1,null))[_0xbb10('0x28')](removeEntity(_0x2a1ce1,null))[_0xbb10('0x4c')](handleError(_0x2a1ce1,null));};exports[_0xbb10('0x5a')]=function(_0x5573bb,_0x506498,_0x79411e){return db[_0xbb10('0x30')][_0xbb10('0x5b')]({'where':{'id':_0x5573bb[_0xbb10('0x4e')]['id']}})[_0xbb10('0x28')](handleEntityNotFound(_0x506498,null))[_0xbb10('0x28')](function(_0x45c0dc){if(!_0x5573bb['query'][_0xbb10('0x5c')]||!utils[_0xbb10('0x5d')](_0x5573bb['query']['channel'])){throw new db['Sequelize'][(_0xbb10('0x5e'))](_0xbb10('0x5f'));}var _0x155dc5={};var _0x5bd1c0={};_0x5bd1c0['model']=_['keys'](db[_[_0xbb10('0x60')](_0x5573bb[_0xbb10('0x33')][_0xbb10('0x5c')]['toLowerCase']())+_0xbb10('0x61')][_0xbb10('0x31')]);_0x5bd1c0['query']=_['keys'](_0x5573bb[_0xbb10('0x33')]);_0x5bd1c0[_0xbb10('0x37')]=_[_0xbb10('0x38')](_0x5bd1c0[_0xbb10('0x32')],_0x5bd1c0['query']);_0x155dc5[_0xbb10('0x39')]=_[_0xbb10('0x38')](_0x5bd1c0[_0xbb10('0x32')],qs['fields'](_0x5573bb[_0xbb10('0x33')][_0xbb10('0x3a')]));_0x155dc5[_0xbb10('0x39')]=_0x155dc5['attributes'][_0xbb10('0x3b')]?_0x155dc5[_0xbb10('0x39')]:_0x5bd1c0[_0xbb10('0x32')];_0x155dc5[_0xbb10('0x23')]=qs['limit'](_0x5573bb[_0xbb10('0x33')][_0xbb10('0x23')]);_0x155dc5[_0xbb10('0x22')]=qs[_0xbb10('0x22')](_0x5573bb['query'][_0xbb10('0x22')]);_0x155dc5[_0xbb10('0x3c')]=qs[_0xbb10('0x62')](_0x5573bb[_0xbb10('0x33')][_0xbb10('0x62')]);_0x155dc5[_0xbb10('0x3d')]=qs[_0xbb10('0x37')](_['pick'](_0x5573bb['query'],_0x5bd1c0['filters']));_0x155dc5=_[_0xbb10('0x46')]({},_0x155dc5,_0x5573bb[_0xbb10('0x47')]);return _0x45c0dc[_0xbb10('0x2a')+_['capitalize'](_0x5573bb['query'][_0xbb10('0x5c')][_0xbb10('0x63')]())+_0xbb10('0x64')](_0x155dc5);})[_0xbb10('0x28')](respondWithResult(_0x506498,null))[_0xbb10('0x4c')](handleError(_0x506498,null));};exports[_0xbb10('0x65')]=function(_0x4cf2f3,_0x1a5ca5,_0x15fae2){return db[_0xbb10('0x30')][_0xbb10('0x5b')]({'where':{'id':_0x4cf2f3[_0xbb10('0x4e')]['id']}})['then'](function(_0x56094a){if(_0x56094a){if(!_0x4cf2f3['body'][_0xbb10('0x5c')]||!utils[_0xbb10('0x5d')](_0x4cf2f3[_0xbb10('0x50')][_0xbb10('0x5c')])){throw new db[(_0xbb10('0x66'))][(_0xbb10('0x5e'))]('Unknown\x20channel');}return _0x56094a[_0xbb10('0x3f')+_['capitalize'](_0x4cf2f3['body']['channel'][_0xbb10('0x63')]())+_0xbb10('0x64')](_0x4cf2f3[_0xbb10('0x50')][_0xbb10('0x67')]);}return null;})['then'](handleEntityNotFound(_0x1a5ca5,null))[_0xbb10('0x28')](respondWithStatusCode(_0x1a5ca5,null))['catch'](handleError(_0x1a5ca5,null));};exports['removeQueues']=function(_0x165fe9,_0xfe3db0,_0x29529c){return db[_0xbb10('0x30')][_0xbb10('0x5b')]({'where':{'id':_0x165fe9['params']['id']}})[_0xbb10('0x28')](function(_0x19fcec){if(_0x19fcec){if(!_0x165fe9[_0xbb10('0x33')][_0xbb10('0x5c')]||!utils[_0xbb10('0x5d')](_0x165fe9[_0xbb10('0x33')][_0xbb10('0x5c')])){throw new db['Sequelize'][(_0xbb10('0x5e'))](_0xbb10('0x5f'));}return _0x19fcec[_0xbb10('0x68')+_[_0xbb10('0x60')](_0x165fe9[_0xbb10('0x33')][_0xbb10('0x5c')][_0xbb10('0x63')]())+_0xbb10('0x64')](_0x165fe9['query'][_0xbb10('0x67')]);}return null;})[_0xbb10('0x28')](handleEntityNotFound(_0xfe3db0,null))[_0xbb10('0x28')](respondWithStatusCode(_0xfe3db0,null))['catch'](handleError(_0xfe3db0,null));};exports['addAgents']=function(_0x4b923a,_0x23286d,_0x5a3c44){return db['Team'][_0xbb10('0x55')]({'where':{'id':_0x4b923a[_0xbb10('0x4e')]['id']}})[_0xbb10('0x28')](handleEntityNotFound(_0x23286d,null))[_0xbb10('0x28')](function(_0x32ec27){if(_0x32ec27){return BPromise[_0xbb10('0x69')]([_0xbb10('0x6a'),_0xbb10('0x6b'),_0xbb10('0x6c'),'sms',_0xbb10('0x6d'),_0xbb10('0x6e')],function(_0x46b6d2){return _0x32ec27[_0xbb10('0x2a')+_['capitalize'](_0x46b6d2)+'Queues']({'attributes':['id',_0xbb10('0x2d')]})[_0xbb10('0x28')](function(_0x30f0a4){return BPromise[_0xbb10('0x69')](_0x30f0a4,function(_0x5ee705){return _0x5ee705[_0xbb10('0x6f')](_0x4b923a[_0xbb10('0x50')][_0xbb10('0x67')])[_0xbb10('0x28')](function(){if(_0x46b6d2===_0xbb10('0x6a')){return db['User']['findAll']({'where':{'id':_0x4b923a[_0xbb10('0x50')][_0xbb10('0x67')]},'attributes':['id',_0xbb10('0x2d'),'loginInPause',_0xbb10('0x70'),_0xbb10('0x71')],'raw':!![]});}})['then'](function(_0x5caa06){if(_0x46b6d2===_0xbb10('0x6a')){return BPromise[_0xbb10('0x69')](_0x5caa06,function(_0x177f77){return db['UserVoiceQueueRt'][_0xbb10('0x72')]({'membername':_0x177f77[_0xbb10('0x2d')],'UserId':_0x177f77['id'],'queue_name':_0x5ee705[_0xbb10('0x2d')],'VoiceQueueId':_0x5ee705['id'],'interface':_[_0xbb10('0x73')](_0x177f77[_0xbb10('0x71')])?util[_0xbb10('0x74')](_0xbb10('0x75'),_0x177f77[_0xbb10('0x2d')]):_0x177f77[_0xbb10('0x71')],'paused':_0x177f77['voicePause']||![],'penalty':0x0});});}});});})[_0xbb10('0x28')](function(){return _0x32ec27;});})[_0xbb10('0x28')](function(){return _0x32ec27;});}})[_0xbb10('0x28')](function(_0xdb7d3e){if(_0xdb7d3e){return _0xdb7d3e[_0xbb10('0x6f')](_0x4b923a[_0xbb10('0x50')][_0xbb10('0x67')],_[_0xbb10('0x76')](_0x4b923a[_0xbb10('0x50')],[_0xbb10('0x67'),'id'])||{})[_0xbb10('0x77')](function(_0x2a4278){for(var _0x59e985=0x0;_0x59e985<_0x4b923a['body'][_0xbb10('0x67')][_0xbb10('0x3b')];_0x59e985+=0x1){socket[_0xbb10('0x78')](_0xbb10('0x79'),{'UserId':_0x4b923a[_0xbb10('0x50')]['ids'][_0x59e985],'TeamId':_0x4b923a[_0xbb10('0x4e')]['id']});}return _0x2a4278;});}})[_0xbb10('0x28')](respondWithResult(_0x23286d,null))[_0xbb10('0x4c')](handleError(_0x23286d,null));};exports[_0xbb10('0x7a')]=function(_0x19694d,_0x379d49,_0x546db5){var _0xb25e71;return db[_0xbb10('0x30')]['find']({'where':{'id':_0x19694d[_0xbb10('0x4e')]['id']}})['then'](handleEntityNotFound(_0x379d49,null))[_0xbb10('0x28')](function(_0x28bd76){if(_0x28bd76){return BPromise[_0xbb10('0x69')]([_0xbb10('0x6a'),_0xbb10('0x6b'),'mail',_0xbb10('0x7b'),'fax',_0xbb10('0x6e')],function(_0x37ec93){return _0x28bd76['get'+_['capitalize'](_0x37ec93)+_0xbb10('0x64')]({'attributes':['id',_0xbb10('0x2d')]})[_0xbb10('0x28')](function(_0x283bab){return BPromise[_0xbb10('0x69')](_0x283bab,function(_0x1cb22f){return _0x1cb22f[_0xbb10('0x7a')](_0x19694d[_0xbb10('0x33')][_0xbb10('0x67')])[_0xbb10('0x28')](function(){if(_0x37ec93===_0xbb10('0x6a')){return db['UserVoiceQueueRt'][_0xbb10('0x29')]({'where':{'VoiceQueueId':_0x1cb22f['id'],'UserId':_0x19694d[_0xbb10('0x33')][_0xbb10('0x67')]}});}});});})[_0xbb10('0x28')](function(){return _0x28bd76;});})[_0xbb10('0x28')](function(){return _0x28bd76;});}})[_0xbb10('0x28')](function(_0xfefa17){if(_0xfefa17){return _0xfefa17[_0xbb10('0x7a')](_0x19694d[_0xbb10('0x33')][_0xbb10('0x67')])[_0xbb10('0x28')](function(_0x2d3e98){if(_['isArray'](_0x19694d[_0xbb10('0x33')]['ids'])){for(var _0x1b6d7d=0x0;_0x1b6d7d<_0x19694d[_0xbb10('0x33')][_0xbb10('0x67')][_0xbb10('0x3b')];_0x1b6d7d+=0x1){socket[_0xbb10('0x78')]('userTeam:remove',{'UserId':_0x19694d[_0xbb10('0x33')][_0xbb10('0x67')][_0x1b6d7d],'TeamId':_0x19694d[_0xbb10('0x4e')]['id']});}}else{socket[_0xbb10('0x78')](_0xbb10('0x7c'),{'UserId':_0x19694d[_0xbb10('0x33')]['ids'],'TeamId':_0x19694d['params']['id']});}});}})[_0xbb10('0x28')](respondWithStatusCode(_0x379d49,null))[_0xbb10('0x4c')](handleError(_0x379d49,null));};exports[_0xbb10('0x7d')]=function(_0x57d5a1,_0x124b32,_0x3d6a91){var _0x514fdf={};var _0x2831de={};var _0xaede56;var _0x5642c3;return db[_0xbb10('0x30')]['findOne']({'where':{'id':_0x57d5a1[_0xbb10('0x4e')]['id']}})[_0xbb10('0x28')](handleEntityNotFound(_0x124b32,null))['then'](function(_0x34a5a3){if(_0x34a5a3){_0xaede56=_0x34a5a3;_0x2831de[_0xbb10('0x32')]=_['keys'](db['User'][_0xbb10('0x31')]);_0x2831de[_0xbb10('0x33')]=_[_0xbb10('0x36')](_0x57d5a1[_0xbb10('0x33')]);_0x2831de[_0xbb10('0x37')]=_['intersection'](_0x2831de[_0xbb10('0x32')],_0x2831de[_0xbb10('0x33')]);_0x514fdf[_0xbb10('0x39')]=_['intersection'](_0x2831de[_0xbb10('0x32')],qs[_0xbb10('0x3a')](_0x57d5a1[_0xbb10('0x33')][_0xbb10('0x3a')]));_0x514fdf[_0xbb10('0x39')]=_0x514fdf[_0xbb10('0x39')][_0xbb10('0x3b')]?_0x514fdf[_0xbb10('0x39')]:_0x2831de[_0xbb10('0x32')];_0x514fdf['order']=qs['sort'](_0x57d5a1[_0xbb10('0x33')][_0xbb10('0x62')]);_0x514fdf[_0xbb10('0x3d')]=qs[_0xbb10('0x37')](_[_0xbb10('0x3e')](_0x57d5a1[_0xbb10('0x33')],_0x2831de[_0xbb10('0x37')]));if(_0x57d5a1[_0xbb10('0x33')][_0xbb10('0x41')]){_0x514fdf[_0xbb10('0x3d')]=_[_0xbb10('0x46')](_0x514fdf[_0xbb10('0x3d')],{'$or':_[_0xbb10('0x42')](_0x514fdf['attributes'],function(_0x1e022d){var _0x123587={};_0x123587[_0x1e022d]={'$like':'%'+_0x57d5a1[_0xbb10('0x33')][_0xbb10('0x41')]+'%'};return _0x123587;})});}_0x514fdf=_[_0xbb10('0x46')]({},_0x514fdf,_0x57d5a1[_0xbb10('0x47')]);return _0xaede56[_0xbb10('0x7d')](_0x514fdf);}})[_0xbb10('0x28')](function(_0x3c6c45){if(_0x3c6c45){_0x5642c3=_0x3c6c45[_0xbb10('0x3b')];if(!_0x57d5a1[_0xbb10('0x33')]['hasOwnProperty'](_0xbb10('0x7e'))){_0x514fdf['limit']=qs[_0xbb10('0x23')](_0x57d5a1[_0xbb10('0x33')][_0xbb10('0x23')]);_0x514fdf[_0xbb10('0x22')]=qs[_0xbb10('0x22')](_0x57d5a1[_0xbb10('0x33')]['offset']);}return _0xaede56[_0xbb10('0x7d')](_0x514fdf);}})['then'](function(_0xd82ce1){if(_0xd82ce1){return _0xd82ce1?{'count':_0x5642c3,'rows':_0xd82ce1}:null;}})[_0xbb10('0x28')](respondWithResult(_0x124b32,null))[_0xbb10('0x4c')](handleError(_0x124b32,null));};