86541d17a601ea152b1f2c75710cb861b824d3da
[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 _0x647f=['create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','find','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','getQueues','findOne','channel','Sequelize','ValidationError','Unknown\x20channel','capitalize','toLowerCase','Queues','addQueues','isValidChannel','add','ids','removeQueues','remove','addAgents','Voice','Mail','Fax','Openchannel','each','User','online','voicePause','UserVoiceQueueRt','upsert','format','SIP/%s','omit','spread','userTeam:save','removeAgents','voice','chat','mail','sms','fax','openchannel','isArray','emit','userTeam:remove','getAgents','eml-format','rimraf','fast-json-patch','moment','bluebird','mustache','path','sox','to-csv','ejs','lodash','squel','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/utils','defaults','redis','localhost','socket.io-emitter','./team.socket','register','sendStatus','status','end','count','offset','set','Content-Range','json','apply','reject','save','update','then','destroy','get','Teams','UserProfileResource','stack','name','send','index','Team','rawAttributes','keys','query','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','filters','pick','merge','map','key','VIRTUAL','field','filter','includeAll','include','findAll','catch','show','params','options'];(function(_0xae44bb,_0x76b2d0){var _0x34cc1d=function(_0x42eb6e){while(--_0x42eb6e){_0xae44bb['push'](_0xae44bb['shift']());}};_0x34cc1d(++_0x76b2d0);}(_0x647f,0x134));var _0xf647=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0x647f[_0x321bb2];return _0x9c12ed;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xf647('0x0'));var rimraf=require(_0xf647('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf647('0x2'));var rp=require('request-promise');var moment=require(_0xf647('0x3'));var BPromise=require(_0xf647('0x4'));var Mustache=require(_0xf647('0x5'));var util=require('util');var path=require(_0xf647('0x6'));var sox=require(_0xf647('0x7'));var csv=require(_0xf647('0x8'));var ejs=require(_0xf647('0x9'));var fs=require('fs');var _=require(_0xf647('0xa'));var squel=require(_0xf647('0xb'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xf647('0xc'));var toCsv=require('to-csv');var querystring=require(_0xf647('0xd'));var Papa=require(_0xf647('0xe'));var Redis=require('ioredis');var authService=require(_0xf647('0xf'));var qs=require(_0xf647('0x10'));var hardwareService=require(_0xf647('0x11'));var logger=require('../../config/logger')('api');var utils=require(_0xf647('0x12'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];config['redis']=_[_0xf647('0x13')](config[_0xf647('0x14')],{'host':_0xf647('0x15'),'port':0x18eb});var socket=require(_0xf647('0x16'))(new Redis(config[_0xf647('0x14')]));require(_0xf647('0x17'))[_0xf647('0x18')](socket);function respondWithStatusCode(_0x37ba5f,_0x5e4818){_0x5e4818=_0x5e4818||0xcc;return function(_0x6c293){if(_0x6c293){return _0x37ba5f[_0xf647('0x19')](_0x5e4818);}return _0x37ba5f[_0xf647('0x1a')](_0x5e4818)[_0xf647('0x1b')]();};}function respondWithResult(_0x46e596,_0x52ac48){_0x52ac48=_0x52ac48||0xc8;return function(_0x38b36e){if(_0x38b36e){return _0x46e596[_0xf647('0x1a')](_0x52ac48)['json'](_0x38b36e);}};}function respondWithFilteredResult(_0xc8146c,_0x3d0634){return function(_0x44ea83){if(_0x44ea83){var _0x35d823=_0x44ea83[_0xf647('0x1c')],_0x15b396=_0x3d0634[_0xf647('0x1d')],_0x5286ac=_0x3d0634[_0xf647('0x1d')]+_0x3d0634['limit'],_0xca1c0e;if(_0x5286ac>=_0x35d823){_0x5286ac=_0x35d823;_0xca1c0e=0xc8;}else{_0xca1c0e=0xce;}_0xc8146c['status'](_0xca1c0e);return _0xc8146c[_0xf647('0x1e')](_0xf647('0x1f'),_0x15b396+'-'+_0x5286ac+'/'+_0x35d823)[_0xf647('0x20')](_0x44ea83);}return null;};}function patchUpdates(_0x5090a1){return function(_0xbbb7cb){try{jsonpatch[_0xf647('0x21')](_0xbbb7cb,_0x5090a1,!![]);}catch(_0x25ccf1){return BPromise[_0xf647('0x22')](_0x25ccf1);}return _0xbbb7cb[_0xf647('0x23')]();};}function saveUpdates(_0x323b78,_0x83b04d){return function(_0x5f426b){if(_0x5f426b){return _0x5f426b[_0xf647('0x24')](_0x323b78)[_0xf647('0x25')](function(_0x575af9){return _0x575af9;});}return null;};}function removeEntity(_0x4c773a,_0x31e75a){return function(_0x1a0024){if(_0x1a0024){return _0x1a0024[_0xf647('0x26')]()[_0xf647('0x25')](function(){var _0x58e28b=_0x1a0024[_0xf647('0x27')]({'plain':!![]});var _0x10be2a=_0xf647('0x28');return db[_0xf647('0x29')][_0xf647('0x26')]({'where':{'type':_0x10be2a,'resourceId':_0x58e28b['id']}})[_0xf647('0x25')](function(){return _0x1a0024;});})['then'](function(){_0x4c773a['status'](0xcc)[_0xf647('0x1b')]();});}};}function handleEntityNotFound(_0x31a019,_0x1d98f4){return function(_0x4840fc){if(!_0x4840fc){_0x31a019[_0xf647('0x19')](0x194);}return _0x4840fc;};}function handleError(_0x5caf12,_0x2c29e7){_0x2c29e7=_0x2c29e7||0x1f4;return function(_0x471e4d){logger['error'](_0x471e4d[_0xf647('0x2a')]);if(_0x471e4d[_0xf647('0x2b')]){delete _0x471e4d['name'];}_0x5caf12[_0xf647('0x1a')](_0x2c29e7)[_0xf647('0x2c')](_0x471e4d);};}exports[_0xf647('0x2d')]=function(_0x290c38,_0x3e1bd1){var _0x141b0b={},_0x1c5ef1={},_0x565af6={'count':0x0,'rows':[]};var _0x4a662d=db[_0xf647('0x2e')][_0xf647('0x2f')];_0x1c5ef1['model']=_[_0xf647('0x30')](_0x4a662d);_0x1c5ef1[_0xf647('0x31')]=_['keys'](_0x290c38[_0xf647('0x31')]);_0x1c5ef1['filters']=_[_0xf647('0x32')](_0x1c5ef1[_0xf647('0x33')],_0x1c5ef1[_0xf647('0x31')]);_0x141b0b[_0xf647('0x34')]=_[_0xf647('0x32')](_0x1c5ef1['model'],qs[_0xf647('0x35')](_0x290c38[_0xf647('0x31')]['fields']));_0x141b0b['attributes']=_0x141b0b[_0xf647('0x34')][_0xf647('0x36')]?_0x141b0b[_0xf647('0x34')]:_0x1c5ef1['model'];if(!_0x290c38[_0xf647('0x31')][_0xf647('0x37')](_0xf647('0x38'))){_0x141b0b['limit']=qs['limit'](_0x290c38[_0xf647('0x31')][_0xf647('0x39')]);_0x141b0b[_0xf647('0x1d')]=qs[_0xf647('0x1d')](_0x290c38[_0xf647('0x31')][_0xf647('0x1d')]);}_0x141b0b[_0xf647('0x3a')]=qs[_0xf647('0x3b')](_0x290c38['query'][_0xf647('0x3b')]);_0x141b0b[_0xf647('0x3c')]=qs[_0xf647('0x3d')](_[_0xf647('0x3e')](_0x290c38['query'],_0x1c5ef1['filters']));if(_0x290c38[_0xf647('0x31')]['filter']){_0x141b0b[_0xf647('0x3c')]=_[_0xf647('0x3f')](_0x141b0b['where'],{'$or':_[_0xf647('0x40')](_0x4a662d,function(_0x351804){if(_0x351804['type'][_0xf647('0x41')]!==_0xf647('0x42')){var _0x57e236={};_0x57e236[_0x351804[_0xf647('0x43')]]={'$like':'%'+_0x290c38['query'][_0xf647('0x44')]+'%'};return _0x57e236;}})});}_0x141b0b=_[_0xf647('0x3f')]({},_0x141b0b,_0x290c38['options']);var _0x139a59={'where':_0x141b0b[_0xf647('0x3c')]};return db[_0xf647('0x2e')][_0xf647('0x1c')](_0x139a59)['then'](function(_0x12beaf){_0x565af6[_0xf647('0x1c')]=_0x12beaf;if(_0x290c38['query'][_0xf647('0x45')]){_0x141b0b[_0xf647('0x46')]=[{'all':!![]}];}return db[_0xf647('0x2e')][_0xf647('0x47')](_0x141b0b);})[_0xf647('0x25')](function(_0x31ac48){_0x565af6['rows']=_0x31ac48;return _0x565af6;})[_0xf647('0x25')](respondWithFilteredResult(_0x3e1bd1,_0x141b0b))[_0xf647('0x48')](handleError(_0x3e1bd1,null));};exports[_0xf647('0x49')]=function(_0x17fe20,_0x44e517){var _0x6b8c2={'raw':![],'where':{'id':_0x17fe20[_0xf647('0x4a')]['id']}},_0x2b512a={};_0x2b512a[_0xf647('0x33')]=_[_0xf647('0x30')](db['Team'][_0xf647('0x2f')]);_0x2b512a[_0xf647('0x31')]=_[_0xf647('0x30')](_0x17fe20[_0xf647('0x31')]);_0x2b512a[_0xf647('0x3d')]=_['intersection'](_0x2b512a[_0xf647('0x33')],_0x2b512a['query']);_0x6b8c2[_0xf647('0x34')]=_[_0xf647('0x32')](_0x2b512a[_0xf647('0x33')],qs[_0xf647('0x35')](_0x17fe20[_0xf647('0x31')][_0xf647('0x35')]));_0x6b8c2[_0xf647('0x34')]=_0x6b8c2[_0xf647('0x34')][_0xf647('0x36')]?_0x6b8c2[_0xf647('0x34')]:_0x2b512a['model'];if(_0x17fe20[_0xf647('0x31')][_0xf647('0x45')]){_0x6b8c2[_0xf647('0x46')]=[{'all':!![]}];}_0x6b8c2=_[_0xf647('0x3f')]({},_0x6b8c2,_0x17fe20[_0xf647('0x4b')]);return db['Team']['find'](_0x6b8c2)[_0xf647('0x25')](handleEntityNotFound(_0x44e517,null))[_0xf647('0x25')](respondWithResult(_0x44e517,null))[_0xf647('0x48')](handleError(_0x44e517,null));};exports[_0xf647('0x4c')]=function(_0xa993b,_0x31e228){return db[_0xf647('0x2e')][_0xf647('0x4c')](_0xa993b[_0xf647('0x4d')],{})[_0xf647('0x25')](function(_0x3d6932){var _0x23db3c=_0xa993b['user'][_0xf647('0x27')]({'plain':!![]});if(!_0x23db3c)throw new Error(_0xf647('0x4e'));if(_0x23db3c[_0xf647('0x4f')]===_0xf647('0x50')){var _0x3e6eb2=_0x3d6932[_0xf647('0x27')]({'plain':!![]});var _0x59ab39=_0xf647('0x28');return db[_0xf647('0x51')][_0xf647('0x52')]({'where':{'name':_0x59ab39,'userProfileId':_0x23db3c['userProfileId']},'raw':!![]})['then'](function(_0x133b62){if(_0x133b62&&_0x133b62[_0xf647('0x53')]===0x0){return db[_0xf647('0x29')][_0xf647('0x4c')]({'name':_0x3e6eb2[_0xf647('0x2b')],'resourceId':_0x3e6eb2['id'],'type':_0x133b62['name'],'sectionId':_0x133b62['id']},{})[_0xf647('0x25')](function(){return _0x3d6932;});}else{return _0x3d6932;}})[_0xf647('0x48')](function(_0x35d81e){logger[_0xf647('0x54')](_0xf647('0x55'),_0x35d81e);throw _0x35d81e;});}return _0x3d6932;})[_0xf647('0x25')](respondWithResult(_0x31e228,0xc9))[_0xf647('0x48')](handleError(_0x31e228,null));};exports[_0xf647('0x24')]=function(_0x17a057,_0x245ecf){if(_0x17a057[_0xf647('0x4d')]['id']){delete _0x17a057[_0xf647('0x4d')]['id'];}return db[_0xf647('0x2e')][_0xf647('0x52')]({'where':{'id':_0x17a057[_0xf647('0x4a')]['id']}})['then'](handleEntityNotFound(_0x245ecf,null))[_0xf647('0x25')](saveUpdates(_0x17a057[_0xf647('0x4d')],null))[_0xf647('0x25')](respondWithResult(_0x245ecf,null))[_0xf647('0x48')](handleError(_0x245ecf,null));};exports[_0xf647('0x26')]=function(_0x4ed85a,_0x5a4e79){return db[_0xf647('0x2e')][_0xf647('0x52')]({'where':{'id':_0x4ed85a[_0xf647('0x4a')]['id']}})[_0xf647('0x25')](handleEntityNotFound(_0x5a4e79,null))['then'](removeEntity(_0x5a4e79,null))[_0xf647('0x48')](handleError(_0x5a4e79,null));};exports[_0xf647('0x56')]=function(_0x1cf705,_0x156165,_0x1ddd24){return db['Team'][_0xf647('0x57')]({'where':{'id':_0x1cf705[_0xf647('0x4a')]['id']}})[_0xf647('0x25')](handleEntityNotFound(_0x156165,null))[_0xf647('0x25')](function(_0x38286e){if(!_0x1cf705[_0xf647('0x31')][_0xf647('0x58')]||!utils['isValidChannel'](_0x1cf705['query'][_0xf647('0x58')])){throw new db[(_0xf647('0x59'))][(_0xf647('0x5a'))](_0xf647('0x5b'));}var _0x38b325={};var _0x5e9fb1={};_0x5e9fb1['model']=_[_0xf647('0x30')](db[_[_0xf647('0x5c')](_0x1cf705['query']['channel'][_0xf647('0x5d')]())+'Queue'][_0xf647('0x2f')]);_0x5e9fb1[_0xf647('0x31')]=_[_0xf647('0x30')](_0x1cf705[_0xf647('0x31')]);_0x5e9fb1['filters']=_[_0xf647('0x32')](_0x5e9fb1[_0xf647('0x33')],_0x5e9fb1['query']);_0x38b325[_0xf647('0x34')]=_['intersection'](_0x5e9fb1[_0xf647('0x33')],qs[_0xf647('0x35')](_0x1cf705['query'][_0xf647('0x35')]));_0x38b325[_0xf647('0x34')]=_0x38b325['attributes']['length']?_0x38b325[_0xf647('0x34')]:_0x5e9fb1[_0xf647('0x33')];_0x38b325[_0xf647('0x39')]=qs[_0xf647('0x39')](_0x1cf705[_0xf647('0x31')]['limit']);_0x38b325[_0xf647('0x1d')]=qs['offset'](_0x1cf705[_0xf647('0x31')][_0xf647('0x1d')]);_0x38b325[_0xf647('0x3a')]=qs[_0xf647('0x3b')](_0x1cf705[_0xf647('0x31')][_0xf647('0x3b')]);_0x38b325['where']=qs['filters'](_[_0xf647('0x3e')](_0x1cf705['query'],_0x5e9fb1['filters']));_0x38b325=_[_0xf647('0x3f')]({},_0x38b325,_0x1cf705[_0xf647('0x4b')]);return _0x38286e[_0xf647('0x27')+_[_0xf647('0x5c')](_0x1cf705[_0xf647('0x31')][_0xf647('0x58')][_0xf647('0x5d')]())+_0xf647('0x5e')](_0x38b325);})['then'](respondWithResult(_0x156165,null))[_0xf647('0x48')](handleError(_0x156165,null));};exports[_0xf647('0x5f')]=function(_0x69988f,_0x5a0e2a,_0x5bfb88){return db['Team'][_0xf647('0x57')]({'where':{'id':_0x69988f['params']['id']}})[_0xf647('0x25')](function(_0x1073e0){if(_0x1073e0){if(!_0x69988f['body'][_0xf647('0x58')]||!utils[_0xf647('0x60')](_0x69988f['body'][_0xf647('0x58')])){throw new db['Sequelize'][(_0xf647('0x5a'))](_0xf647('0x5b'));}return _0x1073e0[_0xf647('0x61')+_['capitalize'](_0x69988f[_0xf647('0x4d')][_0xf647('0x58')]['toLowerCase']())+_0xf647('0x5e')](_0x69988f[_0xf647('0x4d')][_0xf647('0x62')]);}return null;})['then'](handleEntityNotFound(_0x5a0e2a,null))[_0xf647('0x25')](respondWithStatusCode(_0x5a0e2a,null))[_0xf647('0x48')](handleError(_0x5a0e2a,null));};exports[_0xf647('0x63')]=function(_0xb0444a,_0x11b375,_0x2ebb23){return db[_0xf647('0x2e')][_0xf647('0x57')]({'where':{'id':_0xb0444a[_0xf647('0x4a')]['id']}})[_0xf647('0x25')](function(_0x13e5b4){if(_0x13e5b4){if(!_0xb0444a[_0xf647('0x31')][_0xf647('0x58')]||!utils['isValidChannel'](_0xb0444a[_0xf647('0x31')][_0xf647('0x58')])){throw new db[(_0xf647('0x59'))][(_0xf647('0x5a'))]('Unknown\x20channel');}return _0x13e5b4[_0xf647('0x64')+_[_0xf647('0x5c')](_0xb0444a[_0xf647('0x31')][_0xf647('0x58')]['toLowerCase']())+_0xf647('0x5e')](_0xb0444a['query'][_0xf647('0x62')]);}return null;})[_0xf647('0x25')](handleEntityNotFound(_0x11b375,null))[_0xf647('0x25')](respondWithStatusCode(_0x11b375,null))['catch'](handleError(_0x11b375,null));};exports[_0xf647('0x65')]=function(_0x5c3a08,_0x1290ef,_0x2a5c7b){return db['Team'][_0xf647('0x52')]({'where':{'id':_0x5c3a08[_0xf647('0x4a')]['id']}})[_0xf647('0x25')](handleEntityNotFound(_0x1290ef,null))[_0xf647('0x25')](function(_0x2d6660){if(_0x2d6660){var _0xf22b38=[_0xf647('0x66'),'Chat',_0xf647('0x67'),'Sms',_0xf647('0x68'),_0xf647('0x69')];return BPromise[_0xf647('0x6a')](_0xf22b38,function(_0x37a0b9){return _0x2d6660[_0xf647('0x27')+_0x37a0b9+_0xf647('0x5e')]({'attributes':['id','name']})['then'](function(_0x8682bd){return BPromise[_0xf647('0x6a')](_0x8682bd,function(_0x4811b5){return _0x4811b5[_0xf647('0x65')](_0x5c3a08[_0xf647('0x4d')][_0xf647('0x62')])[_0xf647('0x25')](function(){if(_0x37a0b9===_0xf647('0x66')){return db[_0xf647('0x6b')]['findAll']({'where':{'id':_0x5c3a08[_0xf647('0x4d')]['ids']},'attributes':['id',_0xf647('0x2b'),_0xf647('0x6c'),_0xf647('0x6d'),'interface'],'raw':!![]})[_0xf647('0x25')](function(_0x4fd59f){return BPromise[_0xf647('0x6a')](_[_0xf647('0x44')](_0x4fd59f,{'online':0x1}),function(_0x25154f){return db[_0xf647('0x6e')][_0xf647('0x6f')]({'membername':_0x25154f[_0xf647('0x2b')],'UserId':_0x25154f['id'],'queue_name':_0x4811b5[_0xf647('0x2b')],'VoiceQueueId':_0x4811b5['id'],'interface':_['isNil'](_0x25154f['interface'])?util[_0xf647('0x70')](_0xf647('0x71'),_0x25154f[_0xf647('0x2b')]):_0x25154f['interface'],'paused':_0x25154f['voicePause']||![],'penalty':0x0});});});}});});})[_0xf647('0x25')](function(){return _0x2d6660;});})[_0xf647('0x25')](function(){return _0x2d6660;});}})[_0xf647('0x25')](function(_0x490d18){if(_0x490d18){return _0x490d18[_0xf647('0x65')](_0x5c3a08[_0xf647('0x4d')][_0xf647('0x62')],_[_0xf647('0x72')](_0x5c3a08[_0xf647('0x4d')],[_0xf647('0x62'),'id'])||{})[_0xf647('0x73')](function(_0x434d75){for(var _0xcf8674=0x0;_0xcf8674<_0x5c3a08['body']['ids'][_0xf647('0x36')];_0xcf8674+=0x1){socket['emit'](_0xf647('0x74'),{'UserId':_0x5c3a08[_0xf647('0x4d')][_0xf647('0x62')][_0xcf8674],'TeamId':_0x5c3a08[_0xf647('0x4a')]['id']});}return _0x434d75;});}})['then'](respondWithResult(_0x1290ef,null))[_0xf647('0x48')](handleError(_0x1290ef,null));};exports[_0xf647('0x75')]=function(_0x13069e,_0x20dd07,_0x1e6af5){return db[_0xf647('0x2e')][_0xf647('0x52')]({'where':{'id':_0x13069e['params']['id']}})[_0xf647('0x25')](handleEntityNotFound(_0x20dd07,null))['then'](function(_0x5413df){if(_0x5413df){return BPromise[_0xf647('0x6a')]([_0xf647('0x76'),_0xf647('0x77'),_0xf647('0x78'),_0xf647('0x79'),_0xf647('0x7a'),_0xf647('0x7b')],function(_0x40e431){return _0x5413df[_0xf647('0x27')+_[_0xf647('0x5c')](_0x40e431)+_0xf647('0x5e')]({'attributes':['id',_0xf647('0x2b')]})[_0xf647('0x25')](function(_0x5a5276){return BPromise['each'](_0x5a5276,function(_0x172b9f){return _0x172b9f[_0xf647('0x75')](_0x13069e[_0xf647('0x31')][_0xf647('0x62')])[_0xf647('0x25')](function(){if(_0x40e431===_0xf647('0x76')){return db[_0xf647('0x6e')][_0xf647('0x26')]({'where':{'VoiceQueueId':_0x172b9f['id'],'UserId':_0x13069e[_0xf647('0x31')][_0xf647('0x62')]}});}});});})['then'](function(){return _0x5413df;});})[_0xf647('0x25')](function(){return _0x5413df;});}})[_0xf647('0x25')](function(_0x3d6070){if(_0x3d6070){return _0x3d6070[_0xf647('0x75')](_0x13069e[_0xf647('0x31')][_0xf647('0x62')])[_0xf647('0x25')](function(){if(_[_0xf647('0x7c')](_0x13069e['query'][_0xf647('0x62')])){for(var _0x2ce3b0=0x0;_0x2ce3b0<_0x13069e['query']['ids']['length'];_0x2ce3b0+=0x1){socket['emit']('userTeam:remove',{'UserId':Number(_0x13069e[_0xf647('0x31')][_0xf647('0x62')][_0x2ce3b0]),'TeamId':Number(_0x13069e['params']['id'])});}}else{socket[_0xf647('0x7d')](_0xf647('0x7e'),{'UserId':Number(_0x13069e[_0xf647('0x31')][_0xf647('0x62')]),'TeamId':Number(_0x13069e['params']['id'])});}});}})[_0xf647('0x25')](respondWithStatusCode(_0x20dd07,null))[_0xf647('0x48')](handleError(_0x20dd07,null));};exports[_0xf647('0x7f')]=function(_0x18086e,_0x5df2d8,_0x4e64d9){var _0x5c4c07={};var _0x5b3aa3={};var _0x58ce30;var _0x14be74;return db[_0xf647('0x2e')][_0xf647('0x57')]({'where':{'id':_0x18086e[_0xf647('0x4a')]['id']}})[_0xf647('0x25')](handleEntityNotFound(_0x5df2d8,null))[_0xf647('0x25')](function(_0x1a4563){if(_0x1a4563){_0x58ce30=_0x1a4563;_0x5b3aa3[_0xf647('0x33')]=_[_0xf647('0x30')](db[_0xf647('0x6b')][_0xf647('0x2f')]);_0x5b3aa3['query']=_[_0xf647('0x30')](_0x18086e[_0xf647('0x31')]);_0x5b3aa3[_0xf647('0x3d')]=_[_0xf647('0x32')](_0x5b3aa3[_0xf647('0x33')],_0x5b3aa3[_0xf647('0x31')]);_0x5c4c07[_0xf647('0x34')]=_[_0xf647('0x32')](_0x5b3aa3[_0xf647('0x33')],qs[_0xf647('0x35')](_0x18086e[_0xf647('0x31')][_0xf647('0x35')]));_0x5c4c07['attributes']=_0x5c4c07['attributes'][_0xf647('0x36')]?_0x5c4c07[_0xf647('0x34')]:_0x5b3aa3[_0xf647('0x33')];_0x5c4c07[_0xf647('0x3a')]=qs[_0xf647('0x3b')](_0x18086e[_0xf647('0x31')][_0xf647('0x3b')]);_0x5c4c07['where']=qs[_0xf647('0x3d')](_[_0xf647('0x3e')](_0x18086e['query'],_0x5b3aa3['filters']));if(_0x18086e[_0xf647('0x31')][_0xf647('0x44')]){_0x5c4c07[_0xf647('0x3c')]=_[_0xf647('0x3f')](_0x5c4c07[_0xf647('0x3c')],{'$or':_[_0xf647('0x40')](_0x5c4c07['attributes'],function(_0x5b49b6){var _0x4f4290={};_0x4f4290[_0x5b49b6]={'$like':'%'+_0x18086e[_0xf647('0x31')][_0xf647('0x44')]+'%'};return _0x4f4290;})});}_0x5c4c07=_[_0xf647('0x3f')]({},_0x5c4c07,_0x18086e[_0xf647('0x4b')]);return _0x58ce30[_0xf647('0x7f')](_0x5c4c07);}})[_0xf647('0x25')](function(_0x8e0ed4){if(_0x8e0ed4){_0x14be74=_0x8e0ed4[_0xf647('0x36')];if(!_0x18086e[_0xf647('0x31')][_0xf647('0x37')](_0xf647('0x38'))){_0x5c4c07[_0xf647('0x39')]=qs[_0xf647('0x39')](_0x18086e[_0xf647('0x31')][_0xf647('0x39')]);_0x5c4c07[_0xf647('0x1d')]=qs[_0xf647('0x1d')](_0x18086e[_0xf647('0x31')][_0xf647('0x1d')]);}return _0x58ce30[_0xf647('0x7f')](_0x5c4c07);}})['then'](function(_0x440693){if(_0x440693){return _0x440693?{'count':_0x14be74,'rows':_0x440693}:null;}})['then'](respondWithResult(_0x5df2d8,null))[_0xf647('0x48')](handleError(_0x5df2d8,null));};