Built motion from commit e02f907f.|2.6.14
[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 _0x122e=['error','stack','name','send','index','map','Team','rawAttributes','fieldName','type','key','model','keys','query','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','params','find','body','user','Teams','UserProfileSection','userProfileId','UserProfileResource','create','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','sequelize','transaction','SELECT\x20UserId\x20FROM\x20user_has_teams\x20WHERE\x20TeamId\x20=\x20','Sequelize','QueryTypes','SELECT\x20VoiceQueueId\x20FROM\x20team_has_voice_queues\x20WHERE\x20TeamId\x20=\x20','SELECT','VoiceQueueId','UserVoiceQueue','SELECT\x20MailQueueId\x20FROM\x20team_has_mail_queues\x20WHERE\x20TeamId\x20=\x20','MailQueueId','destroy','SELECT\x20SmsQueueId\x20FROM\x20team_has_sms_queues\x20WHERE\x20TeamId\x20=\x20','SmsQueueId','UserSmsQueue','UserChatQueue','SELECT\x20FaxQueueId\x20FROM\x20team_has_fax_queues\x20WHERE\x20TeamId\x20=\x20','SELECT\x20OpenchannelQueueId\x20FROM\x20team_has_openchannel_queues\x20WHERE\x20TeamId\x20=\x20','OpenchannelQueueId','UserOpenchannelQueue','SELECT\x20WhatsappQueueId\x20FROM\x20team_has_whatsapp_queues\x20WHERE\x20TeamId\x20=\x20','TeamVoicePrefix','UserVoicePrefix','getQueues','findOne','isValidChannel','channel','ValidationError','Unknown\x20channel','capitalize','toLowerCase','pick','get','Queues','addQueues','add','ids','remove','addAgents','Voice','Chat','Sms','Fax','Whatsapp','penalty','QueueId','User','Queue','findOrCreate','emit','Queue:save','online','UserVoiceQueueRt','isNil','interface','format','SIP/%s','voicePause','TeamVoiceQueue','all','upsert','VoicePrefixId','spread','isArray','Mail','Openchannel','removeAgents','getAgents','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','util','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','defaults','redis','socket.io-emitter','register','status','end','json','offset','undefined','limit','count','apply','reject','update','then','sendStatus'];(function(_0x4b65d2,_0x99cc45){var _0x1a954d=function(_0x28f9fc){while(--_0x28f9fc){_0x4b65d2['push'](_0x4b65d2['shift']());}};_0x1a954d(++_0x99cc45);}(_0x122e,0x6f));var _0xe122=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0x122e[_0x321bb2];return _0x9c12ed;};'use strict';var emlformat=require(_0xe122('0x0'));var rimraf=require(_0xe122('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xe122('0x2'));var rp=require(_0xe122('0x3'));var moment=require(_0xe122('0x4'));var BPromise=require(_0xe122('0x5'));var Mustache=require('mustache');var util=require(_0xe122('0x6'));var path=require('path');var sox=require(_0xe122('0x7'));var csv=require('to-csv');var ejs=require(_0xe122('0x8'));var fs=require('fs');var fs_extra=require(_0xe122('0x9'));var _=require(_0xe122('0xa'));var squel=require(_0xe122('0xb'));var crypto=require(_0xe122('0xc'));var jsforce=require(_0xe122('0xd'));var deskjs=require('desk.js');var toCsv=require(_0xe122('0xe'));var querystring=require(_0xe122('0xf'));var Papa=require(_0xe122('0x10'));var Redis=require(_0xe122('0x11'));var authService=require(_0xe122('0x12'));var qs=require(_0xe122('0x13'));var as=require(_0xe122('0x14'));var hardwareService=require(_0xe122('0x15'));var logger=require('../../config/logger')('api');var utils=require(_0xe122('0x16'));var config=require(_0xe122('0x17'));var licenseUtil=require(_0xe122('0x18'));var db=require('../../mysqldb')['db'];config['redis']=_[_0xe122('0x19')](config[_0xe122('0x1a')],{'host':'localhost','port':0x18eb});var socket=require(_0xe122('0x1b'))(new Redis(config[_0xe122('0x1a')]));require('./team.socket')[_0xe122('0x1c')](socket);function respondWithStatusCode(_0x1ff672,_0x16059d){_0x16059d=_0x16059d||0xcc;return function(_0x547a2b){if(_0x547a2b){return _0x1ff672['sendStatus'](_0x16059d);}return _0x1ff672[_0xe122('0x1d')](_0x16059d)[_0xe122('0x1e')]();};}function respondWithResult(_0x23289a,_0x402931){_0x402931=_0x402931||0xc8;return function(_0x2042cb){if(_0x2042cb){return _0x23289a[_0xe122('0x1d')](_0x402931)[_0xe122('0x1f')](_0x2042cb);}};}function respondWithFilteredResult(_0x2512db,_0x1099bc){return function(_0x4722f7){if(_0x4722f7){var _0x1f035c=typeof _0x1099bc[_0xe122('0x20')]===_0xe122('0x21')&&typeof _0x1099bc[_0xe122('0x22')]==='undefined';var _0x5706ad=_0x4722f7[_0xe122('0x23')];var _0x5ba613=_0x1f035c?0x0:_0x1099bc[_0xe122('0x20')];var _0x490deb=_0x1f035c?_0x4722f7['count']:_0x1099bc[_0xe122('0x20')]+_0x1099bc[_0xe122('0x22')];var _0x2166d7;if(_0x490deb>=_0x5706ad){_0x490deb=_0x5706ad;_0x2166d7=0xc8;}else{_0x2166d7=0xce;}_0x2512db[_0xe122('0x1d')](_0x2166d7);return _0x2512db['set']('Content-Range',_0x5ba613+'-'+_0x490deb+'/'+_0x5706ad)[_0xe122('0x1f')](_0x4722f7);}return null;};}function patchUpdates(_0x4982e0){return function(_0x4a71a4){try{jsonpatch[_0xe122('0x24')](_0x4a71a4,_0x4982e0,!![]);}catch(_0x54a7e2){return BPromise[_0xe122('0x25')](_0x54a7e2);}return _0x4a71a4['save']();};}function saveUpdates(_0x19cb2d,_0x7ae1f0){return function(_0x348f77){if(_0x348f77){return _0x348f77[_0xe122('0x26')](_0x19cb2d)[_0xe122('0x27')](function(_0x505eed){return _0x505eed;});}return null;};}function handleEntityNotFound(_0x29c2a6,_0x3d7102){return function(_0x1b8407){if(!_0x1b8407){_0x29c2a6[_0xe122('0x28')](0x194);}return _0x1b8407;};}function handleError(_0x188d3c,_0x28e851){_0x28e851=_0x28e851||0x1f4;return function(_0x4ce6c3){logger[_0xe122('0x29')](_0x4ce6c3[_0xe122('0x2a')]);if(_0x4ce6c3[_0xe122('0x2b')]){delete _0x4ce6c3[_0xe122('0x2b')];}_0x188d3c[_0xe122('0x1d')](_0x28e851)[_0xe122('0x2c')](_0x4ce6c3);};}exports[_0xe122('0x2d')]=function(_0x59cf20,_0x370cb6){var _0x2958e9={},_0xfaebef={},_0x3b7be1={'count':0x0,'rows':[]};var _0x94fd0b=_[_0xe122('0x2e')](db[_0xe122('0x2f')][_0xe122('0x30')],function(_0x1bf47){return{'name':_0x1bf47[_0xe122('0x31')],'type':_0x1bf47[_0xe122('0x32')][_0xe122('0x33')]};});_0xfaebef[_0xe122('0x34')]=_[_0xe122('0x2e')](_0x94fd0b,_0xe122('0x2b'));_0xfaebef['query']=_[_0xe122('0x35')](_0x59cf20[_0xe122('0x36')]);_0xfaebef['filters']=_[_0xe122('0x37')](_0xfaebef[_0xe122('0x34')],_0xfaebef['query']);_0x2958e9[_0xe122('0x38')]=_[_0xe122('0x37')](_0xfaebef[_0xe122('0x34')],qs[_0xe122('0x39')](_0x59cf20[_0xe122('0x36')]['fields']));_0x2958e9[_0xe122('0x38')]=_0x2958e9['attributes'][_0xe122('0x3a')]?_0x2958e9[_0xe122('0x38')]:_0xfaebef[_0xe122('0x34')];if(!_0x59cf20[_0xe122('0x36')][_0xe122('0x3b')](_0xe122('0x3c'))){_0x2958e9['limit']=qs[_0xe122('0x22')](_0x59cf20[_0xe122('0x36')][_0xe122('0x22')]);_0x2958e9['offset']=qs[_0xe122('0x20')](_0x59cf20[_0xe122('0x36')][_0xe122('0x20')]);}_0x2958e9[_0xe122('0x3d')]=qs[_0xe122('0x3e')](_0x59cf20[_0xe122('0x36')][_0xe122('0x3e')]);_0x2958e9[_0xe122('0x3f')]=qs['filters'](_['pick'](_0x59cf20[_0xe122('0x36')],_0xfaebef[_0xe122('0x40')]),_0x94fd0b);if(_0x59cf20[_0xe122('0x36')][_0xe122('0x41')]){_0x2958e9[_0xe122('0x3f')]=_[_0xe122('0x42')](_0x2958e9[_0xe122('0x3f')],{'$or':_['map'](_0x94fd0b,function(_0x12b18c){if(_0x12b18c[_0xe122('0x32')]!==_0xe122('0x43')){var _0x17f349={};_0x17f349[_0x12b18c[_0xe122('0x2b')]]={'$like':'%'+_0x59cf20[_0xe122('0x36')][_0xe122('0x41')]+'%'};return _0x17f349;}})});}_0x2958e9=_[_0xe122('0x42')]({},_0x2958e9,_0x59cf20[_0xe122('0x44')]);var _0x4f74a0={'where':_0x2958e9[_0xe122('0x3f')]};return db[_0xe122('0x2f')][_0xe122('0x23')](_0x4f74a0)[_0xe122('0x27')](function(_0x4d0901){_0x3b7be1[_0xe122('0x23')]=_0x4d0901;if(_0x59cf20[_0xe122('0x36')][_0xe122('0x45')]){_0x2958e9[_0xe122('0x46')]=[{'all':!![]}];}return db[_0xe122('0x2f')][_0xe122('0x47')](_0x2958e9);})[_0xe122('0x27')](function(_0x3dd13c){_0x3b7be1[_0xe122('0x48')]=_0x3dd13c;return _0x3b7be1;})[_0xe122('0x27')](respondWithFilteredResult(_0x370cb6,_0x2958e9))[_0xe122('0x49')](handleError(_0x370cb6,null));};exports['show']=function(_0x422f9d,_0x2c51b){var _0x13ef82={'raw':![],'where':{'id':_0x422f9d[_0xe122('0x4a')]['id']}},_0x392ff2={};_0x392ff2[_0xe122('0x34')]=_[_0xe122('0x35')](db[_0xe122('0x2f')][_0xe122('0x30')]);_0x392ff2['query']=_[_0xe122('0x35')](_0x422f9d[_0xe122('0x36')]);_0x392ff2[_0xe122('0x40')]=_[_0xe122('0x37')](_0x392ff2[_0xe122('0x34')],_0x392ff2['query']);_0x13ef82[_0xe122('0x38')]=_[_0xe122('0x37')](_0x392ff2[_0xe122('0x34')],qs['fields'](_0x422f9d[_0xe122('0x36')][_0xe122('0x39')]));_0x13ef82[_0xe122('0x38')]=_0x13ef82[_0xe122('0x38')][_0xe122('0x3a')]?_0x13ef82[_0xe122('0x38')]:_0x392ff2[_0xe122('0x34')];if(_0x422f9d[_0xe122('0x36')][_0xe122('0x45')]){_0x13ef82[_0xe122('0x46')]=[{'all':!![]}];}_0x13ef82=_[_0xe122('0x42')]({},_0x13ef82,_0x422f9d['options']);return db[_0xe122('0x2f')][_0xe122('0x4b')](_0x13ef82)['then'](handleEntityNotFound(_0x2c51b,null))[_0xe122('0x27')](respondWithResult(_0x2c51b,null))[_0xe122('0x49')](handleError(_0x2c51b,null));};exports['create']=function(_0x2dccd1,_0x17ebbf){return db[_0xe122('0x2f')]['create'](_0x2dccd1[_0xe122('0x4c')],{})['then'](function(_0x3484b6){var _0x1f7fc2=_0x2dccd1[_0xe122('0x4d')]['get']({'plain':!![]});if(!_0x1f7fc2)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x1f7fc2['role']===_0xe122('0x4d')){var _0xa485a1=_0x3484b6['get']({'plain':!![]});var _0x45f2c5=_0xe122('0x4e');return db[_0xe122('0x4f')][_0xe122('0x4b')]({'where':{'name':_0x45f2c5,'userProfileId':_0x1f7fc2[_0xe122('0x50')]},'raw':!![]})[_0xe122('0x27')](function(_0x4c4f32){if(_0x4c4f32&&_0x4c4f32['autoAssociation']===0x0){return db[_0xe122('0x51')][_0xe122('0x52')]({'name':_0xa485a1[_0xe122('0x2b')],'resourceId':_0xa485a1['id'],'type':_0x4c4f32['name'],'sectionId':_0x4c4f32['id']},{})['then'](function(){return _0x3484b6;});}else{return _0x3484b6;}})[_0xe122('0x49')](function(_0x454dd){logger[_0xe122('0x29')](_0xe122('0x53'),_0x454dd);throw _0x454dd;});}return _0x3484b6;})[_0xe122('0x27')](respondWithResult(_0x17ebbf,0xc9))[_0xe122('0x49')](handleError(_0x17ebbf,null));};exports[_0xe122('0x26')]=function(_0x453c07,_0x25a7e1){if(_0x453c07[_0xe122('0x4c')]['id']){delete _0x453c07[_0xe122('0x4c')]['id'];}return db[_0xe122('0x2f')][_0xe122('0x4b')]({'where':{'id':_0x453c07[_0xe122('0x4a')]['id']}})[_0xe122('0x27')](handleEntityNotFound(_0x25a7e1,null))[_0xe122('0x27')](saveUpdates(_0x453c07[_0xe122('0x4c')],null))[_0xe122('0x27')](respondWithResult(_0x25a7e1,null))[_0xe122('0x49')](handleError(_0x25a7e1,null));};exports['destroy']=function(_0x6bd430,_0x1e55a5){var _0x98f56=_0x6bd430[_0xe122('0x4a')]['id'];var _0x2f2e8a=[];return db[_0xe122('0x54')][_0xe122('0x55')](function(_0x4016f1){var _0x275cfb=_0xe122('0x56')+_0x98f56;return db[_0xe122('0x54')]['query'](_0x275cfb,{'type':db[_0xe122('0x57')][_0xe122('0x58')]['SELECT'],'raw':!![],'transaction':_0x4016f1})['then'](function(_0x147c69){_0x2f2e8a=_[_0xe122('0x2e')](_0x147c69,function(_0x4c764a){return Number(_0x4c764a['UserId']);});})['then'](function(){var _0x171fb3=_0xe122('0x59')+_0x98f56;return db[_0xe122('0x54')]['query'](_0x171fb3,{'type':db['Sequelize'][_0xe122('0x58')][_0xe122('0x5a')],'raw':!![],'transaction':_0x4016f1});})['then'](function(_0x26792d){var _0x54dfc6=_[_0xe122('0x2e')](_0x26792d,function(_0x46e2f9){return Number(_0x46e2f9[_0xe122('0x5b')]);});return db[_0xe122('0x5c')]['destroy']({'where':{'UserId':{'$in':_0x2f2e8a},'VoiceQueueId':{'$in':_0x54dfc6}},'transaction':_0x4016f1});})[_0xe122('0x27')](function(){var _0x9a800d=_0xe122('0x5d')+_0x98f56;return db[_0xe122('0x54')][_0xe122('0x36')](_0x9a800d,{'type':db['Sequelize'][_0xe122('0x58')][_0xe122('0x5a')],'raw':!![],'transaction':_0x4016f1});})[_0xe122('0x27')](function(_0x39431c){var _0x4c7dbe=_[_0xe122('0x2e')](_0x39431c,function(_0x3bc486){return Number(_0x3bc486[_0xe122('0x5e')]);});return db['UserMailQueue'][_0xe122('0x5f')]({'where':{'UserId':{'$in':_0x2f2e8a},'MailQueueId':{'$in':_0x4c7dbe}},'transaction':_0x4016f1});})['then'](function(){var _0x11feb2=_0xe122('0x60')+_0x98f56;return db['sequelize'][_0xe122('0x36')](_0x11feb2,{'type':db[_0xe122('0x57')]['QueryTypes']['SELECT'],'raw':!![],'transaction':_0x4016f1});})[_0xe122('0x27')](function(_0x5d4753){var _0x311d21=_['map'](_0x5d4753,function(_0x2af2d2){return Number(_0x2af2d2[_0xe122('0x61')]);});return db[_0xe122('0x62')][_0xe122('0x5f')]({'where':{'UserId':{'$in':_0x2f2e8a},'SmsQueueId':{'$in':_0x311d21}},'transaction':_0x4016f1});})[_0xe122('0x27')](function(){var _0x5cae41='SELECT\x20ChatQueueId\x20FROM\x20team_has_chat_queues\x20WHERE\x20TeamId\x20=\x20'+_0x98f56;return db[_0xe122('0x54')][_0xe122('0x36')](_0x5cae41,{'type':db[_0xe122('0x57')]['QueryTypes']['SELECT'],'raw':!![],'transaction':_0x4016f1});})[_0xe122('0x27')](function(_0x28a2c8){var _0x232e2b=_['map'](_0x28a2c8,function(_0x5ddaa7){return Number(_0x5ddaa7['ChatQueueId']);});return db[_0xe122('0x63')]['destroy']({'where':{'UserId':{'$in':_0x2f2e8a},'ChatQueueId':{'$in':_0x232e2b}},'transaction':_0x4016f1});})[_0xe122('0x27')](function(){var _0x402084=_0xe122('0x64')+_0x98f56;return db['sequelize'][_0xe122('0x36')](_0x402084,{'type':db[_0xe122('0x57')][_0xe122('0x58')][_0xe122('0x5a')],'raw':!![],'transaction':_0x4016f1});})[_0xe122('0x27')](function(_0xab2949){var _0x446fb8=_['map'](_0xab2949,function(_0xf23e76){return Number(_0xf23e76['FaxQueueId']);});return db['UserFaxQueue']['destroy']({'where':{'UserId':{'$in':_0x2f2e8a},'FaxQueueId':{'$in':_0x446fb8}},'transaction':_0x4016f1});})[_0xe122('0x27')](function(){var _0x4bb2db=_0xe122('0x65')+_0x98f56;return db['sequelize'][_0xe122('0x36')](_0x4bb2db,{'type':db[_0xe122('0x57')][_0xe122('0x58')][_0xe122('0x5a')],'raw':!![],'transaction':_0x4016f1});})[_0xe122('0x27')](function(_0x4321dc){var _0xb5d9ef=_[_0xe122('0x2e')](_0x4321dc,function(_0x286d5f){return Number(_0x286d5f[_0xe122('0x66')]);});return db[_0xe122('0x67')][_0xe122('0x5f')]({'where':{'UserId':{'$in':_0x2f2e8a},'OpenchannelQueueId':{'$in':_0xb5d9ef}},'transaction':_0x4016f1});})[_0xe122('0x27')](function(){var _0x28cef9=_0xe122('0x68')+_0x98f56;return db['sequelize'][_0xe122('0x36')](_0x28cef9,{'type':db[_0xe122('0x57')][_0xe122('0x58')][_0xe122('0x5a')],'raw':!![],'transaction':_0x4016f1});})['then'](function(_0x54031e){var _0x1c31cc=_[_0xe122('0x2e')](_0x54031e,function(_0x1f8184){return Number(_0x1f8184['WhatsappQueueId']);});return db['UserWhatsappQueue'][_0xe122('0x5f')]({'where':{'UserId':{'$in':_0x2f2e8a},'WhatsappQueueId':{'$in':_0x1c31cc}},'transaction':_0x4016f1});})[_0xe122('0x27')](function(){return db[_0xe122('0x69')][_0xe122('0x4b')]({'where':{'TeamId':_0x98f56}});})['then'](function(_0x5de5c0){if(_0x5de5c0===null){return;}return db[_0xe122('0x6a')][_0xe122('0x5f')]({'where':{'UserId':{'$in':_0x2f2e8a},'VoicePrefixId':_0x5de5c0['VoicePrefixId']},'transaction':_0x4016f1});})[_0xe122('0x27')](function(){return db[_0xe122('0x2f')][_0xe122('0x5f')]({'where':{'id':_0x98f56},'cascade':!![],'transaction':_0x4016f1});})['then'](function(_0x51c8ef){if(_0x51c8ef===0x0){_0x1e55a5[_0xe122('0x28')](0x194);}else{return db[_0xe122('0x51')][_0xe122('0x5f')]({'where':{'type':_0xe122('0x4e'),'resourceId':_0x98f56},'cascade':!![],'transaction':_0x4016f1})['then'](function(){_0x1e55a5[_0xe122('0x1d')](0xcc)['end']();});}})['catch'](function(_0x1bb86d){_0x1e55a5[_0xe122('0x1d')](0x1f4)[_0xe122('0x2c')](_0x1bb86d);});});};exports[_0xe122('0x6b')]=function(_0x276755,_0xcec5cb,_0x11ce03){return db[_0xe122('0x2f')][_0xe122('0x6c')]({'where':{'id':_0x276755[_0xe122('0x4a')]['id']}})['then'](handleEntityNotFound(_0xcec5cb,null))[_0xe122('0x27')](function(_0x2ff9d7){if(!_0x276755[_0xe122('0x36')]['channel']||!utils[_0xe122('0x6d')](_0x276755[_0xe122('0x36')][_0xe122('0x6e')])){throw new db[(_0xe122('0x57'))][(_0xe122('0x6f'))](_0xe122('0x70'));}var _0x25424a={};var _0x163f30={};_0x163f30[_0xe122('0x34')]=_['keys'](db[_[_0xe122('0x71')](_0x276755[_0xe122('0x36')][_0xe122('0x6e')][_0xe122('0x72')]())+'Queue'][_0xe122('0x30')]);_0x163f30[_0xe122('0x36')]=_[_0xe122('0x35')](_0x276755['query']);_0x163f30[_0xe122('0x40')]=_[_0xe122('0x37')](_0x163f30[_0xe122('0x34')],_0x163f30[_0xe122('0x36')]);_0x25424a['attributes']=_[_0xe122('0x37')](_0x163f30[_0xe122('0x34')],qs[_0xe122('0x39')](_0x276755[_0xe122('0x36')][_0xe122('0x39')]));_0x25424a[_0xe122('0x38')]=_0x25424a[_0xe122('0x38')]['length']?_0x25424a[_0xe122('0x38')]:_0x163f30['model'];_0x25424a['limit']=qs['limit'](_0x276755[_0xe122('0x36')][_0xe122('0x22')]);_0x25424a[_0xe122('0x20')]=qs[_0xe122('0x20')](_0x276755['query']['offset']);_0x25424a['order']=qs[_0xe122('0x3e')](_0x276755[_0xe122('0x36')][_0xe122('0x3e')]);_0x25424a[_0xe122('0x3f')]=qs[_0xe122('0x40')](_[_0xe122('0x73')](_0x276755[_0xe122('0x36')],_0x163f30[_0xe122('0x40')]));_0x25424a=_[_0xe122('0x42')]({},_0x25424a,_0x276755[_0xe122('0x44')]);return _0x2ff9d7[_0xe122('0x74')+_[_0xe122('0x71')](_0x276755[_0xe122('0x36')]['channel']['toLowerCase']())+_0xe122('0x75')](_0x25424a);})[_0xe122('0x27')](respondWithResult(_0xcec5cb,null))[_0xe122('0x49')](handleError(_0xcec5cb,null));};exports[_0xe122('0x76')]=function(_0x1eb1c2,_0x4444d8,_0x7dfe57){return db['Team'][_0xe122('0x6c')]({'where':{'id':_0x1eb1c2[_0xe122('0x4a')]['id']}})[_0xe122('0x27')](function(_0x2fba25){if(_0x2fba25){if(!_0x1eb1c2[_0xe122('0x4c')]['channel']||!utils['isValidChannel'](_0x1eb1c2['body'][_0xe122('0x6e')])){throw new db['Sequelize']['ValidationError']('Unknown\x20channel');}return _0x2fba25[_0xe122('0x77')+_[_0xe122('0x71')](_0x1eb1c2[_0xe122('0x4c')][_0xe122('0x6e')][_0xe122('0x72')]())+'Queues'](_0x1eb1c2[_0xe122('0x4c')][_0xe122('0x78')]);}return null;})[_0xe122('0x27')](handleEntityNotFound(_0x4444d8,null))[_0xe122('0x27')](respondWithStatusCode(_0x4444d8,null))['catch'](handleError(_0x4444d8,null));};exports['removeQueues']=function(_0x3150ad,_0x1ba966,_0x5610c5){return db[_0xe122('0x2f')][_0xe122('0x6c')]({'where':{'id':_0x3150ad[_0xe122('0x4a')]['id']}})[_0xe122('0x27')](function(_0x13f40c){if(_0x13f40c){if(!_0x3150ad[_0xe122('0x36')][_0xe122('0x6e')]||!utils[_0xe122('0x6d')](_0x3150ad[_0xe122('0x36')]['channel'])){throw new db[(_0xe122('0x57'))][(_0xe122('0x6f'))](_0xe122('0x70'));}return _0x13f40c[_0xe122('0x79')+_[_0xe122('0x71')](_0x3150ad[_0xe122('0x36')][_0xe122('0x6e')][_0xe122('0x72')]())+_0xe122('0x75')](_0x3150ad[_0xe122('0x36')][_0xe122('0x78')]);}return null;})[_0xe122('0x27')](handleEntityNotFound(_0x1ba966,null))[_0xe122('0x27')](respondWithStatusCode(_0x1ba966,null))[_0xe122('0x49')](handleError(_0x1ba966,null));};exports[_0xe122('0x7a')]=function(_0x409d59,_0x47b309){var _0xae82a=_['isArray'](_0x409d59[_0xe122('0x4c')]['ids'])?_0x409d59['body']['ids']:[_0x409d59[_0xe122('0x4c')]['ids']];var _0x5b2e18=_0x409d59[_0xe122('0x4a')]['id'];return db[_0xe122('0x2f')][_0xe122('0x4b')]({'where':{'id':_0x5b2e18}})[_0xe122('0x27')](handleEntityNotFound(_0x47b309,null))[_0xe122('0x27')](function(_0x3c2b5b){if(_0x3c2b5b){var _0x3c8125=[_0xe122('0x7b'),_0xe122('0x7c'),'Mail',_0xe122('0x7d'),_0xe122('0x7e'),'Openchannel',_0xe122('0x7f')];return db[_0xe122('0x54')][_0xe122('0x55')](function(_0xf4cac5){var _0x3fe753=_[_0xe122('0x2e')](_0x3c8125,function(_0x4074e0){var _0x402882={'attributes':['id',_0xe122('0x2b')]};if(_0x4074e0===_0xe122('0x7b')){_0x402882['through']={'attributes':[_0xe122('0x80')]};}return _0x3c2b5b[_0xe122('0x74')+_0x4074e0+_0xe122('0x75')](_0x402882)['then'](function(_0xa2951b){var _0x1ace8d=_[_0xe122('0x2e')](_0xa2951b,function(_0xe1925){var _0x1dff24=_['map'](_0xae82a,function(_0x4082ad){var _0x4b6d4f={'where':{'UserId':_0x4082ad,[_0x4074e0+_0xe122('0x81')]:_0xe1925['id']},'transaction':_0xf4cac5};if(_0x4074e0===_0xe122('0x7b')){_0x4b6d4f['defaults']={'penalty':_0xe1925['TeamVoiceQueue'][_0xe122('0x80')]};}return db[_0xe122('0x82')+_0x4074e0+_0xe122('0x83')][_0xe122('0x84')](_0x4b6d4f)[_0xe122('0x27')](function(){socket[_0xe122('0x85')]('user'+_0x4074e0+_0xe122('0x86'),{'UserId':_0x4082ad,[_0x4074e0+_0xe122('0x81')]:_0xe1925['id']});if(_0x4074e0!=='Voice'){return;}return db[_0xe122('0x82')][_0xe122('0x47')]({'where':{'id':_0xae82a,'online':0x1},'attributes':['id',_0xe122('0x2b'),_0xe122('0x87'),'voicePause','interface'],'raw':!![]})['then'](function(_0x225ef4){var _0x23a16b=_['map'](_0x225ef4,function(_0x46f01a){return db[_0xe122('0x88')]['upsert']({'membername':_0x46f01a[_0xe122('0x2b')],'UserId':_0x46f01a['id'],'queue_name':_0xe1925['name'],'VoiceQueueId':_0xe1925['id'],'interface':_[_0xe122('0x89')](_0x46f01a[_0xe122('0x8a')])?util[_0xe122('0x8b')](_0xe122('0x8c'),_0x46f01a[_0xe122('0x2b')]):_0x46f01a[_0xe122('0x8a')],'paused':_0x46f01a[_0xe122('0x8d')]||![],'penalty':_0xe1925[_0xe122('0x8e')]['penalty']},{'transaction':_0xf4cac5});});return Promise['all'](_0x23a16b);});});});return Promise[_0xe122('0x8f')](_0x1dff24);});return Promise[_0xe122('0x8f')](_0x1ace8d);})[_0xe122('0x27')](function(){return db['TeamVoicePrefix'][_0xe122('0x6c')]({'where':{'teamId':_0x5b2e18}})[_0xe122('0x27')](function(_0x1dffa6){if(_0x1dffa6){var _0x47d97d=_[_0xe122('0x2e')](_0xae82a,function(_0x13bd50){db[_0xe122('0x6a')][_0xe122('0x90')]({'UserId':_0x13bd50,'VoicePrefixId':_0x1dffa6[_0xe122('0x91')]});});return Promise[_0xe122('0x8f')](_0x47d97d);}});});});return Promise['all'](_0x3fe753)[_0xe122('0x27')](function(){return _0x3c2b5b[_0xe122('0x7a')](_0xae82a,{'transaction':_0xf4cac5})[_0xe122('0x92')](function(_0x1e76c5){return _0x1e76c5;});});});}})['then'](respondWithResult(_0x47b309,null))['catch'](handleError(_0x47b309,null));};exports['removeAgents']=function(_0x497d94,_0x7404ab){var _0x2d5596=_[_0xe122('0x93')](_0x497d94[_0xe122('0x36')]['ids'])?_0x497d94['query'][_0xe122('0x78')]:[_0x497d94[_0xe122('0x36')]['ids']];var _0x452037=_0x497d94[_0xe122('0x4a')]['id'];return db['Team'][_0xe122('0x4b')]({'where':{'id':_0x452037}})[_0xe122('0x27')](handleEntityNotFound(_0x7404ab,null))[_0xe122('0x27')](function(_0x13fc8c){if(_0x13fc8c){var _0x4a0998=[_0xe122('0x7b'),_0xe122('0x7c'),_0xe122('0x94'),_0xe122('0x7d'),'Fax',_0xe122('0x95'),_0xe122('0x7f')];return db[_0xe122('0x54')][_0xe122('0x55')](function(_0x4fcc1a){var _0x2bc5be=_[_0xe122('0x2e')](_0x4a0998,function(_0x30f11c){var _0x489320={'attributes':['id',_0xe122('0x2b')]};return _0x13fc8c[_0xe122('0x74')+_0x30f11c+_0xe122('0x75')](_0x489320)[_0xe122('0x27')](function(_0x197205){var _0x1cfe07=_[_0xe122('0x2e')](_0x197205,function(_0x2b9da6){return _0x2b9da6[_0xe122('0x96')](_0x2d5596,{'transaction':_0x4fcc1a})[_0xe122('0x27')](function(){var _0x13d333=_[_0xe122('0x2e')](_0x2d5596,function(_0x5c8b74){socket[_0xe122('0x85')](_0xe122('0x4d')+_0x30f11c+'Queue:remove',{'UserId':Number(_0x5c8b74),[_0x30f11c+_0xe122('0x81')]:_0x2b9da6['id']});if(_0x30f11c!==_0xe122('0x7b')){return;}return db[_0xe122('0x88')][_0xe122('0x5f')]({'where':{'VoiceQueueId':_0x2b9da6['id'],'UserId':_0x5c8b74},'transaction':_0x4fcc1a});});return Promise[_0xe122('0x8f')](_0x13d333);});});return Promise['all'](_0x1cfe07);});});return Promise[_0xe122('0x8f')](_0x2bc5be)['then'](function(){return _0x13fc8c[_0xe122('0x96')](_0x2d5596,{'transaction':_0x4fcc1a});})[_0xe122('0x27')](function(){return db[_0xe122('0x69')]['findOne']({'where':{'teamId':_0x452037}})[_0xe122('0x27')](function(_0xeb0bc5){if(_0xeb0bc5){var _0x58b734=_[_0xe122('0x2e')](_0x2d5596,function(_0x3074a9){db[_0xe122('0x6a')][_0xe122('0x5f')]({'where':{'UserId':_0x3074a9,'VoicePrefixId':_0xeb0bc5['VoicePrefixId']}});});return Promise[_0xe122('0x8f')](_0x58b734);}});});});}})['then'](respondWithStatusCode(_0x7404ab,null))['catch'](handleError(_0x7404ab,null));};exports[_0xe122('0x97')]=function(_0x2505a0,_0x1e6c07,_0x44bb31){var _0x1142f3={};var _0x29cc5e={};var _0xc7d695;var _0x23a787;return db['Team']['findOne']({'where':{'id':_0x2505a0[_0xe122('0x4a')]['id']}})['then'](handleEntityNotFound(_0x1e6c07,null))[_0xe122('0x27')](function(_0x410a81){if(_0x410a81){_0xc7d695=_0x410a81;_0x29cc5e[_0xe122('0x34')]=_[_0xe122('0x35')](db[_0xe122('0x82')]['rawAttributes']);_0x29cc5e['query']=_[_0xe122('0x35')](_0x2505a0[_0xe122('0x36')]);_0x29cc5e[_0xe122('0x40')]=_[_0xe122('0x37')](_0x29cc5e['model'],_0x29cc5e[_0xe122('0x36')]);_0x1142f3[_0xe122('0x38')]=_[_0xe122('0x37')](_0x29cc5e[_0xe122('0x34')],qs['fields'](_0x2505a0[_0xe122('0x36')][_0xe122('0x39')]));_0x1142f3[_0xe122('0x38')]=_0x1142f3[_0xe122('0x38')][_0xe122('0x3a')]?_0x1142f3['attributes']:_0x29cc5e[_0xe122('0x34')];_0x1142f3[_0xe122('0x3d')]=qs[_0xe122('0x3e')](_0x2505a0['query'][_0xe122('0x3e')]);_0x1142f3['where']=qs[_0xe122('0x40')](_[_0xe122('0x73')](_0x2505a0[_0xe122('0x36')],_0x29cc5e[_0xe122('0x40')]));if(_0x2505a0[_0xe122('0x36')][_0xe122('0x41')]){_0x1142f3[_0xe122('0x3f')]=_[_0xe122('0x42')](_0x1142f3[_0xe122('0x3f')],{'$or':_[_0xe122('0x2e')](_0x1142f3[_0xe122('0x38')],function(_0x5b0cb7){var _0x165c54={};_0x165c54[_0x5b0cb7]={'$like':'%'+_0x2505a0['query']['filter']+'%'};return _0x165c54;})});}_0x1142f3=_[_0xe122('0x42')]({},_0x1142f3,_0x2505a0[_0xe122('0x44')]);return _0xc7d695[_0xe122('0x97')](_0x1142f3);}})[_0xe122('0x27')](function(_0x32191d){if(_0x32191d){_0x23a787=_0x32191d[_0xe122('0x3a')];if(!_0x2505a0[_0xe122('0x36')]['hasOwnProperty'](_0xe122('0x3c'))){_0x1142f3[_0xe122('0x22')]=qs[_0xe122('0x22')](_0x2505a0[_0xe122('0x36')][_0xe122('0x22')]);_0x1142f3['offset']=qs[_0xe122('0x20')](_0x2505a0[_0xe122('0x36')][_0xe122('0x20')]);}return _0xc7d695[_0xe122('0x97')](_0x1142f3);}})['then'](function(_0x5baf7b){if(_0x5baf7b){return _0x5baf7b?{'count':_0x23a787,'rows':_0x5baf7b}:null;}})[_0xe122('0x27')](respondWithResult(_0x1e6c07,null))[_0xe122('0x49')](handleError(_0x1e6c07,null));};