8c28afc471473cb201f19848c8d2bb5a6b054fdd
[motion2.git] / server / api / faxQueue / faxQueue.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 _0x9f15=['voicePause','interface','sequelize','transaction','each','findOrCreate','forEach','emit','userFaxQueue:save','select','field','tq.TeamId','team_has_fax_queues','join','ut.UserId\x20=\x20?','push','toString','SELECT','every','all','union','value','removeTeams','removeAgents','userFaxQueue:remove','addAgents','omit','spread','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','ejs','fs-extra','lodash','squel','jsforce','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','./faxQueue.socket','register','sendStatus','status','json','offset','undefined','count','limit','set','apply','reject','save','update','then','destroy','get','FaxQueues','UserProfileResource','error','stack','name','index','map','FaxQueue','rawAttributes','fieldName','type','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','order','sort','where','filter','merge','VIRTUAL','options','includeAll','findAll','rows','show','params','keys','include','find','catch','create','body','user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','findOne','UserFaxQueue','nolimit','pick','User','UserId','faxPause','format','%s/%s','SIP','createdAt','updatedAt','getTeams','addTeams','ids','Team','Agents'];(function(_0xe73080,_0x24c56d){var _0x12cbc4=function(_0x1377e2){while(--_0x1377e2){_0xe73080['push'](_0xe73080['shift']());}};_0x12cbc4(++_0x24c56d);}(_0x9f15,0xa5));var _0x59f1=function(_0x54dcad,_0x554f46){_0x54dcad=_0x54dcad-0x0;var _0x537c56=_0x9f15[_0x54dcad];return _0x537c56;};'use strict';var emlformat=require(_0x59f1('0x0'));var rimraf=require(_0x59f1('0x1'));var zipdir=require(_0x59f1('0x2'));var jsonpatch=require(_0x59f1('0x3'));var rp=require('request-promise');var moment=require(_0x59f1('0x4'));var BPromise=require(_0x59f1('0x5'));var Mustache=require(_0x59f1('0x6'));var util=require(_0x59f1('0x7'));var path=require(_0x59f1('0x8'));var sox=require(_0x59f1('0x9'));var csv=require('to-csv');var ejs=require(_0x59f1('0xa'));var fs=require('fs');var fs_extra=require(_0x59f1('0xb'));var _=require(_0x59f1('0xc'));var squel=require(_0x59f1('0xd'));var crypto=require('crypto');var jsforce=require(_0x59f1('0xe'));var deskjs=require(_0x59f1('0xf'));var toCsv=require(_0x59f1('0x10'));var querystring=require(_0x59f1('0x11'));var Papa=require(_0x59f1('0x12'));var Redis=require('ioredis');var authService=require(_0x59f1('0x13'));var qs=require('../../components/parsers/qs');var as=require(_0x59f1('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x59f1('0x15'))(_0x59f1('0x16'));var utils=require(_0x59f1('0x17'));var config=require(_0x59f1('0x18'));var licenseUtil=require(_0x59f1('0x19'));var db=require(_0x59f1('0x1a'))['db'];config['redis']=_[_0x59f1('0x1b')](config[_0x59f1('0x1c')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x59f1('0x1c')]));require(_0x59f1('0x1d'))[_0x59f1('0x1e')](socket);function respondWithStatusCode(_0x4cb7b7,_0x390cfb){_0x390cfb=_0x390cfb||0xcc;return function(_0x398fa5){if(_0x398fa5){return _0x4cb7b7[_0x59f1('0x1f')](_0x390cfb);}return _0x4cb7b7[_0x59f1('0x20')](_0x390cfb)['end']();};}function respondWithResult(_0x255cf8,_0x33cd93){_0x33cd93=_0x33cd93||0xc8;return function(_0x2d00a6){if(_0x2d00a6){return _0x255cf8['status'](_0x33cd93)[_0x59f1('0x21')](_0x2d00a6);}};}function respondWithFilteredResult(_0x14e8f9,_0x257e40){return function(_0x1eded6){if(_0x1eded6){var _0x1f03df=typeof _0x257e40[_0x59f1('0x22')]===_0x59f1('0x23')&&typeof _0x257e40['limit']===_0x59f1('0x23');var _0x1b6cde=_0x1eded6[_0x59f1('0x24')];var _0x46a13b=_0x1f03df?0x0:_0x257e40[_0x59f1('0x22')];var _0x21be2e=_0x1f03df?_0x1eded6['count']:_0x257e40[_0x59f1('0x22')]+_0x257e40[_0x59f1('0x25')];var _0x242cc9;if(_0x21be2e>=_0x1b6cde){_0x21be2e=_0x1b6cde;_0x242cc9=0xc8;}else{_0x242cc9=0xce;}_0x14e8f9[_0x59f1('0x20')](_0x242cc9);return _0x14e8f9[_0x59f1('0x26')]('Content-Range',_0x46a13b+'-'+_0x21be2e+'/'+_0x1b6cde)[_0x59f1('0x21')](_0x1eded6);}return null;};}function patchUpdates(_0x4b7ef4){return function(_0x7927e1){try{jsonpatch[_0x59f1('0x27')](_0x7927e1,_0x4b7ef4,!![]);}catch(_0x217f62){return BPromise[_0x59f1('0x28')](_0x217f62);}return _0x7927e1[_0x59f1('0x29')]();};}function saveUpdates(_0x3c74dc,_0x2ebce9){return function(_0x22384c){if(_0x22384c){return _0x22384c[_0x59f1('0x2a')](_0x3c74dc)[_0x59f1('0x2b')](function(_0x3ce977){return _0x3ce977;});}return null;};}function removeEntity(_0x1478e5,_0x104e64){return function(_0x1494cb){if(_0x1494cb){return _0x1494cb[_0x59f1('0x2c')]()[_0x59f1('0x2b')](function(){var _0x27ab92=_0x1494cb[_0x59f1('0x2d')]({'plain':!![]});var _0x4d7d5e=_0x59f1('0x2e');return db[_0x59f1('0x2f')][_0x59f1('0x2c')]({'where':{'type':_0x4d7d5e,'resourceId':_0x27ab92['id']}})[_0x59f1('0x2b')](function(){return _0x1494cb;});})[_0x59f1('0x2b')](function(){_0x1478e5[_0x59f1('0x20')](0xcc)['end']();});}};}function handleEntityNotFound(_0x32da94,_0x1e4500){return function(_0x154c55){if(!_0x154c55){_0x32da94['sendStatus'](0x194);}return _0x154c55;};}function handleError(_0x2bf544,_0x44cd1b){_0x44cd1b=_0x44cd1b||0x1f4;return function(_0x538530){logger[_0x59f1('0x30')](_0x538530[_0x59f1('0x31')]);if(_0x538530[_0x59f1('0x32')]){delete _0x538530[_0x59f1('0x32')];}_0x2bf544[_0x59f1('0x20')](_0x44cd1b)['send'](_0x538530);};}exports[_0x59f1('0x33')]=function(_0x56d4cb,_0x34b58a){var _0x156c55={},_0x334ed={},_0x43cf4e={'count':0x0,'rows':[]};var _0x4dd4e6=_[_0x59f1('0x34')](db[_0x59f1('0x35')][_0x59f1('0x36')],function(_0x3c0582){return{'name':_0x3c0582[_0x59f1('0x37')],'type':_0x3c0582[_0x59f1('0x38')]['key']};});_0x334ed['model']=_[_0x59f1('0x34')](_0x4dd4e6,_0x59f1('0x32'));_0x334ed['query']=_['keys'](_0x56d4cb[_0x59f1('0x39')]);_0x334ed[_0x59f1('0x3a')]=_[_0x59f1('0x3b')](_0x334ed[_0x59f1('0x3c')],_0x334ed[_0x59f1('0x39')]);_0x156c55[_0x59f1('0x3d')]=_[_0x59f1('0x3b')](_0x334ed[_0x59f1('0x3c')],qs[_0x59f1('0x3e')](_0x56d4cb['query'][_0x59f1('0x3e')]));_0x156c55[_0x59f1('0x3d')]=_0x156c55[_0x59f1('0x3d')][_0x59f1('0x3f')]?_0x156c55[_0x59f1('0x3d')]:_0x334ed[_0x59f1('0x3c')];if(!_0x56d4cb[_0x59f1('0x39')][_0x59f1('0x40')]('nolimit')){_0x156c55['limit']=qs[_0x59f1('0x25')](_0x56d4cb[_0x59f1('0x39')][_0x59f1('0x25')]);_0x156c55[_0x59f1('0x22')]=qs[_0x59f1('0x22')](_0x56d4cb[_0x59f1('0x39')][_0x59f1('0x22')]);}_0x156c55[_0x59f1('0x41')]=qs[_0x59f1('0x42')](_0x56d4cb[_0x59f1('0x39')][_0x59f1('0x42')]);_0x156c55[_0x59f1('0x43')]=qs[_0x59f1('0x3a')](_['pick'](_0x56d4cb[_0x59f1('0x39')],_0x334ed[_0x59f1('0x3a')]),_0x4dd4e6);if(_0x56d4cb[_0x59f1('0x39')][_0x59f1('0x44')]){_0x156c55[_0x59f1('0x43')]=_[_0x59f1('0x45')](_0x156c55[_0x59f1('0x43')],{'$or':_[_0x59f1('0x34')](_0x4dd4e6,function(_0x3e9435){if(_0x3e9435['type']!==_0x59f1('0x46')){var _0x37de29={};_0x37de29[_0x3e9435[_0x59f1('0x32')]]={'$like':'%'+_0x56d4cb[_0x59f1('0x39')][_0x59f1('0x44')]+'%'};return _0x37de29;}})});}_0x156c55=_[_0x59f1('0x45')]({},_0x156c55,_0x56d4cb[_0x59f1('0x47')]);var _0x365cb3={'where':_0x156c55[_0x59f1('0x43')]};return db[_0x59f1('0x35')][_0x59f1('0x24')](_0x365cb3)[_0x59f1('0x2b')](function(_0x5b04a4){_0x43cf4e[_0x59f1('0x24')]=_0x5b04a4;if(_0x56d4cb[_0x59f1('0x39')][_0x59f1('0x48')]){_0x156c55['include']=[{'all':!![]}];}return db[_0x59f1('0x35')][_0x59f1('0x49')](_0x156c55);})[_0x59f1('0x2b')](function(_0x2d4369){_0x43cf4e[_0x59f1('0x4a')]=_0x2d4369;return _0x43cf4e;})[_0x59f1('0x2b')](respondWithFilteredResult(_0x34b58a,_0x156c55))['catch'](handleError(_0x34b58a,null));};exports[_0x59f1('0x4b')]=function(_0x58c182,_0x35662a){var _0x447b2a={'raw':!![],'where':{'id':_0x58c182[_0x59f1('0x4c')]['id']}},_0x44f836={};_0x44f836[_0x59f1('0x3c')]=_[_0x59f1('0x4d')](db[_0x59f1('0x35')][_0x59f1('0x36')]);_0x44f836[_0x59f1('0x39')]=_[_0x59f1('0x4d')](_0x58c182[_0x59f1('0x39')]);_0x44f836['filters']=_[_0x59f1('0x3b')](_0x44f836['model'],_0x44f836['query']);_0x447b2a[_0x59f1('0x3d')]=_[_0x59f1('0x3b')](_0x44f836[_0x59f1('0x3c')],qs[_0x59f1('0x3e')](_0x58c182[_0x59f1('0x39')]['fields']));_0x447b2a[_0x59f1('0x3d')]=_0x447b2a[_0x59f1('0x3d')][_0x59f1('0x3f')]?_0x447b2a[_0x59f1('0x3d')]:_0x44f836[_0x59f1('0x3c')];if(_0x58c182[_0x59f1('0x39')][_0x59f1('0x48')]){_0x447b2a[_0x59f1('0x4e')]=[{'all':!![]}];}_0x447b2a=_[_0x59f1('0x45')]({},_0x447b2a,_0x58c182[_0x59f1('0x47')]);return db['FaxQueue'][_0x59f1('0x4f')](_0x447b2a)[_0x59f1('0x2b')](handleEntityNotFound(_0x35662a,null))[_0x59f1('0x2b')](respondWithResult(_0x35662a,null))[_0x59f1('0x50')](handleError(_0x35662a,null));};exports[_0x59f1('0x51')]=function(_0x3f9fd2,_0x58c801){return db[_0x59f1('0x35')][_0x59f1('0x51')](_0x3f9fd2[_0x59f1('0x52')],{})[_0x59f1('0x2b')](function(_0xcc6a14){var _0x362b7d=_0x3f9fd2[_0x59f1('0x53')]['get']({'plain':!![]});if(!_0x362b7d)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x362b7d[_0x59f1('0x54')]===_0x59f1('0x53')){var _0x103f4a=_0xcc6a14['get']({'plain':!![]});var _0x39fed1=_0x59f1('0x2e');return db[_0x59f1('0x55')]['find']({'where':{'name':_0x39fed1,'userProfileId':_0x362b7d[_0x59f1('0x56')]},'raw':!![]})['then'](function(_0x4e23fb){if(_0x4e23fb&&_0x4e23fb[_0x59f1('0x57')]===0x0){return db[_0x59f1('0x2f')]['create']({'name':_0x103f4a[_0x59f1('0x32')],'resourceId':_0x103f4a['id'],'type':_0x4e23fb['name'],'sectionId':_0x4e23fb['id']},{})[_0x59f1('0x2b')](function(){return _0xcc6a14;});}else{return _0xcc6a14;}})[_0x59f1('0x50')](function(_0x211c27){logger[_0x59f1('0x30')](_0x59f1('0x58'),_0x211c27);throw _0x211c27;});}return _0xcc6a14;})[_0x59f1('0x2b')](respondWithResult(_0x58c801,0xc9))[_0x59f1('0x50')](handleError(_0x58c801,null));};exports[_0x59f1('0x2a')]=function(_0x544cd0,_0x3ede88){if(_0x544cd0[_0x59f1('0x52')]['id']){delete _0x544cd0[_0x59f1('0x52')]['id'];}return db['FaxQueue'][_0x59f1('0x4f')]({'where':{'id':_0x544cd0['params']['id']}})[_0x59f1('0x2b')](handleEntityNotFound(_0x3ede88,null))[_0x59f1('0x2b')](saveUpdates(_0x544cd0['body'],null))[_0x59f1('0x2b')](respondWithResult(_0x3ede88,null))[_0x59f1('0x50')](handleError(_0x3ede88,null));};exports[_0x59f1('0x2c')]=function(_0x5e8c1c,_0x408e93){return db['FaxQueue']['find']({'where':{'id':_0x5e8c1c[_0x59f1('0x4c')]['id']}})[_0x59f1('0x2b')](handleEntityNotFound(_0x408e93,null))['then'](removeEntity(_0x408e93,null))['catch'](handleError(_0x408e93,null));};exports['describe']=function(_0x200f47,_0x15b523){return db[_0x59f1('0x35')][_0x59f1('0x59')]()[_0x59f1('0x2b')](respondWithResult(_0x15b523,null))[_0x59f1('0x50')](handleError(_0x15b523,null));};exports['getMembers']=function(_0x1500a0,_0x55add8,_0x580952){var _0x433250={'raw':!![],'where':{}},_0x11c13c={},_0x5756ce;return db[_0x59f1('0x35')][_0x59f1('0x5a')]({'where':{'id':_0x1500a0[_0x59f1('0x4c')]['id']}})[_0x59f1('0x2b')](handleEntityNotFound(_0x55add8,null))[_0x59f1('0x2b')](function(_0x51f96b){if(_0x51f96b){_0x5756ce=_0x51f96b['get']({'plain':!![]});_0x11c13c['model']=_[_0x59f1('0x4d')](db[_0x59f1('0x5b')][_0x59f1('0x36')]);_0x11c13c[_0x59f1('0x39')]=_['keys'](_0x1500a0[_0x59f1('0x39')]);_0x11c13c['filters']=_['intersection'](_0x11c13c[_0x59f1('0x3c')],_0x11c13c[_0x59f1('0x39')]);_0x433250[_0x59f1('0x3d')]=_[_0x59f1('0x3b')](_0x11c13c[_0x59f1('0x3c')],qs['fields'](_0x1500a0[_0x59f1('0x39')]['fields']));_0x433250['attributes']=_0x433250[_0x59f1('0x3d')][_0x59f1('0x3f')]?_0x433250[_0x59f1('0x3d')]:_0x11c13c[_0x59f1('0x3c')];if(!_0x1500a0['query'][_0x59f1('0x40')](_0x59f1('0x5c'))){_0x433250[_0x59f1('0x25')]=qs[_0x59f1('0x25')](_0x1500a0['query']['limit']);_0x433250['offset']=qs[_0x59f1('0x22')](_0x1500a0[_0x59f1('0x39')][_0x59f1('0x22')]);}_0x433250['order']=qs[_0x59f1('0x42')](_0x1500a0['query'][_0x59f1('0x42')]);_0x433250[_0x59f1('0x43')]=qs['filters'](_[_0x59f1('0x5d')](_0x1500a0['query'],_0x11c13c['filters']));_0x433250[_0x59f1('0x43')]['FaxQueueId']=_0x51f96b['id'];if(_0x1500a0[_0x59f1('0x39')][_0x59f1('0x44')]){_0x433250[_0x59f1('0x43')]=_['merge'](_0x433250['where'],{'$or':_[_0x59f1('0x34')](_0x433250['attributes'],function(_0x3e94a1){var _0x3969ba={};_0x3969ba[_0x3e94a1]={'$like':'%'+_0x1500a0[_0x59f1('0x39')][_0x59f1('0x44')]+'%'};return _0x3969ba;})});}_0x433250=_[_0x59f1('0x45')]({},_0x433250,_0x1500a0['options']);return db['UserFaxQueue'][_0x59f1('0x49')](_0x433250);}})[_0x59f1('0x2b')](function(_0x4cc052){if(_0x4cc052){return db[_0x59f1('0x5e')]['findAndCountAll']({'where':{'id':_[_0x59f1('0x34')](_0x4cc052,_0x59f1('0x5f')),'role':'agent'},'attributes':['id',_0x59f1('0x32'),_0x59f1('0x60'),'updatedAt','createdAt']});}})[_0x59f1('0x2b')](function(_0x18e44b){if(_0x18e44b){return{'count':_0x18e44b['count'],'rows':_[_0x59f1('0x34')](_0x18e44b[_0x59f1('0x4a')],function(_0x5e0f1e){return{'membername':_0x5e0f1e[_0x59f1('0x32')],'UserId':_0x5e0f1e['id'],'queue_name':_0x5756ce[_0x59f1('0x32')],'FaxQueueId':_0x5756ce['id'],'interface':util[_0x59f1('0x61')](_0x59f1('0x62'),_0x59f1('0x63'),_0x5e0f1e['name']),'penalty':0x0,'paused':_0x5e0f1e[_0x59f1('0x60')],'createdAt':_0x5e0f1e[_0x59f1('0x64')],'updatedAt':_0x5e0f1e[_0x59f1('0x65')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x59f1('0x2b')](respondWithFilteredResult(_0x55add8,_0x433250))[_0x59f1('0x50')](handleError(_0x55add8,null));};exports['getTeams']=function(_0x80d7e7,_0x2b060e,_0x4f403b){var _0x37e4ff={};var _0x179144={};var _0x454d16;var _0x378f5e;return db[_0x59f1('0x35')][_0x59f1('0x5a')]({'where':{'id':_0x80d7e7[_0x59f1('0x4c')]['id']}})[_0x59f1('0x2b')](handleEntityNotFound(_0x2b060e,null))[_0x59f1('0x2b')](function(_0x4bd4d4){if(_0x4bd4d4){_0x454d16=_0x4bd4d4;_0x179144[_0x59f1('0x3c')]=_[_0x59f1('0x4d')](db['Team']['rawAttributes']);_0x179144[_0x59f1('0x39')]=_[_0x59f1('0x4d')](_0x80d7e7[_0x59f1('0x39')]);_0x179144['filters']=_[_0x59f1('0x3b')](_0x179144[_0x59f1('0x3c')],_0x179144[_0x59f1('0x39')]);_0x37e4ff['attributes']=_[_0x59f1('0x3b')](_0x179144['model'],qs['fields'](_0x80d7e7[_0x59f1('0x39')][_0x59f1('0x3e')]));_0x37e4ff[_0x59f1('0x3d')]=_0x37e4ff[_0x59f1('0x3d')][_0x59f1('0x3f')]?_0x37e4ff[_0x59f1('0x3d')]:_0x179144[_0x59f1('0x3c')];_0x37e4ff[_0x59f1('0x41')]=qs['sort'](_0x80d7e7[_0x59f1('0x39')]['sort']);_0x37e4ff['where']=qs['filters'](_[_0x59f1('0x5d')](_0x80d7e7[_0x59f1('0x39')],_0x179144[_0x59f1('0x3a')]));if(_0x80d7e7[_0x59f1('0x39')][_0x59f1('0x44')]){_0x37e4ff['where']=_['merge'](_0x37e4ff[_0x59f1('0x43')],{'$or':_[_0x59f1('0x34')](_0x37e4ff['attributes'],function(_0x17aa20){var _0x5a363d={};_0x5a363d[_0x17aa20]={'$like':'%'+_0x80d7e7[_0x59f1('0x39')]['filter']+'%'};return _0x5a363d;})});}_0x37e4ff=_[_0x59f1('0x45')]({},_0x37e4ff,_0x80d7e7[_0x59f1('0x47')]);return _0x454d16[_0x59f1('0x66')](_0x37e4ff);}})[_0x59f1('0x2b')](function(_0x2c1a05){if(_0x2c1a05){_0x378f5e=_0x2c1a05[_0x59f1('0x3f')];if(!_0x80d7e7[_0x59f1('0x39')][_0x59f1('0x40')](_0x59f1('0x5c'))){_0x37e4ff[_0x59f1('0x25')]=qs[_0x59f1('0x25')](_0x80d7e7[_0x59f1('0x39')][_0x59f1('0x25')]);_0x37e4ff[_0x59f1('0x22')]=qs[_0x59f1('0x22')](_0x80d7e7[_0x59f1('0x39')]['offset']);}return _0x454d16[_0x59f1('0x66')](_0x37e4ff);}})[_0x59f1('0x2b')](function(_0x6a2d22){if(_0x6a2d22){return _0x6a2d22?{'count':_0x378f5e,'rows':_0x6a2d22}:null;}})[_0x59f1('0x2b')](respondWithResult(_0x2b060e,null))[_0x59f1('0x50')](handleError(_0x2b060e,null));};exports[_0x59f1('0x67')]=function(_0xcc057d,_0x465a65,_0x3ddcc5){var _0x26b534=_0xcc057d['body'][_0x59f1('0x68')];return db[_0x59f1('0x69')]['findAll']({'where':{'id':_0x26b534},'attributes':['id'],'include':[{'model':db[_0x59f1('0x5e')],'as':_0x59f1('0x6a'),'attributes':['id',_0x59f1('0x32'),'online',_0x59f1('0x6b'),_0x59f1('0x6c')],'raw':!![]}]})[_0x59f1('0x2b')](function(_0x18288b){if(_0x18288b){var _0x59b6dc=_['flatMap'](_0x18288b,function(_0x32905c){var _0x123fec=_0x32905c[_0x59f1('0x2d')]({'plain':!![]});return _0x123fec['Agents'];});return db[_0x59f1('0x35')][_0x59f1('0x4f')]({'where':{'id':_0xcc057d[_0x59f1('0x4c')]['id']}})[_0x59f1('0x2b')](function(_0x165df1){return db[_0x59f1('0x6d')][_0x59f1('0x6e')](function(_0x337ddd){return _0x165df1[_0x59f1('0x67')](_0x26b534,{'transaction':_0x337ddd})[_0x59f1('0x2b')](function(){return BPromise[_0x59f1('0x6f')](_0x59b6dc,function(_0x4d0599){return db[_0x59f1('0x5b')][_0x59f1('0x70')]({'where':{'UserId':_0x4d0599['id'],'FaxQueueId':_0xcc057d[_0x59f1('0x4c')]['id']},'transaction':_0x337ddd});});})[_0x59f1('0x2b')](function(){_0x59b6dc[_0x59f1('0x71')](function(_0x5d0f80){socket[_0x59f1('0x72')](_0x59f1('0x73'),{'UserId':_0x5d0f80['id'],'FaxQueueId':_0x165df1['id']});});});});});}})[_0x59f1('0x2b')](respondWithStatusCode(_0x465a65,null))[_0x59f1('0x50')](handleError(_0x465a65,null));};exports['removeTeams']=function(_0x515f3e,_0x16090e,_0x55f886){return db[_0x59f1('0x69')][_0x59f1('0x49')]({'where':{'id':_0x515f3e[_0x59f1('0x39')][_0x59f1('0x68')]},'attributes':['id'],'include':[{'model':db[_0x59f1('0x5e')],'as':_0x59f1('0x6a'),'attributes':['id'],'raw':!![]}]})[_0x59f1('0x2b')](handleEntityNotFound(_0x16090e,null))['then'](function(_0x4e4988){var _0x482cf6=_['map'](_0x4e4988,'id');var _0x503864=[];var _0x458a9a=[];var _0x2cd15b=squel[_0x59f1('0x74')]();_0x2cd15b[_0x59f1('0x75')](_0x59f1('0x76'))['from'](_0x59f1('0x77'),'tq')[_0x59f1('0x78')]('user_has_teams','ut','ut.TeamId\x20=\x20tq.TeamId')[_0x59f1('0x43')]('FaxQueueId\x20=\x20?',_0x515f3e[_0x59f1('0x4c')]['id']);for(var _0x14fee0=0x0;_0x14fee0<_0x4e4988[_0x59f1('0x3f')];_0x14fee0+=0x1){let _0x30b716=_0x4e4988[_0x14fee0];for(var _0x19d53b=0x0;_0x19d53b<_0x30b716[_0x59f1('0x6a')][_0x59f1('0x3f')];_0x19d53b+=0x1){let _0xd48fd8=_0x30b716['Agents'][_0x19d53b];var _0x573861=_0x2cd15b['clone']();_0x573861['where'](_0x59f1('0x79'),_0xd48fd8['id']);_0x458a9a[_0x59f1('0x7a')](db['sequelize'][_0x59f1('0x39')](_0x573861[_0x59f1('0x7b')](),{'type':db[_0x59f1('0x6d')]['QueryTypes'][_0x59f1('0x7c')]})[_0x59f1('0x2b')](function(_0x451a8e){if(_0x451a8e[_0x59f1('0x3f')]===0x1){return _0xd48fd8['id'];}else{var _0x1c7777=_[_0x59f1('0x7d')](_[_0x59f1('0x34')](_0x451a8e,'TeamId'),function(_0x39b6b2){return _['includes'](_0x482cf6,_0x39b6b2);});if(_0x1c7777){return _0xd48fd8['id'];}}}));}}return BPromise[_0x59f1('0x7e')](_0x458a9a)[_0x59f1('0x2b')](function(_0x47d432){_0x503864=_(_0x503864)[_0x59f1('0x7f')](_0x47d432)['compact']()[_0x59f1('0x80')]();return db['FaxQueue'][_0x59f1('0x4f')]({'where':{'id':_0x515f3e[_0x59f1('0x4c')]['id']}})[_0x59f1('0x2b')](function(_0x552e15){return db[_0x59f1('0x6d')][_0x59f1('0x6e')](function(_0x5b4500){return _0x552e15[_0x59f1('0x81')](_0x515f3e[_0x59f1('0x39')][_0x59f1('0x68')],{'transaction':_0x5b4500})['then'](function(){if(!_['isEmpty'](_0x503864)){return _0x552e15[_0x59f1('0x82')](_0x503864,{'transaction':_0x5b4500});}})['then'](function(){_0x503864['forEach'](function(_0x62a629){socket[_0x59f1('0x72')](_0x59f1('0x83'),{'UserId':_0x62a629,'FaxQueueId':_0x552e15['id']});});});});});});})[_0x59f1('0x2b')](respondWithStatusCode(_0x16090e,null))[_0x59f1('0x50')](handleError(_0x16090e,null));};exports[_0x59f1('0x84')]=function(_0xee3860,_0x2a0492,_0x4c50e3){return db[_0x59f1('0x35')][_0x59f1('0x4f')]({'where':{'id':_0xee3860[_0x59f1('0x4c')]['id']}})[_0x59f1('0x2b')](handleEntityNotFound(_0x2a0492,null))[_0x59f1('0x2b')](function(_0x313210){if(_0x313210){return _0x313210[_0x59f1('0x84')](_0xee3860['body'][_0x59f1('0x68')],_[_0x59f1('0x85')](_0xee3860[_0x59f1('0x52')],['ids','id'])||{})[_0x59f1('0x86')](function(_0x322ee7){for(var _0x2c0441=0x0;_0x2c0441<_0xee3860[_0x59f1('0x52')]['ids'][_0x59f1('0x3f')];_0x2c0441+=0x1){socket['emit'](_0x59f1('0x73'),{'UserId':Number(_0xee3860[_0x59f1('0x52')]['ids'][_0x2c0441]),'FaxQueueId':Number(_0xee3860[_0x59f1('0x4c')]['id'])});}return _0x322ee7;});}})[_0x59f1('0x2b')](respondWithResult(_0x2a0492,null))['catch'](handleError(_0x2a0492,null));};exports[_0x59f1('0x82')]=function(_0x3bc61c,_0x4962db,_0x5bca88){return db[_0x59f1('0x35')]['find']({'where':{'id':_0x3bc61c[_0x59f1('0x4c')]['id']}})[_0x59f1('0x2b')](handleEntityNotFound(_0x4962db,null))[_0x59f1('0x2b')](function(_0x2c2065){if(_0x2c2065){return _0x2c2065[_0x59f1('0x82')](_0x3bc61c[_0x59f1('0x39')][_0x59f1('0x68')])['then'](function(){if(_['isArray'](_0x3bc61c[_0x59f1('0x39')][_0x59f1('0x68')])){for(var _0x14af74=0x0;_0x14af74<_0x3bc61c[_0x59f1('0x39')][_0x59f1('0x68')][_0x59f1('0x3f')];_0x14af74+=0x1){socket[_0x59f1('0x72')]('userFaxQueue:remove',{'UserId':Number(_0x3bc61c['query'][_0x59f1('0x68')][_0x14af74]),'FaxQueueId':Number(_0x3bc61c[_0x59f1('0x4c')]['id'])});}}else{socket[_0x59f1('0x72')](_0x59f1('0x83'),{'UserId':Number(_0x3bc61c[_0x59f1('0x39')][_0x59f1('0x68')]),'FaxQueueId':Number(_0x3bc61c[_0x59f1('0x4c')]['id'])});}});}})[_0x59f1('0x2b')](respondWithStatusCode(_0x4962db,null))[_0x59f1('0x50')](handleError(_0x4962db,null));};exports[_0x59f1('0x87')]=function(_0x43a4ac,_0x2ed924,_0x50b82c){var _0x48aaa8={};var _0x57787e={};var _0x2a405a;var _0xcedbe9;return db[_0x59f1('0x35')][_0x59f1('0x5a')]({'where':{'id':_0x43a4ac[_0x59f1('0x4c')]['id']}})[_0x59f1('0x2b')](handleEntityNotFound(_0x2ed924,null))[_0x59f1('0x2b')](function(_0x4a0e62){if(_0x4a0e62){_0x2a405a=_0x4a0e62;_0x57787e[_0x59f1('0x3c')]=_['keys'](db[_0x59f1('0x5e')]['rawAttributes']);_0x57787e[_0x59f1('0x39')]=_[_0x59f1('0x4d')](_0x43a4ac[_0x59f1('0x39')]);_0x57787e[_0x59f1('0x3a')]=_[_0x59f1('0x3b')](_0x57787e[_0x59f1('0x3c')],_0x57787e[_0x59f1('0x39')]);_0x48aaa8[_0x59f1('0x3d')]=_[_0x59f1('0x3b')](_0x57787e[_0x59f1('0x3c')],qs[_0x59f1('0x3e')](_0x43a4ac[_0x59f1('0x39')][_0x59f1('0x3e')]));_0x48aaa8[_0x59f1('0x3d')]=_0x48aaa8[_0x59f1('0x3d')][_0x59f1('0x3f')]?_0x48aaa8[_0x59f1('0x3d')]:_0x57787e[_0x59f1('0x3c')];_0x48aaa8[_0x59f1('0x41')]=qs[_0x59f1('0x42')](_0x43a4ac[_0x59f1('0x39')]['sort']);_0x48aaa8[_0x59f1('0x43')]=qs[_0x59f1('0x3a')](_[_0x59f1('0x5d')](_0x43a4ac[_0x59f1('0x39')],_0x57787e[_0x59f1('0x3a')]));if(_0x43a4ac[_0x59f1('0x39')][_0x59f1('0x44')]){_0x48aaa8['where']=_['merge'](_0x48aaa8[_0x59f1('0x43')],{'$or':_[_0x59f1('0x34')](_0x48aaa8[_0x59f1('0x3d')],function(_0x19513e){var _0x97299c={};_0x97299c[_0x19513e]={'$like':'%'+_0x43a4ac[_0x59f1('0x39')]['filter']+'%'};return _0x97299c;})});}_0x48aaa8=_['merge']({},_0x48aaa8,_0x43a4ac[_0x59f1('0x47')]);return _0x2a405a[_0x59f1('0x87')](_0x48aaa8);}})['then'](function(_0x2c626c){if(_0x2c626c){_0xcedbe9=_0x2c626c[_0x59f1('0x3f')];if(!_0x43a4ac[_0x59f1('0x39')][_0x59f1('0x40')](_0x59f1('0x5c'))){_0x48aaa8[_0x59f1('0x25')]=qs[_0x59f1('0x25')](_0x43a4ac[_0x59f1('0x39')][_0x59f1('0x25')]);_0x48aaa8['offset']=qs[_0x59f1('0x22')](_0x43a4ac[_0x59f1('0x39')][_0x59f1('0x22')]);}return _0x2a405a[_0x59f1('0x87')](_0x48aaa8);}})['then'](function(_0x4334b2){if(_0x4334b2){return _0x4334b2?{'count':_0xcedbe9,'rows':_0x4334b2}:null;}})[_0x59f1('0x2b')](respondWithResult(_0x2ed924,null))[_0x59f1('0x50')](handleError(_0x2ed924,null));};