Built motion from commit ffdca78c.|2.6.24
[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 _0xdcd9=['limit','set','Content-Range','json','apply','reject','save','then','error','name','send','index','map','Team','rawAttributes','fieldName','type','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','VIRTUAL','filter','options','includeAll','include','rows','catch','show','params','find','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','Teams','UserProfileSection','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','sequelize','SELECT\x20UserId\x20FROM\x20user_has_teams\x20WHERE\x20TeamId\x20=\x20','Sequelize','QueryTypes','UserId','SELECT\x20VoiceQueueId\x20FROM\x20team_has_voice_queues\x20WHERE\x20TeamId\x20=\x20','VoiceQueueId','UserVoiceQueue','SELECT\x20MailQueueId\x20FROM\x20team_has_mail_queues\x20WHERE\x20TeamId\x20=\x20','MailQueueId','UserMailQueue','destroy','UserSmsQueue','SELECT\x20ChatQueueId\x20FROM\x20team_has_chat_queues\x20WHERE\x20TeamId\x20=\x20','SELECT','ChatQueueId','UserChatQueue','SELECT\x20FaxQueueId\x20FROM\x20team_has_fax_queues\x20WHERE\x20TeamId\x20=\x20','UserOpenchannelQueue','SELECT\x20WhatsappQueueId\x20FROM\x20team_has_whatsapp_queues\x20WHERE\x20TeamId\x20=\x20','WhatsappQueueId','UserWhatsappQueue','TeamVoicePrefix','UserVoicePrefix','VoicePrefixId','getQueues','findOne','channel','Unknown\x20channel','toLowerCase','Queue','capitalize','addQueues','add','removeQueues','ValidationError','Queues','ids','addAgents','isArray','Voice','Chat','Mail','Sms','Whatsapp','transaction','through','QueueId','defaults','penalty','User','findOrCreate','Queue:save','findAll','UserVoiceQueueRt','upsert','isNil','interface','format','SIP/%s','TeamVoiceQueue','all','spread','removeAgents','Openchannel','emit','Queue:remove','getAgents','eml-format','rimraf','request-promise','moment','bluebird','mustache','util','sox','to-csv','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','redis','localhost','./team.socket','register','sendStatus','status','end','offset','undefined','count'];(function(_0x9fd887,_0x47f76c){var _0x1a54ab=function(_0xb65c08){while(--_0xb65c08){_0x9fd887['push'](_0x9fd887['shift']());}};_0x1a54ab(++_0x47f76c);}(_0xdcd9,0x1b0));var _0x9dcd=function(_0x481ae7,_0x473628){_0x481ae7=_0x481ae7-0x0;var _0xe486d1=_0xdcd9[_0x481ae7];return _0xe486d1;};'use strict';var emlformat=require(_0x9dcd('0x0'));var rimraf=require(_0x9dcd('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x9dcd('0x2'));var moment=require(_0x9dcd('0x3'));var BPromise=require(_0x9dcd('0x4'));var Mustache=require(_0x9dcd('0x5'));var util=require(_0x9dcd('0x6'));var path=require('path');var sox=require(_0x9dcd('0x7'));var csv=require(_0x9dcd('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x9dcd('0x9'));var _=require(_0x9dcd('0xa'));var squel=require(_0x9dcd('0xb'));var crypto=require(_0x9dcd('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x9dcd('0xd'));var toCsv=require(_0x9dcd('0x8'));var querystring=require(_0x9dcd('0xe'));var Papa=require(_0x9dcd('0xf'));var Redis=require('ioredis');var authService=require(_0x9dcd('0x10'));var qs=require(_0x9dcd('0x11'));var as=require(_0x9dcd('0x12'));var hardwareService=require(_0x9dcd('0x13'));var logger=require('../../config/logger')('api');var utils=require(_0x9dcd('0x14'));var config=require(_0x9dcd('0x15'));var licenseUtil=require(_0x9dcd('0x16'));var db=require('../../mysqldb')['db'];config[_0x9dcd('0x17')]=_['defaults'](config['redis'],{'host':_0x9dcd('0x18'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x9dcd('0x17')]));require(_0x9dcd('0x19'))[_0x9dcd('0x1a')](socket);function respondWithStatusCode(_0x34d0c1,_0x2b5f7d){_0x2b5f7d=_0x2b5f7d||0xcc;return function(_0x183524){if(_0x183524){return _0x34d0c1[_0x9dcd('0x1b')](_0x2b5f7d);}return _0x34d0c1[_0x9dcd('0x1c')](_0x2b5f7d)[_0x9dcd('0x1d')]();};}function respondWithResult(_0x344698,_0x34e1d7){_0x34e1d7=_0x34e1d7||0xc8;return function(_0x24411b){if(_0x24411b){return _0x344698[_0x9dcd('0x1c')](_0x34e1d7)['json'](_0x24411b);}};}function respondWithFilteredResult(_0x1bc0b9,_0x4ec3b4){return function(_0x4da24d){if(_0x4da24d){var _0x2bf287=typeof _0x4ec3b4[_0x9dcd('0x1e')]===_0x9dcd('0x1f')&&typeof _0x4ec3b4['limit']===_0x9dcd('0x1f');var _0x52ae36=_0x4da24d[_0x9dcd('0x20')];var _0x5496f6=_0x2bf287?0x0:_0x4ec3b4[_0x9dcd('0x1e')];var _0x23b961=_0x2bf287?_0x4da24d[_0x9dcd('0x20')]:_0x4ec3b4[_0x9dcd('0x1e')]+_0x4ec3b4[_0x9dcd('0x21')];var _0x4b1ee2;if(_0x23b961>=_0x52ae36){_0x23b961=_0x52ae36;_0x4b1ee2=0xc8;}else{_0x4b1ee2=0xce;}_0x1bc0b9[_0x9dcd('0x1c')](_0x4b1ee2);return _0x1bc0b9[_0x9dcd('0x22')](_0x9dcd('0x23'),_0x5496f6+'-'+_0x23b961+'/'+_0x52ae36)[_0x9dcd('0x24')](_0x4da24d);}return null;};}function patchUpdates(_0x3082db){return function(_0x1517b1){try{jsonpatch[_0x9dcd('0x25')](_0x1517b1,_0x3082db,!![]);}catch(_0x434593){return BPromise[_0x9dcd('0x26')](_0x434593);}return _0x1517b1[_0x9dcd('0x27')]();};}function saveUpdates(_0x27bd81,_0x4836ca){return function(_0x4f7f31){if(_0x4f7f31){return _0x4f7f31['update'](_0x27bd81)[_0x9dcd('0x28')](function(_0x5e4038){return _0x5e4038;});}return null;};}function handleEntityNotFound(_0x4d80d6,_0x43ff47){return function(_0x15a326){if(!_0x15a326){_0x4d80d6[_0x9dcd('0x1b')](0x194);}return _0x15a326;};}function handleError(_0x4fc785,_0x288f07){_0x288f07=_0x288f07||0x1f4;return function(_0x2f233c){logger[_0x9dcd('0x29')](_0x2f233c['stack']);if(_0x2f233c[_0x9dcd('0x2a')]){delete _0x2f233c[_0x9dcd('0x2a')];}_0x4fc785['status'](_0x288f07)[_0x9dcd('0x2b')](_0x2f233c);};}exports[_0x9dcd('0x2c')]=function(_0x35aa56,_0x39db76){var _0x5af6dc={},_0x470f63={},_0x24bcb7={'count':0x0,'rows':[]};var _0x610020=_[_0x9dcd('0x2d')](db[_0x9dcd('0x2e')][_0x9dcd('0x2f')],function(_0x181a34){return{'name':_0x181a34[_0x9dcd('0x30')],'type':_0x181a34[_0x9dcd('0x31')]['key']};});_0x470f63[_0x9dcd('0x32')]=_[_0x9dcd('0x2d')](_0x610020,_0x9dcd('0x2a'));_0x470f63[_0x9dcd('0x33')]=_[_0x9dcd('0x34')](_0x35aa56[_0x9dcd('0x33')]);_0x470f63[_0x9dcd('0x35')]=_[_0x9dcd('0x36')](_0x470f63['model'],_0x470f63[_0x9dcd('0x33')]);_0x5af6dc['attributes']=_[_0x9dcd('0x36')](_0x470f63[_0x9dcd('0x32')],qs['fields'](_0x35aa56[_0x9dcd('0x33')][_0x9dcd('0x37')]));_0x5af6dc[_0x9dcd('0x38')]=_0x5af6dc['attributes'][_0x9dcd('0x39')]?_0x5af6dc[_0x9dcd('0x38')]:_0x470f63[_0x9dcd('0x32')];if(!_0x35aa56[_0x9dcd('0x33')][_0x9dcd('0x3a')](_0x9dcd('0x3b'))){_0x5af6dc[_0x9dcd('0x21')]=qs[_0x9dcd('0x21')](_0x35aa56[_0x9dcd('0x33')]['limit']);_0x5af6dc[_0x9dcd('0x1e')]=qs[_0x9dcd('0x1e')](_0x35aa56[_0x9dcd('0x33')][_0x9dcd('0x1e')]);}_0x5af6dc[_0x9dcd('0x3c')]=qs[_0x9dcd('0x3d')](_0x35aa56[_0x9dcd('0x33')][_0x9dcd('0x3d')]);_0x5af6dc[_0x9dcd('0x3e')]=qs[_0x9dcd('0x35')](_[_0x9dcd('0x3f')](_0x35aa56[_0x9dcd('0x33')],_0x470f63[_0x9dcd('0x35')]),_0x610020);if(_0x35aa56[_0x9dcd('0x33')]['filter']){_0x5af6dc[_0x9dcd('0x3e')]=_[_0x9dcd('0x40')](_0x5af6dc[_0x9dcd('0x3e')],{'$or':_[_0x9dcd('0x2d')](_0x610020,function(_0x4f8f15){if(_0x4f8f15[_0x9dcd('0x31')]!==_0x9dcd('0x41')){var _0x197d35={};_0x197d35[_0x4f8f15[_0x9dcd('0x2a')]]={'$like':'%'+_0x35aa56[_0x9dcd('0x33')][_0x9dcd('0x42')]+'%'};return _0x197d35;}})});}_0x5af6dc=_[_0x9dcd('0x40')]({},_0x5af6dc,_0x35aa56[_0x9dcd('0x43')]);var _0xe5faa8={'where':_0x5af6dc['where']};return db[_0x9dcd('0x2e')][_0x9dcd('0x20')](_0xe5faa8)[_0x9dcd('0x28')](function(_0x106379){_0x24bcb7[_0x9dcd('0x20')]=_0x106379;if(_0x35aa56[_0x9dcd('0x33')][_0x9dcd('0x44')]){_0x5af6dc[_0x9dcd('0x45')]=[{'all':!![]}];}return db[_0x9dcd('0x2e')]['findAll'](_0x5af6dc);})[_0x9dcd('0x28')](function(_0x1d2dc4){_0x24bcb7[_0x9dcd('0x46')]=_0x1d2dc4;return _0x24bcb7;})[_0x9dcd('0x28')](respondWithFilteredResult(_0x39db76,_0x5af6dc))[_0x9dcd('0x47')](handleError(_0x39db76,null));};exports[_0x9dcd('0x48')]=function(_0x446385,_0xa79318){var _0x5bbea4={'raw':![],'where':{'id':_0x446385[_0x9dcd('0x49')]['id']}},_0x265f1a={};_0x265f1a[_0x9dcd('0x32')]=_[_0x9dcd('0x34')](db['Team'][_0x9dcd('0x2f')]);_0x265f1a[_0x9dcd('0x33')]=_['keys'](_0x446385['query']);_0x265f1a[_0x9dcd('0x35')]=_[_0x9dcd('0x36')](_0x265f1a[_0x9dcd('0x32')],_0x265f1a[_0x9dcd('0x33')]);_0x5bbea4['attributes']=_[_0x9dcd('0x36')](_0x265f1a[_0x9dcd('0x32')],qs[_0x9dcd('0x37')](_0x446385[_0x9dcd('0x33')][_0x9dcd('0x37')]));_0x5bbea4[_0x9dcd('0x38')]=_0x5bbea4['attributes'][_0x9dcd('0x39')]?_0x5bbea4['attributes']:_0x265f1a[_0x9dcd('0x32')];if(_0x446385[_0x9dcd('0x33')][_0x9dcd('0x44')]){_0x5bbea4['include']=[{'all':!![]}];}_0x5bbea4=_[_0x9dcd('0x40')]({},_0x5bbea4,_0x446385[_0x9dcd('0x43')]);return db[_0x9dcd('0x2e')][_0x9dcd('0x4a')](_0x5bbea4)['then'](handleEntityNotFound(_0xa79318,null))[_0x9dcd('0x28')](respondWithResult(_0xa79318,null))['catch'](handleError(_0xa79318,null));};exports[_0x9dcd('0x4b')]=function(_0x5509b8,_0x4fa53b){return db['Team']['create'](_0x5509b8[_0x9dcd('0x4c')],{})[_0x9dcd('0x28')](function(_0x3e7953){var _0x353755=_0x5509b8[_0x9dcd('0x4d')][_0x9dcd('0x4e')]({'plain':!![]});if(!_0x353755)throw new Error(_0x9dcd('0x4f'));if(_0x353755[_0x9dcd('0x50')]===_0x9dcd('0x4d')){var _0x4cd6df=_0x3e7953[_0x9dcd('0x4e')]({'plain':!![]});var _0x425686=_0x9dcd('0x51');return db[_0x9dcd('0x52')][_0x9dcd('0x4a')]({'where':{'name':_0x425686,'userProfileId':_0x353755['userProfileId']},'raw':!![]})[_0x9dcd('0x28')](function(_0x58e34e){if(_0x58e34e&&_0x58e34e[_0x9dcd('0x53')]===0x0){return db[_0x9dcd('0x54')][_0x9dcd('0x4b')]({'name':_0x4cd6df['name'],'resourceId':_0x4cd6df['id'],'type':_0x58e34e[_0x9dcd('0x2a')],'sectionId':_0x58e34e['id']},{})['then'](function(){return _0x3e7953;});}else{return _0x3e7953;}})[_0x9dcd('0x47')](function(_0x2ddd4f){logger[_0x9dcd('0x29')](_0x9dcd('0x55'),_0x2ddd4f);throw _0x2ddd4f;});}return _0x3e7953;})['then'](respondWithResult(_0x4fa53b,0xc9))[_0x9dcd('0x47')](handleError(_0x4fa53b,null));};exports[_0x9dcd('0x56')]=function(_0x26751e,_0x1fdcbd){if(_0x26751e[_0x9dcd('0x4c')]['id']){delete _0x26751e[_0x9dcd('0x4c')]['id'];}return db[_0x9dcd('0x2e')][_0x9dcd('0x4a')]({'where':{'id':_0x26751e[_0x9dcd('0x49')]['id']}})['then'](handleEntityNotFound(_0x1fdcbd,null))['then'](saveUpdates(_0x26751e[_0x9dcd('0x4c')],null))['then'](respondWithResult(_0x1fdcbd,null))[_0x9dcd('0x47')](handleError(_0x1fdcbd,null));};exports['destroy']=function(_0x256811,_0x6eff33){var _0x39b8cb=_0x256811[_0x9dcd('0x49')]['id'];var _0x505550=[];return db[_0x9dcd('0x57')]['transaction'](function(_0x296150){var _0x193524=_0x9dcd('0x58')+_0x39b8cb;return db['sequelize'][_0x9dcd('0x33')](_0x193524,{'type':db[_0x9dcd('0x59')][_0x9dcd('0x5a')]['SELECT'],'raw':!![],'transaction':_0x296150})[_0x9dcd('0x28')](function(_0x4a4996){_0x505550=_[_0x9dcd('0x2d')](_0x4a4996,function(_0x33d511){return Number(_0x33d511[_0x9dcd('0x5b')]);});})[_0x9dcd('0x28')](function(){var _0x2d7001=_0x9dcd('0x5c')+_0x39b8cb;return db[_0x9dcd('0x57')][_0x9dcd('0x33')](_0x2d7001,{'type':db[_0x9dcd('0x59')][_0x9dcd('0x5a')]['SELECT'],'raw':!![],'transaction':_0x296150});})['then'](function(_0x17e2ac){var _0x3e5b24=_[_0x9dcd('0x2d')](_0x17e2ac,function(_0x5be4f6){return Number(_0x5be4f6[_0x9dcd('0x5d')]);});return db[_0x9dcd('0x5e')]['destroy']({'where':{'UserId':{'$in':_0x505550},'VoiceQueueId':{'$in':_0x3e5b24}},'transaction':_0x296150});})[_0x9dcd('0x28')](function(){var _0x442aa7=_0x9dcd('0x5f')+_0x39b8cb;return db[_0x9dcd('0x57')][_0x9dcd('0x33')](_0x442aa7,{'type':db['Sequelize'][_0x9dcd('0x5a')]['SELECT'],'raw':!![],'transaction':_0x296150});})[_0x9dcd('0x28')](function(_0x2b98e2){var _0x593d38=_[_0x9dcd('0x2d')](_0x2b98e2,function(_0x4c8225){return Number(_0x4c8225[_0x9dcd('0x60')]);});return db[_0x9dcd('0x61')][_0x9dcd('0x62')]({'where':{'UserId':{'$in':_0x505550},'MailQueueId':{'$in':_0x593d38}},'transaction':_0x296150});})[_0x9dcd('0x28')](function(){var _0x1a2cc5='SELECT\x20SmsQueueId\x20FROM\x20team_has_sms_queues\x20WHERE\x20TeamId\x20=\x20'+_0x39b8cb;return db['sequelize']['query'](_0x1a2cc5,{'type':db['Sequelize'][_0x9dcd('0x5a')]['SELECT'],'raw':!![],'transaction':_0x296150});})['then'](function(_0xebb8a0){var _0x570224=_[_0x9dcd('0x2d')](_0xebb8a0,function(_0x4c4099){return Number(_0x4c4099['SmsQueueId']);});return db[_0x9dcd('0x63')][_0x9dcd('0x62')]({'where':{'UserId':{'$in':_0x505550},'SmsQueueId':{'$in':_0x570224}},'transaction':_0x296150});})['then'](function(){var _0x142fcd=_0x9dcd('0x64')+_0x39b8cb;return db['sequelize'][_0x9dcd('0x33')](_0x142fcd,{'type':db['Sequelize'][_0x9dcd('0x5a')][_0x9dcd('0x65')],'raw':!![],'transaction':_0x296150});})['then'](function(_0x442d95){var _0x63f05a=_['map'](_0x442d95,function(_0x15f814){return Number(_0x15f814[_0x9dcd('0x66')]);});return db[_0x9dcd('0x67')][_0x9dcd('0x62')]({'where':{'UserId':{'$in':_0x505550},'ChatQueueId':{'$in':_0x63f05a}},'transaction':_0x296150});})[_0x9dcd('0x28')](function(){var _0x28db7c=_0x9dcd('0x68')+_0x39b8cb;return db[_0x9dcd('0x57')][_0x9dcd('0x33')](_0x28db7c,{'type':db['Sequelize']['QueryTypes'][_0x9dcd('0x65')],'raw':!![],'transaction':_0x296150});})['then'](function(_0x482cb2){var _0x226a73=_[_0x9dcd('0x2d')](_0x482cb2,function(_0x36f014){return Number(_0x36f014['FaxQueueId']);});return db['UserFaxQueue'][_0x9dcd('0x62')]({'where':{'UserId':{'$in':_0x505550},'FaxQueueId':{'$in':_0x226a73}},'transaction':_0x296150});})[_0x9dcd('0x28')](function(){var _0x13f672='SELECT\x20OpenchannelQueueId\x20FROM\x20team_has_openchannel_queues\x20WHERE\x20TeamId\x20=\x20'+_0x39b8cb;return db[_0x9dcd('0x57')][_0x9dcd('0x33')](_0x13f672,{'type':db[_0x9dcd('0x59')][_0x9dcd('0x5a')][_0x9dcd('0x65')],'raw':!![],'transaction':_0x296150});})[_0x9dcd('0x28')](function(_0xf97a05){var _0xa40306=_[_0x9dcd('0x2d')](_0xf97a05,function(_0x2af30d){return Number(_0x2af30d['OpenchannelQueueId']);});return db[_0x9dcd('0x69')][_0x9dcd('0x62')]({'where':{'UserId':{'$in':_0x505550},'OpenchannelQueueId':{'$in':_0xa40306}},'transaction':_0x296150});})[_0x9dcd('0x28')](function(){var _0x484443=_0x9dcd('0x6a')+_0x39b8cb;return db[_0x9dcd('0x57')][_0x9dcd('0x33')](_0x484443,{'type':db[_0x9dcd('0x59')]['QueryTypes'][_0x9dcd('0x65')],'raw':!![],'transaction':_0x296150});})[_0x9dcd('0x28')](function(_0x31344c){var _0x3853c6=_[_0x9dcd('0x2d')](_0x31344c,function(_0x6498a){return Number(_0x6498a[_0x9dcd('0x6b')]);});return db[_0x9dcd('0x6c')][_0x9dcd('0x62')]({'where':{'UserId':{'$in':_0x505550},'WhatsappQueueId':{'$in':_0x3853c6}},'transaction':_0x296150});})[_0x9dcd('0x28')](function(){return db[_0x9dcd('0x6d')]['find']({'where':{'TeamId':_0x39b8cb}});})[_0x9dcd('0x28')](function(_0x188273){if(_0x188273===null){return;}return db[_0x9dcd('0x6e')][_0x9dcd('0x62')]({'where':{'UserId':{'$in':_0x505550},'VoicePrefixId':_0x188273[_0x9dcd('0x6f')]},'transaction':_0x296150});})[_0x9dcd('0x28')](function(){return db[_0x9dcd('0x2e')][_0x9dcd('0x62')]({'where':{'id':_0x39b8cb},'cascade':!![],'transaction':_0x296150});})[_0x9dcd('0x28')](function(_0x7c5d71){if(_0x7c5d71===0x0){_0x6eff33[_0x9dcd('0x1b')](0x194);}else{return db[_0x9dcd('0x54')]['destroy']({'where':{'type':'Teams','resourceId':_0x39b8cb},'cascade':!![],'transaction':_0x296150})[_0x9dcd('0x28')](function(){_0x6eff33[_0x9dcd('0x1c')](0xcc)[_0x9dcd('0x1d')]();});}})[_0x9dcd('0x47')](function(_0x5dbd63){_0x6eff33['status'](0x1f4)['send'](_0x5dbd63);});});};exports[_0x9dcd('0x70')]=function(_0x175c33,_0x2b30a6,_0x1e2c0d){return db[_0x9dcd('0x2e')][_0x9dcd('0x71')]({'where':{'id':_0x175c33['params']['id']}})[_0x9dcd('0x28')](handleEntityNotFound(_0x2b30a6,null))[_0x9dcd('0x28')](function(_0x2336ce){if(!_0x175c33[_0x9dcd('0x33')]['channel']||!utils['isValidChannel'](_0x175c33[_0x9dcd('0x33')][_0x9dcd('0x72')])){throw new db['Sequelize']['ValidationError'](_0x9dcd('0x73'));}var _0x1aea4a={};var _0x475691={};_0x475691['model']=_['keys'](db[_['capitalize'](_0x175c33[_0x9dcd('0x33')]['channel'][_0x9dcd('0x74')]())+_0x9dcd('0x75')][_0x9dcd('0x2f')]);_0x475691[_0x9dcd('0x33')]=_[_0x9dcd('0x34')](_0x175c33[_0x9dcd('0x33')]);_0x475691['filters']=_[_0x9dcd('0x36')](_0x475691['model'],_0x475691[_0x9dcd('0x33')]);_0x1aea4a[_0x9dcd('0x38')]=_[_0x9dcd('0x36')](_0x475691[_0x9dcd('0x32')],qs[_0x9dcd('0x37')](_0x175c33[_0x9dcd('0x33')][_0x9dcd('0x37')]));_0x1aea4a[_0x9dcd('0x38')]=_0x1aea4a[_0x9dcd('0x38')][_0x9dcd('0x39')]?_0x1aea4a[_0x9dcd('0x38')]:_0x475691['model'];_0x1aea4a[_0x9dcd('0x21')]=qs[_0x9dcd('0x21')](_0x175c33[_0x9dcd('0x33')][_0x9dcd('0x21')]);_0x1aea4a[_0x9dcd('0x1e')]=qs[_0x9dcd('0x1e')](_0x175c33['query']['offset']);_0x1aea4a['order']=qs['sort'](_0x175c33[_0x9dcd('0x33')][_0x9dcd('0x3d')]);_0x1aea4a[_0x9dcd('0x3e')]=qs[_0x9dcd('0x35')](_[_0x9dcd('0x3f')](_0x175c33[_0x9dcd('0x33')],_0x475691[_0x9dcd('0x35')]));_0x1aea4a=_[_0x9dcd('0x40')]({},_0x1aea4a,_0x175c33[_0x9dcd('0x43')]);return _0x2336ce['get'+_[_0x9dcd('0x76')](_0x175c33[_0x9dcd('0x33')]['channel'][_0x9dcd('0x74')]())+'Queues'](_0x1aea4a);})[_0x9dcd('0x28')](respondWithResult(_0x2b30a6,null))['catch'](handleError(_0x2b30a6,null));};exports[_0x9dcd('0x77')]=function(_0x17a44c,_0x5cddbc,_0xd6395f){return db['Team'][_0x9dcd('0x71')]({'where':{'id':_0x17a44c[_0x9dcd('0x49')]['id']}})[_0x9dcd('0x28')](function(_0x3c100a){if(_0x3c100a){if(!_0x17a44c['body'][_0x9dcd('0x72')]||!utils['isValidChannel'](_0x17a44c['body'][_0x9dcd('0x72')])){throw new db[(_0x9dcd('0x59'))]['ValidationError'](_0x9dcd('0x73'));}return _0x3c100a[_0x9dcd('0x78')+_[_0x9dcd('0x76')](_0x17a44c['body'][_0x9dcd('0x72')][_0x9dcd('0x74')]())+'Queues'](_0x17a44c[_0x9dcd('0x4c')]['ids']);}return null;})['then'](handleEntityNotFound(_0x5cddbc,null))[_0x9dcd('0x28')](respondWithStatusCode(_0x5cddbc,null))[_0x9dcd('0x47')](handleError(_0x5cddbc,null));};exports[_0x9dcd('0x79')]=function(_0x39e70a,_0x57f447,_0x40db4d){return db[_0x9dcd('0x2e')][_0x9dcd('0x71')]({'where':{'id':_0x39e70a[_0x9dcd('0x49')]['id']}})[_0x9dcd('0x28')](function(_0x26acf2){if(_0x26acf2){if(!_0x39e70a[_0x9dcd('0x33')][_0x9dcd('0x72')]||!utils['isValidChannel'](_0x39e70a[_0x9dcd('0x33')]['channel'])){throw new db[(_0x9dcd('0x59'))][(_0x9dcd('0x7a'))](_0x9dcd('0x73'));}return _0x26acf2['remove'+_[_0x9dcd('0x76')](_0x39e70a[_0x9dcd('0x33')]['channel'][_0x9dcd('0x74')]())+_0x9dcd('0x7b')](_0x39e70a[_0x9dcd('0x33')][_0x9dcd('0x7c')]);}return null;})['then'](handleEntityNotFound(_0x57f447,null))[_0x9dcd('0x28')](respondWithStatusCode(_0x57f447,null))[_0x9dcd('0x47')](handleError(_0x57f447,null));};exports[_0x9dcd('0x7d')]=function(_0x1e3900,_0x52d30){var _0x538a8c=_[_0x9dcd('0x7e')](_0x1e3900[_0x9dcd('0x4c')][_0x9dcd('0x7c')])?_0x1e3900[_0x9dcd('0x4c')][_0x9dcd('0x7c')]:[_0x1e3900[_0x9dcd('0x4c')][_0x9dcd('0x7c')]];var _0x3bfbf5=_0x1e3900[_0x9dcd('0x49')]['id'];return db[_0x9dcd('0x2e')][_0x9dcd('0x4a')]({'where':{'id':_0x3bfbf5}})[_0x9dcd('0x28')](handleEntityNotFound(_0x52d30,null))[_0x9dcd('0x28')](function(_0x53173a){if(_0x53173a){var _0x26cb6a=[_0x9dcd('0x7f'),_0x9dcd('0x80'),_0x9dcd('0x81'),_0x9dcd('0x82'),'Fax','Openchannel',_0x9dcd('0x83')];return db[_0x9dcd('0x57')][_0x9dcd('0x84')](function(_0x24f746){var _0x26073c=_[_0x9dcd('0x2d')](_0x26cb6a,function(_0x53e3fc){var _0xc571a7={'attributes':['id','name']};if(_0x53e3fc==='Voice'){_0xc571a7[_0x9dcd('0x85')]={'attributes':['penalty']};}return _0x53173a['get'+_0x53e3fc+_0x9dcd('0x7b')](_0xc571a7)[_0x9dcd('0x28')](function(_0x3388a6){var _0x195034=_[_0x9dcd('0x2d')](_0x3388a6,function(_0x18298d){var _0x25447e=_['map'](_0x538a8c,function(_0x4bbd3d){var _0x1314fc={'where':{'UserId':_0x4bbd3d,[_0x53e3fc+_0x9dcd('0x86')]:_0x18298d['id']},'transaction':_0x24f746};if(_0x53e3fc===_0x9dcd('0x7f')){_0x1314fc[_0x9dcd('0x87')]={'penalty':_0x18298d['TeamVoiceQueue'][_0x9dcd('0x88')]};}return db[_0x9dcd('0x89')+_0x53e3fc+_0x9dcd('0x75')][_0x9dcd('0x8a')](_0x1314fc)[_0x9dcd('0x28')](function(){socket['emit'](_0x9dcd('0x4d')+_0x53e3fc+_0x9dcd('0x8b'),{'UserId':_0x4bbd3d,[_0x53e3fc+_0x9dcd('0x86')]:_0x18298d['id']});if(_0x53e3fc!=='Voice'){return;}return db[_0x9dcd('0x89')][_0x9dcd('0x8c')]({'where':{'id':_0x538a8c,'online':0x1},'attributes':['id',_0x9dcd('0x2a'),'online','voicePause','interface'],'raw':!![]})[_0x9dcd('0x28')](function(_0x4674eb){var _0x350689=_[_0x9dcd('0x2d')](_0x4674eb,function(_0x10d7f5){return db[_0x9dcd('0x8d')][_0x9dcd('0x8e')]({'membername':_0x10d7f5['name'],'UserId':_0x10d7f5['id'],'queue_name':_0x18298d[_0x9dcd('0x2a')],'VoiceQueueId':_0x18298d['id'],'interface':_[_0x9dcd('0x8f')](_0x10d7f5[_0x9dcd('0x90')])?util[_0x9dcd('0x91')](_0x9dcd('0x92'),_0x10d7f5[_0x9dcd('0x2a')]):_0x10d7f5['interface'],'paused':_0x10d7f5['voicePause']||![],'penalty':_0x18298d[_0x9dcd('0x93')]['penalty']},{'transaction':_0x24f746});});return Promise['all'](_0x350689);});});});return Promise['all'](_0x25447e);});return Promise['all'](_0x195034);})[_0x9dcd('0x28')](function(){return db['TeamVoicePrefix'][_0x9dcd('0x71')]({'where':{'teamId':_0x3bfbf5}})['then'](function(_0x1dfd19){if(_0x1dfd19){var _0xcdd2ec=_[_0x9dcd('0x2d')](_0x538a8c,function(_0x15298c){db[_0x9dcd('0x6e')][_0x9dcd('0x8e')]({'UserId':_0x15298c,'VoicePrefixId':_0x1dfd19[_0x9dcd('0x6f')]});});return Promise[_0x9dcd('0x94')](_0xcdd2ec);}});});});return Promise['all'](_0x26073c)[_0x9dcd('0x28')](function(){return _0x53173a[_0x9dcd('0x7d')](_0x538a8c,{'transaction':_0x24f746})[_0x9dcd('0x95')](function(_0x17d248){return _0x17d248;});});});}})[_0x9dcd('0x28')](respondWithResult(_0x52d30,null))[_0x9dcd('0x47')](handleError(_0x52d30,null));};exports[_0x9dcd('0x96')]=function(_0x594cc4,_0x58a77c){var _0xbf2a49=_['isArray'](_0x594cc4[_0x9dcd('0x33')][_0x9dcd('0x7c')])?_0x594cc4[_0x9dcd('0x33')][_0x9dcd('0x7c')]:[_0x594cc4[_0x9dcd('0x33')][_0x9dcd('0x7c')]];var _0x5a0693=_0x594cc4[_0x9dcd('0x49')]['id'];return db[_0x9dcd('0x2e')]['find']({'where':{'id':_0x5a0693}})[_0x9dcd('0x28')](handleEntityNotFound(_0x58a77c,null))['then'](function(_0x43c39b){if(_0x43c39b){var _0x170987=[_0x9dcd('0x7f'),_0x9dcd('0x80'),_0x9dcd('0x81'),_0x9dcd('0x82'),'Fax',_0x9dcd('0x97'),'Whatsapp'];return db[_0x9dcd('0x57')]['transaction'](function(_0x1fd6ed){var _0x3546ce=_['map'](_0x170987,function(_0x5c0dfe){var _0x66f326={'attributes':['id',_0x9dcd('0x2a')]};return _0x43c39b[_0x9dcd('0x4e')+_0x5c0dfe+_0x9dcd('0x7b')](_0x66f326)[_0x9dcd('0x28')](function(_0x5083da){var _0x4dff3a=_[_0x9dcd('0x2d')](_0x5083da,function(_0x5a0e8d){return _0x5a0e8d['removeAgents'](_0xbf2a49,{'transaction':_0x1fd6ed})['then'](function(){var _0x3e01f1=_[_0x9dcd('0x2d')](_0xbf2a49,function(_0x3362eb){socket[_0x9dcd('0x98')]('user'+_0x5c0dfe+_0x9dcd('0x99'),{'UserId':Number(_0x3362eb),[_0x5c0dfe+'QueueId']:_0x5a0e8d['id']});if(_0x5c0dfe!==_0x9dcd('0x7f')){return;}return db[_0x9dcd('0x8d')][_0x9dcd('0x62')]({'where':{'VoiceQueueId':_0x5a0e8d['id'],'UserId':_0x3362eb},'transaction':_0x1fd6ed});});return Promise[_0x9dcd('0x94')](_0x3e01f1);});});return Promise['all'](_0x4dff3a);});});return Promise[_0x9dcd('0x94')](_0x3546ce)['then'](function(){return _0x43c39b[_0x9dcd('0x96')](_0xbf2a49,{'transaction':_0x1fd6ed});})[_0x9dcd('0x28')](function(){return db[_0x9dcd('0x6d')][_0x9dcd('0x71')]({'where':{'teamId':_0x5a0693}})[_0x9dcd('0x28')](function(_0x394591){if(_0x394591){var _0x3260c0=_[_0x9dcd('0x2d')](_0xbf2a49,function(_0x125d37){db[_0x9dcd('0x6e')][_0x9dcd('0x62')]({'where':{'UserId':_0x125d37,'VoicePrefixId':_0x394591['VoicePrefixId']}});});return Promise['all'](_0x3260c0);}});});});}})[_0x9dcd('0x28')](respondWithStatusCode(_0x58a77c,null))[_0x9dcd('0x47')](handleError(_0x58a77c,null));};exports[_0x9dcd('0x9a')]=function(_0x298029,_0x29e3a4,_0x5b2e21){var _0x18672b={};var _0x1fb502={};var _0x1fb766;var _0x207dcd;return db[_0x9dcd('0x2e')][_0x9dcd('0x71')]({'where':{'id':_0x298029[_0x9dcd('0x49')]['id']}})[_0x9dcd('0x28')](handleEntityNotFound(_0x29e3a4,null))['then'](function(_0x51dad5){if(_0x51dad5){_0x1fb766=_0x51dad5;_0x1fb502['model']=_[_0x9dcd('0x34')](db[_0x9dcd('0x89')]['rawAttributes']);_0x1fb502[_0x9dcd('0x33')]=_[_0x9dcd('0x34')](_0x298029['query']);_0x1fb502[_0x9dcd('0x35')]=_[_0x9dcd('0x36')](_0x1fb502[_0x9dcd('0x32')],_0x1fb502[_0x9dcd('0x33')]);_0x18672b[_0x9dcd('0x38')]=_[_0x9dcd('0x36')](_0x1fb502['model'],qs[_0x9dcd('0x37')](_0x298029[_0x9dcd('0x33')]['fields']));_0x18672b[_0x9dcd('0x38')]=_0x18672b[_0x9dcd('0x38')]['length']?_0x18672b[_0x9dcd('0x38')]:_0x1fb502[_0x9dcd('0x32')];_0x18672b['order']=qs[_0x9dcd('0x3d')](_0x298029[_0x9dcd('0x33')][_0x9dcd('0x3d')]);_0x18672b[_0x9dcd('0x3e')]=qs[_0x9dcd('0x35')](_[_0x9dcd('0x3f')](_0x298029[_0x9dcd('0x33')],_0x1fb502['filters']));if(_0x298029[_0x9dcd('0x33')][_0x9dcd('0x42')]){_0x18672b[_0x9dcd('0x3e')]=_[_0x9dcd('0x40')](_0x18672b[_0x9dcd('0x3e')],{'$or':_[_0x9dcd('0x2d')](_0x18672b[_0x9dcd('0x38')],function(_0x3d4c19){var _0x10dc61={};_0x10dc61[_0x3d4c19]={'$like':'%'+_0x298029['query']['filter']+'%'};return _0x10dc61;})});}_0x18672b=_[_0x9dcd('0x40')]({},_0x18672b,_0x298029[_0x9dcd('0x43')]);return _0x1fb766['getAgents'](_0x18672b);}})[_0x9dcd('0x28')](function(_0x32beaa){if(_0x32beaa){_0x207dcd=_0x32beaa[_0x9dcd('0x39')];if(!_0x298029[_0x9dcd('0x33')]['hasOwnProperty']('nolimit')){_0x18672b[_0x9dcd('0x21')]=qs[_0x9dcd('0x21')](_0x298029[_0x9dcd('0x33')][_0x9dcd('0x21')]);_0x18672b[_0x9dcd('0x1e')]=qs[_0x9dcd('0x1e')](_0x298029[_0x9dcd('0x33')][_0x9dcd('0x1e')]);}return _0x1fb766[_0x9dcd('0x9a')](_0x18672b);}})[_0x9dcd('0x28')](function(_0x413517){if(_0x413517){return _0x413517?{'count':_0x207dcd,'rows':_0x413517}:null;}})[_0x9dcd('0x28')](respondWithResult(_0x29e3a4,null))[_0x9dcd('0x47')](handleError(_0x29e3a4,null));};