74cb67083d1e8e8fce3de5ecbe85a208025531af
[motion2.git] / server / api / openchannelQueue / openchannelQueue.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 _0xf2c4=['each','findOrCreate','forEach','userOpenchannelQueue:save','removeTeams','User','select','field','tq.TeamId','team_has_openchannel_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','OpenchannelQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','QueryTypes','SELECT','TeamId','includes','all','union','compact','value','isEmpty','removeAgents','userOpenchannelQueue:remove','addAgents','spread','emit','getAgents','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','fs-extra','lodash','squel','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','defaults','redis','localhost','./openchannelQueue.socket','sendStatus','undefined','limit','count','offset','Content-Range','json','reject','save','then','destroy','get','UserProfileResource','status','error','stack','name','index','fieldName','key','model','map','keys','query','filters','intersection','fields','attributes','length','nolimit','order','sort','where','pick','merge','VIRTUAL','filter','options','OpenchannelQueue','include','show','params','rawAttributes','find','catch','create','body','user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','getMembers','UserOpenchannelQueue','hasOwnProperty','findAndCountAll','openchannelPause','updatedAt','createdAt','rows','%s/%s','SIP','findOne','Team','getTeams','ids','findAll','Agents','online','voicePause','interface','sequelize','transaction'];(function(_0x3390b3,_0x354c9c){var _0x4befca=function(_0x114951){while(--_0x114951){_0x3390b3['push'](_0x3390b3['shift']());}};_0x4befca(++_0x354c9c);}(_0xf2c4,0xab));var _0x4f2c=function(_0x413feb,_0x10477f){_0x413feb=_0x413feb-0x0;var _0x40ee88=_0xf2c4[_0x413feb];return _0x40ee88;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x4f2c('0x0'));var jsonpatch=require(_0x4f2c('0x1'));var rp=require(_0x4f2c('0x2'));var moment=require(_0x4f2c('0x3'));var BPromise=require(_0x4f2c('0x4'));var Mustache=require(_0x4f2c('0x5'));var util=require(_0x4f2c('0x6'));var path=require(_0x4f2c('0x7'));var sox=require(_0x4f2c('0x8'));var csv=require('to-csv');var ejs=require(_0x4f2c('0x9'));var fs=require('fs');var fs_extra=require(_0x4f2c('0xa'));var _=require(_0x4f2c('0xb'));var squel=require(_0x4f2c('0xc'));var crypto=require('crypto');var jsforce=require(_0x4f2c('0xd'));var deskjs=require(_0x4f2c('0xe'));var toCsv=require(_0x4f2c('0xf'));var querystring=require(_0x4f2c('0x10'));var Papa=require(_0x4f2c('0x11'));var Redis=require(_0x4f2c('0x12'));var authService=require(_0x4f2c('0x13'));var qs=require(_0x4f2c('0x14'));var as=require(_0x4f2c('0x15'));var hardwareService=require(_0x4f2c('0x16'));var logger=require(_0x4f2c('0x17'))(_0x4f2c('0x18'));var utils=require(_0x4f2c('0x19'));var config=require('../../config/environment');var licenseUtil=require(_0x4f2c('0x1a'));var db=require(_0x4f2c('0x1b'))['db'];config['redis']=_[_0x4f2c('0x1c')](config[_0x4f2c('0x1d')],{'host':_0x4f2c('0x1e'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x4f2c('0x1f'))['register'](socket);function respondWithStatusCode(_0x3fbdd4,_0x88efda){_0x88efda=_0x88efda||0xcc;return function(_0x148446){if(_0x148446){return _0x3fbdd4[_0x4f2c('0x20')](_0x88efda);}return _0x3fbdd4['status'](_0x88efda)['end']();};}function respondWithResult(_0x545d99,_0x3be9a9){_0x3be9a9=_0x3be9a9||0xc8;return function(_0x2fef91){if(_0x2fef91){return _0x545d99['status'](_0x3be9a9)['json'](_0x2fef91);}};}function respondWithFilteredResult(_0x41d064,_0x4a9f76){return function(_0x3eb03c){if(_0x3eb03c){var _0x443057=typeof _0x4a9f76['offset']===_0x4f2c('0x21')&&typeof _0x4a9f76[_0x4f2c('0x22')]===_0x4f2c('0x21');var _0x3bf567=_0x3eb03c[_0x4f2c('0x23')];var _0x46a8b4=_0x443057?0x0:_0x4a9f76['offset'];var _0x280f58=_0x443057?_0x3eb03c[_0x4f2c('0x23')]:_0x4a9f76[_0x4f2c('0x24')]+_0x4a9f76['limit'];var _0x28682e;if(_0x280f58>=_0x3bf567){_0x280f58=_0x3bf567;_0x28682e=0xc8;}else{_0x28682e=0xce;}_0x41d064['status'](_0x28682e);return _0x41d064['set'](_0x4f2c('0x25'),_0x46a8b4+'-'+_0x280f58+'/'+_0x3bf567)[_0x4f2c('0x26')](_0x3eb03c);}return null;};}function patchUpdates(_0x1ef8fe){return function(_0x28b37b){try{jsonpatch['apply'](_0x28b37b,_0x1ef8fe,!![]);}catch(_0x1382f2){return BPromise[_0x4f2c('0x27')](_0x1382f2);}return _0x28b37b[_0x4f2c('0x28')]();};}function saveUpdates(_0x1b92b3,_0x1455a4){return function(_0x1e1503){if(_0x1e1503){return _0x1e1503['update'](_0x1b92b3)[_0x4f2c('0x29')](function(_0x51ffd2){return _0x51ffd2;});}return null;};}function removeEntity(_0x16f873,_0x3cbc3f){return function(_0x6aa815){if(_0x6aa815){return _0x6aa815[_0x4f2c('0x2a')]()[_0x4f2c('0x29')](function(){var _0x45f038=_0x6aa815[_0x4f2c('0x2b')]({'plain':!![]});var _0x3b2042='OpenchannelQueues';return db[_0x4f2c('0x2c')][_0x4f2c('0x2a')]({'where':{'type':_0x3b2042,'resourceId':_0x45f038['id']}})[_0x4f2c('0x29')](function(){return _0x6aa815;});})[_0x4f2c('0x29')](function(){_0x16f873[_0x4f2c('0x2d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x25ccf9,_0x3c4c2c){return function(_0x5cb924){if(!_0x5cb924){_0x25ccf9['sendStatus'](0x194);}return _0x5cb924;};}function handleError(_0x725522,_0x1e5dc1){_0x1e5dc1=_0x1e5dc1||0x1f4;return function(_0x11f7ea){logger[_0x4f2c('0x2e')](_0x11f7ea[_0x4f2c('0x2f')]);if(_0x11f7ea[_0x4f2c('0x30')]){delete _0x11f7ea[_0x4f2c('0x30')];}_0x725522['status'](_0x1e5dc1)['send'](_0x11f7ea);};}exports[_0x4f2c('0x31')]=function(_0x15253e,_0x4e8ce9){var _0x3cc5fb={},_0x6052b3={},_0x1492b5={'count':0x0,'rows':[]};var _0x4ef76f=_['map'](db['OpenchannelQueue']['rawAttributes'],function(_0x20f392){return{'name':_0x20f392[_0x4f2c('0x32')],'type':_0x20f392['type'][_0x4f2c('0x33')]};});_0x6052b3[_0x4f2c('0x34')]=_[_0x4f2c('0x35')](_0x4ef76f,'name');_0x6052b3['query']=_[_0x4f2c('0x36')](_0x15253e[_0x4f2c('0x37')]);_0x6052b3[_0x4f2c('0x38')]=_[_0x4f2c('0x39')](_0x6052b3['model'],_0x6052b3[_0x4f2c('0x37')]);_0x3cc5fb['attributes']=_[_0x4f2c('0x39')](_0x6052b3[_0x4f2c('0x34')],qs[_0x4f2c('0x3a')](_0x15253e[_0x4f2c('0x37')][_0x4f2c('0x3a')]));_0x3cc5fb[_0x4f2c('0x3b')]=_0x3cc5fb[_0x4f2c('0x3b')][_0x4f2c('0x3c')]?_0x3cc5fb[_0x4f2c('0x3b')]:_0x6052b3['model'];if(!_0x15253e[_0x4f2c('0x37')]['hasOwnProperty'](_0x4f2c('0x3d'))){_0x3cc5fb['limit']=qs[_0x4f2c('0x22')](_0x15253e['query'][_0x4f2c('0x22')]);_0x3cc5fb[_0x4f2c('0x24')]=qs[_0x4f2c('0x24')](_0x15253e[_0x4f2c('0x37')][_0x4f2c('0x24')]);}_0x3cc5fb[_0x4f2c('0x3e')]=qs[_0x4f2c('0x3f')](_0x15253e[_0x4f2c('0x37')][_0x4f2c('0x3f')]);_0x3cc5fb[_0x4f2c('0x40')]=qs['filters'](_[_0x4f2c('0x41')](_0x15253e[_0x4f2c('0x37')],_0x6052b3['filters']),_0x4ef76f);if(_0x15253e[_0x4f2c('0x37')]['filter']){_0x3cc5fb['where']=_[_0x4f2c('0x42')](_0x3cc5fb[_0x4f2c('0x40')],{'$or':_[_0x4f2c('0x35')](_0x4ef76f,function(_0x4aaf54){if(_0x4aaf54['type']!==_0x4f2c('0x43')){var _0x54ed81={};_0x54ed81[_0x4aaf54[_0x4f2c('0x30')]]={'$like':'%'+_0x15253e['query'][_0x4f2c('0x44')]+'%'};return _0x54ed81;}})});}_0x3cc5fb=_[_0x4f2c('0x42')]({},_0x3cc5fb,_0x15253e[_0x4f2c('0x45')]);var _0x22e5ad={'where':_0x3cc5fb[_0x4f2c('0x40')]};return db[_0x4f2c('0x46')][_0x4f2c('0x23')](_0x22e5ad)[_0x4f2c('0x29')](function(_0x62c240){_0x1492b5['count']=_0x62c240;if(_0x15253e[_0x4f2c('0x37')]['includeAll']){_0x3cc5fb[_0x4f2c('0x47')]=[{'all':!![]}];}return db[_0x4f2c('0x46')]['findAll'](_0x3cc5fb);})[_0x4f2c('0x29')](function(_0x489d2b){_0x1492b5['rows']=_0x489d2b;return _0x1492b5;})[_0x4f2c('0x29')](respondWithFilteredResult(_0x4e8ce9,_0x3cc5fb))['catch'](handleError(_0x4e8ce9,null));};exports[_0x4f2c('0x48')]=function(_0x4aad30,_0x365ee4){var _0x1f2fff={'raw':!![],'where':{'id':_0x4aad30[_0x4f2c('0x49')]['id']}},_0x9b2092={};_0x9b2092[_0x4f2c('0x34')]=_[_0x4f2c('0x36')](db[_0x4f2c('0x46')][_0x4f2c('0x4a')]);_0x9b2092[_0x4f2c('0x37')]=_[_0x4f2c('0x36')](_0x4aad30[_0x4f2c('0x37')]);_0x9b2092['filters']=_[_0x4f2c('0x39')](_0x9b2092['model'],_0x9b2092[_0x4f2c('0x37')]);_0x1f2fff[_0x4f2c('0x3b')]=_[_0x4f2c('0x39')](_0x9b2092[_0x4f2c('0x34')],qs[_0x4f2c('0x3a')](_0x4aad30['query']['fields']));_0x1f2fff[_0x4f2c('0x3b')]=_0x1f2fff[_0x4f2c('0x3b')][_0x4f2c('0x3c')]?_0x1f2fff[_0x4f2c('0x3b')]:_0x9b2092[_0x4f2c('0x34')];if(_0x4aad30[_0x4f2c('0x37')]['includeAll']){_0x1f2fff['include']=[{'all':!![]}];}_0x1f2fff=_[_0x4f2c('0x42')]({},_0x1f2fff,_0x4aad30[_0x4f2c('0x45')]);return db[_0x4f2c('0x46')][_0x4f2c('0x4b')](_0x1f2fff)[_0x4f2c('0x29')](handleEntityNotFound(_0x365ee4,null))[_0x4f2c('0x29')](respondWithResult(_0x365ee4,null))[_0x4f2c('0x4c')](handleError(_0x365ee4,null));};exports[_0x4f2c('0x4d')]=function(_0x577b12,_0x5298cb){return db[_0x4f2c('0x46')]['create'](_0x577b12[_0x4f2c('0x4e')],{})[_0x4f2c('0x29')](function(_0x49c229){var _0x1a36b2=_0x577b12[_0x4f2c('0x4f')][_0x4f2c('0x2b')]({'plain':!![]});if(!_0x1a36b2)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x1a36b2[_0x4f2c('0x50')]===_0x4f2c('0x4f')){var _0x1108e8=_0x49c229[_0x4f2c('0x2b')]({'plain':!![]});var _0x37e853='OpenchannelQueues';return db[_0x4f2c('0x51')][_0x4f2c('0x4b')]({'where':{'name':_0x37e853,'userProfileId':_0x1a36b2[_0x4f2c('0x52')]},'raw':!![]})[_0x4f2c('0x29')](function(_0x2ec685){if(_0x2ec685&&_0x2ec685[_0x4f2c('0x53')]===0x0){return db[_0x4f2c('0x2c')][_0x4f2c('0x4d')]({'name':_0x1108e8[_0x4f2c('0x30')],'resourceId':_0x1108e8['id'],'type':_0x2ec685[_0x4f2c('0x30')],'sectionId':_0x2ec685['id']},{})[_0x4f2c('0x29')](function(){return _0x49c229;});}else{return _0x49c229;}})[_0x4f2c('0x4c')](function(_0x38bdc0){logger[_0x4f2c('0x2e')](_0x4f2c('0x54'),_0x38bdc0);throw _0x38bdc0;});}return _0x49c229;})[_0x4f2c('0x29')](respondWithResult(_0x5298cb,0xc9))[_0x4f2c('0x4c')](handleError(_0x5298cb,null));};exports['update']=function(_0x11ca1c,_0x2df175){if(_0x11ca1c[_0x4f2c('0x4e')]['id']){delete _0x11ca1c['body']['id'];}return db[_0x4f2c('0x46')]['find']({'where':{'id':_0x11ca1c[_0x4f2c('0x49')]['id']}})['then'](handleEntityNotFound(_0x2df175,null))[_0x4f2c('0x29')](saveUpdates(_0x11ca1c[_0x4f2c('0x4e')],null))[_0x4f2c('0x29')](respondWithResult(_0x2df175,null))[_0x4f2c('0x4c')](handleError(_0x2df175,null));};exports[_0x4f2c('0x2a')]=function(_0x25599f,_0x4a040f){return db['OpenchannelQueue']['find']({'where':{'id':_0x25599f[_0x4f2c('0x49')]['id']}})[_0x4f2c('0x29')](handleEntityNotFound(_0x4a040f,null))[_0x4f2c('0x29')](removeEntity(_0x4a040f,null))['catch'](handleError(_0x4a040f,null));};exports[_0x4f2c('0x55')]=function(_0x200529,_0x4719a9){return db[_0x4f2c('0x46')]['describe']()[_0x4f2c('0x29')](respondWithResult(_0x4719a9,null))[_0x4f2c('0x4c')](handleError(_0x4719a9,null));};exports[_0x4f2c('0x56')]=function(_0x10bf8f,_0xd0c44f,_0x21febe){var _0x7ac2b5={'raw':!![],'where':{}},_0x5edc54={},_0x5db9e4;return db[_0x4f2c('0x46')]['findOne']({'where':{'id':_0x10bf8f[_0x4f2c('0x49')]['id']}})[_0x4f2c('0x29')](handleEntityNotFound(_0xd0c44f,null))[_0x4f2c('0x29')](function(_0x4ccedc){if(_0x4ccedc){_0x5db9e4=_0x4ccedc[_0x4f2c('0x2b')]({'plain':!![]});_0x5edc54['model']=_['keys'](db[_0x4f2c('0x57')][_0x4f2c('0x4a')]);_0x5edc54['query']=_[_0x4f2c('0x36')](_0x10bf8f['query']);_0x5edc54[_0x4f2c('0x38')]=_['intersection'](_0x5edc54[_0x4f2c('0x34')],_0x5edc54['query']);_0x7ac2b5['attributes']=_[_0x4f2c('0x39')](_0x5edc54[_0x4f2c('0x34')],qs[_0x4f2c('0x3a')](_0x10bf8f['query'][_0x4f2c('0x3a')]));_0x7ac2b5[_0x4f2c('0x3b')]=_0x7ac2b5['attributes'][_0x4f2c('0x3c')]?_0x7ac2b5[_0x4f2c('0x3b')]:_0x5edc54[_0x4f2c('0x34')];if(!_0x10bf8f[_0x4f2c('0x37')][_0x4f2c('0x58')](_0x4f2c('0x3d'))){_0x7ac2b5[_0x4f2c('0x22')]=qs[_0x4f2c('0x22')](_0x10bf8f[_0x4f2c('0x37')][_0x4f2c('0x22')]);_0x7ac2b5[_0x4f2c('0x24')]=qs[_0x4f2c('0x24')](_0x10bf8f[_0x4f2c('0x37')]['offset']);}_0x7ac2b5[_0x4f2c('0x3e')]=qs[_0x4f2c('0x3f')](_0x10bf8f[_0x4f2c('0x37')][_0x4f2c('0x3f')]);_0x7ac2b5['where']=qs[_0x4f2c('0x38')](_[_0x4f2c('0x41')](_0x10bf8f[_0x4f2c('0x37')],_0x5edc54[_0x4f2c('0x38')]));_0x7ac2b5['where']['OpenchannelQueueId']=_0x4ccedc['id'];if(_0x10bf8f['query'][_0x4f2c('0x44')]){_0x7ac2b5[_0x4f2c('0x40')]=_[_0x4f2c('0x42')](_0x7ac2b5[_0x4f2c('0x40')],{'$or':_[_0x4f2c('0x35')](_0x7ac2b5[_0x4f2c('0x3b')],function(_0x4f56d4){var _0x552486={};_0x552486[_0x4f56d4]={'$like':'%'+_0x10bf8f['query']['filter']+'%'};return _0x552486;})});}_0x7ac2b5=_[_0x4f2c('0x42')]({},_0x7ac2b5,_0x10bf8f[_0x4f2c('0x45')]);return db[_0x4f2c('0x57')]['findAll'](_0x7ac2b5);}})[_0x4f2c('0x29')](function(_0x42caa4){if(_0x42caa4){return db['User'][_0x4f2c('0x59')]({'where':{'id':_[_0x4f2c('0x35')](_0x42caa4,'UserId'),'role':'agent'},'attributes':['id','name',_0x4f2c('0x5a'),_0x4f2c('0x5b'),_0x4f2c('0x5c')]});}})[_0x4f2c('0x29')](function(_0x44f20a){if(_0x44f20a){return{'count':_0x44f20a['count'],'rows':_[_0x4f2c('0x35')](_0x44f20a[_0x4f2c('0x5d')],function(_0x401802){return{'membername':_0x401802[_0x4f2c('0x30')],'UserId':_0x401802['id'],'queue_name':_0x5db9e4[_0x4f2c('0x30')],'OpenchannelQueueId':_0x5db9e4['id'],'interface':util['format'](_0x4f2c('0x5e'),_0x4f2c('0x5f'),_0x401802[_0x4f2c('0x30')]),'penalty':0x0,'paused':_0x401802[_0x4f2c('0x5a')],'createdAt':_0x401802[_0x4f2c('0x5c')],'updatedAt':_0x401802[_0x4f2c('0x5b')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x4f2c('0x29')](respondWithFilteredResult(_0xd0c44f,_0x7ac2b5))[_0x4f2c('0x4c')](handleError(_0xd0c44f,null));};exports['getTeams']=function(_0xb46839,_0x987dd6,_0x58b065){var _0x3fb07e={};var _0x300cca={};var _0x401f5c;var _0x2aa60f;return db[_0x4f2c('0x46')][_0x4f2c('0x60')]({'where':{'id':_0xb46839['params']['id']}})[_0x4f2c('0x29')](handleEntityNotFound(_0x987dd6,null))[_0x4f2c('0x29')](function(_0x7fdffe){if(_0x7fdffe){_0x401f5c=_0x7fdffe;_0x300cca['model']=_[_0x4f2c('0x36')](db[_0x4f2c('0x61')][_0x4f2c('0x4a')]);_0x300cca[_0x4f2c('0x37')]=_['keys'](_0xb46839['query']);_0x300cca[_0x4f2c('0x38')]=_[_0x4f2c('0x39')](_0x300cca[_0x4f2c('0x34')],_0x300cca[_0x4f2c('0x37')]);_0x3fb07e[_0x4f2c('0x3b')]=_[_0x4f2c('0x39')](_0x300cca[_0x4f2c('0x34')],qs['fields'](_0xb46839[_0x4f2c('0x37')][_0x4f2c('0x3a')]));_0x3fb07e['attributes']=_0x3fb07e['attributes'][_0x4f2c('0x3c')]?_0x3fb07e[_0x4f2c('0x3b')]:_0x300cca[_0x4f2c('0x34')];_0x3fb07e[_0x4f2c('0x3e')]=qs[_0x4f2c('0x3f')](_0xb46839[_0x4f2c('0x37')][_0x4f2c('0x3f')]);_0x3fb07e[_0x4f2c('0x40')]=qs['filters'](_['pick'](_0xb46839[_0x4f2c('0x37')],_0x300cca[_0x4f2c('0x38')]));if(_0xb46839[_0x4f2c('0x37')][_0x4f2c('0x44')]){_0x3fb07e[_0x4f2c('0x40')]=_[_0x4f2c('0x42')](_0x3fb07e[_0x4f2c('0x40')],{'$or':_['map'](_0x3fb07e[_0x4f2c('0x3b')],function(_0x234439){var _0x476dc7={};_0x476dc7[_0x234439]={'$like':'%'+_0xb46839[_0x4f2c('0x37')][_0x4f2c('0x44')]+'%'};return _0x476dc7;})});}_0x3fb07e=_[_0x4f2c('0x42')]({},_0x3fb07e,_0xb46839['options']);return _0x401f5c['getTeams'](_0x3fb07e);}})[_0x4f2c('0x29')](function(_0xbaac4e){if(_0xbaac4e){_0x2aa60f=_0xbaac4e[_0x4f2c('0x3c')];if(!_0xb46839['query']['hasOwnProperty'](_0x4f2c('0x3d'))){_0x3fb07e[_0x4f2c('0x22')]=qs[_0x4f2c('0x22')](_0xb46839[_0x4f2c('0x37')][_0x4f2c('0x22')]);_0x3fb07e['offset']=qs[_0x4f2c('0x24')](_0xb46839[_0x4f2c('0x37')]['offset']);}return _0x401f5c[_0x4f2c('0x62')](_0x3fb07e);}})['then'](function(_0x25efe7){if(_0x25efe7){return _0x25efe7?{'count':_0x2aa60f,'rows':_0x25efe7}:null;}})[_0x4f2c('0x29')](respondWithResult(_0x987dd6,null))[_0x4f2c('0x4c')](handleError(_0x987dd6,null));};exports['addTeams']=function(_0x3702e5,_0x264da6,_0x5b838a){var _0x5280c4=_0x3702e5['body'][_0x4f2c('0x63')];return db['Team'][_0x4f2c('0x64')]({'where':{'id':_0x5280c4},'attributes':['id'],'include':[{'model':db['User'],'as':_0x4f2c('0x65'),'attributes':['id',_0x4f2c('0x30'),_0x4f2c('0x66'),_0x4f2c('0x67'),_0x4f2c('0x68')],'raw':!![]}]})['then'](function(_0x3ed7c0){if(_0x3ed7c0){var _0x22411e=_['flatMap'](_0x3ed7c0,function(_0x4572d8){var _0x4ad031=_0x4572d8['get']({'plain':!![]});return _0x4ad031[_0x4f2c('0x65')];});return db[_0x4f2c('0x46')][_0x4f2c('0x4b')]({'where':{'id':_0x3702e5['params']['id']}})['then'](function(_0x43e3c3){return db[_0x4f2c('0x69')][_0x4f2c('0x6a')](function(_0x53e6ee){return _0x43e3c3['addTeams'](_0x5280c4,{'transaction':_0x53e6ee})[_0x4f2c('0x29')](function(){return BPromise[_0x4f2c('0x6b')](_0x22411e,function(_0x4d0b1e){return db[_0x4f2c('0x57')][_0x4f2c('0x6c')]({'where':{'UserId':_0x4d0b1e['id'],'OpenchannelQueueId':_0x3702e5[_0x4f2c('0x49')]['id']},'transaction':_0x53e6ee});});})[_0x4f2c('0x29')](function(){_0x22411e[_0x4f2c('0x6d')](function(_0x3e8030){socket['emit'](_0x4f2c('0x6e'),{'UserId':_0x3e8030['id'],'OpenchannelQueueId':_0x43e3c3['id']});});});});});}})[_0x4f2c('0x29')](respondWithStatusCode(_0x264da6,null))[_0x4f2c('0x4c')](handleError(_0x264da6,null));};exports[_0x4f2c('0x6f')]=function(_0x38cf39,_0x385f3a,_0x149fa2){return db[_0x4f2c('0x61')]['findAll']({'where':{'id':_0x38cf39[_0x4f2c('0x37')]['ids']},'attributes':['id'],'include':[{'model':db[_0x4f2c('0x70')],'as':_0x4f2c('0x65'),'attributes':['id'],'raw':!![]}]})[_0x4f2c('0x29')](handleEntityNotFound(_0x385f3a,null))[_0x4f2c('0x29')](function(_0x43fea0){var _0x1128d4=_['map'](_0x43fea0,'id');var _0x310a42=[];var _0x4ea289=[];var _0x544a39=squel[_0x4f2c('0x71')]();_0x544a39[_0x4f2c('0x72')](_0x4f2c('0x73'))['from'](_0x4f2c('0x74'),'tq')[_0x4f2c('0x75')](_0x4f2c('0x76'),'ut',_0x4f2c('0x77'))[_0x4f2c('0x40')](_0x4f2c('0x78'),_0x38cf39[_0x4f2c('0x49')]['id']);for(var _0x9b433c=0x0;_0x9b433c<_0x43fea0[_0x4f2c('0x3c')];_0x9b433c+=0x1){let _0x1928aa=_0x43fea0[_0x9b433c];for(var _0x40d5a2=0x0;_0x40d5a2<_0x1928aa[_0x4f2c('0x65')][_0x4f2c('0x3c')];_0x40d5a2+=0x1){let _0xfc9cd7=_0x1928aa[_0x4f2c('0x65')][_0x40d5a2];var _0x4137eb=_0x544a39[_0x4f2c('0x79')]();_0x4137eb['where'](_0x4f2c('0x7a'),_0xfc9cd7['id']);_0x4ea289[_0x4f2c('0x7b')](db[_0x4f2c('0x69')][_0x4f2c('0x37')](_0x4137eb['toString'](),{'type':db[_0x4f2c('0x69')][_0x4f2c('0x7c')][_0x4f2c('0x7d')]})['then'](function(_0x1d86b1){if(_0x1d86b1[_0x4f2c('0x3c')]===0x1){return _0xfc9cd7['id'];}else{var _0x520213=_['every'](_[_0x4f2c('0x35')](_0x1d86b1,_0x4f2c('0x7e')),function(_0x5094d5){return _[_0x4f2c('0x7f')](_0x1128d4,_0x5094d5);});if(_0x520213){return _0xfc9cd7['id'];}}}));}}return BPromise[_0x4f2c('0x80')](_0x4ea289)[_0x4f2c('0x29')](function(_0x53cb5f){_0x310a42=_(_0x310a42)[_0x4f2c('0x81')](_0x53cb5f)[_0x4f2c('0x82')]()[_0x4f2c('0x83')]();return db[_0x4f2c('0x46')][_0x4f2c('0x4b')]({'where':{'id':_0x38cf39[_0x4f2c('0x49')]['id']}})[_0x4f2c('0x29')](function(_0x480e24){return db['sequelize'][_0x4f2c('0x6a')](function(_0xff6c4f){return _0x480e24[_0x4f2c('0x6f')](_0x38cf39['query'][_0x4f2c('0x63')],{'transaction':_0xff6c4f})[_0x4f2c('0x29')](function(){if(!_[_0x4f2c('0x84')](_0x310a42)){return _0x480e24[_0x4f2c('0x85')](_0x310a42,{'transaction':_0xff6c4f});}})[_0x4f2c('0x29')](function(){_0x310a42[_0x4f2c('0x6d')](function(_0x5e3470){socket['emit'](_0x4f2c('0x86'),{'UserId':_0x5e3470,'OpenchannelQueueId':_0x480e24['id']});});});});});});})[_0x4f2c('0x29')](respondWithStatusCode(_0x385f3a,null))['catch'](handleError(_0x385f3a,null));};exports[_0x4f2c('0x87')]=function(_0x4aaa88,_0x18ca3a,_0xaef004){return db[_0x4f2c('0x46')][_0x4f2c('0x4b')]({'where':{'id':_0x4aaa88[_0x4f2c('0x49')]['id']}})['then'](handleEntityNotFound(_0x18ca3a,null))[_0x4f2c('0x29')](function(_0x6df1c0){if(_0x6df1c0){return _0x6df1c0[_0x4f2c('0x87')](_0x4aaa88[_0x4f2c('0x4e')]['ids'],_['omit'](_0x4aaa88[_0x4f2c('0x4e')],[_0x4f2c('0x63'),'id'])||{})[_0x4f2c('0x88')](function(_0x5410b4){for(var _0xbafccf=0x0;_0xbafccf<_0x4aaa88[_0x4f2c('0x4e')]['ids'][_0x4f2c('0x3c')];_0xbafccf+=0x1){socket[_0x4f2c('0x89')](_0x4f2c('0x6e'),{'UserId':Number(_0x4aaa88[_0x4f2c('0x4e')][_0x4f2c('0x63')][_0xbafccf]),'OpenchannelQueueId':Number(_0x4aaa88[_0x4f2c('0x49')]['id'])});}return _0x5410b4;});}})['then'](respondWithResult(_0x18ca3a,null))[_0x4f2c('0x4c')](handleError(_0x18ca3a,null));};exports[_0x4f2c('0x85')]=function(_0x189459,_0x5dbaec,_0xd320c3){return db[_0x4f2c('0x46')][_0x4f2c('0x4b')]({'where':{'id':_0x189459[_0x4f2c('0x49')]['id']}})[_0x4f2c('0x29')](handleEntityNotFound(_0x5dbaec,null))[_0x4f2c('0x29')](function(_0x48a8ad){if(_0x48a8ad){return _0x48a8ad[_0x4f2c('0x85')](_0x189459['query'][_0x4f2c('0x63')])[_0x4f2c('0x29')](function(){if(_['isArray'](_0x189459[_0x4f2c('0x37')][_0x4f2c('0x63')])){for(var _0x84e69e=0x0;_0x84e69e<_0x189459['query'][_0x4f2c('0x63')][_0x4f2c('0x3c')];_0x84e69e+=0x1){socket[_0x4f2c('0x89')](_0x4f2c('0x86'),{'UserId':Number(_0x189459['query'][_0x4f2c('0x63')][_0x84e69e]),'OpenchannelQueueId':Number(_0x189459['params']['id'])});}}else{socket[_0x4f2c('0x89')](_0x4f2c('0x86'),{'UserId':Number(_0x189459[_0x4f2c('0x37')][_0x4f2c('0x63')]),'OpenchannelQueueId':Number(_0x189459[_0x4f2c('0x49')]['id'])});}});}})[_0x4f2c('0x29')](respondWithStatusCode(_0x5dbaec,null))[_0x4f2c('0x4c')](handleError(_0x5dbaec,null));};exports[_0x4f2c('0x8a')]=function(_0x13eb69,_0x32d04c,_0x5c355c){var _0x479e24={};var _0x2a4177={};var _0x5508a4;var _0x5b9c18;return db[_0x4f2c('0x46')][_0x4f2c('0x60')]({'where':{'id':_0x13eb69[_0x4f2c('0x49')]['id']}})[_0x4f2c('0x29')](handleEntityNotFound(_0x32d04c,null))[_0x4f2c('0x29')](function(_0x181c57){if(_0x181c57){_0x5508a4=_0x181c57;_0x2a4177['model']=_[_0x4f2c('0x36')](db[_0x4f2c('0x70')][_0x4f2c('0x4a')]);_0x2a4177[_0x4f2c('0x37')]=_['keys'](_0x13eb69[_0x4f2c('0x37')]);_0x2a4177[_0x4f2c('0x38')]=_[_0x4f2c('0x39')](_0x2a4177['model'],_0x2a4177[_0x4f2c('0x37')]);_0x479e24[_0x4f2c('0x3b')]=_[_0x4f2c('0x39')](_0x2a4177[_0x4f2c('0x34')],qs[_0x4f2c('0x3a')](_0x13eb69[_0x4f2c('0x37')]['fields']));_0x479e24[_0x4f2c('0x3b')]=_0x479e24[_0x4f2c('0x3b')][_0x4f2c('0x3c')]?_0x479e24[_0x4f2c('0x3b')]:_0x2a4177['model'];_0x479e24['order']=qs['sort'](_0x13eb69[_0x4f2c('0x37')][_0x4f2c('0x3f')]);_0x479e24[_0x4f2c('0x40')]=qs[_0x4f2c('0x38')](_[_0x4f2c('0x41')](_0x13eb69['query'],_0x2a4177[_0x4f2c('0x38')]));if(_0x13eb69[_0x4f2c('0x37')][_0x4f2c('0x44')]){_0x479e24[_0x4f2c('0x40')]=_[_0x4f2c('0x42')](_0x479e24[_0x4f2c('0x40')],{'$or':_[_0x4f2c('0x35')](_0x479e24['attributes'],function(_0x2e26b8){var _0x3df4ad={};_0x3df4ad[_0x2e26b8]={'$like':'%'+_0x13eb69[_0x4f2c('0x37')][_0x4f2c('0x44')]+'%'};return _0x3df4ad;})});}_0x479e24=_[_0x4f2c('0x42')]({},_0x479e24,_0x13eb69[_0x4f2c('0x45')]);return _0x5508a4[_0x4f2c('0x8a')](_0x479e24);}})[_0x4f2c('0x29')](function(_0x173fb6){if(_0x173fb6){_0x5b9c18=_0x173fb6[_0x4f2c('0x3c')];if(!_0x13eb69[_0x4f2c('0x37')]['hasOwnProperty'](_0x4f2c('0x3d'))){_0x479e24['limit']=qs[_0x4f2c('0x22')](_0x13eb69[_0x4f2c('0x37')]['limit']);_0x479e24[_0x4f2c('0x24')]=qs['offset'](_0x13eb69[_0x4f2c('0x37')][_0x4f2c('0x24')]);}return _0x5508a4['getAgents'](_0x479e24);}})[_0x4f2c('0x29')](function(_0x42c84b){if(_0x42c84b){return _0x42c84b?{'count':_0x5b9c18,'rows':_0x42c84b}:null;}})[_0x4f2c('0x29')](respondWithResult(_0x32d04c,null))[_0x4f2c('0x4c')](handleError(_0x32d04c,null));};