Built motion from commit (unavailable).|2.5.7
[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 _0x9f48=['includeAll','include','catch','params','rawAttributes','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','describe','getMembers','findOne','nolimit','pick','FaxQueueId','findAll','agent','faxPause','updatedAt','createdAt','rows','format','%s/%s','getTeams','hasOwnProperty','ids','Team','Agents','voicePause','interface','flatMap','sequelize','transaction','addTeams','each','UserFaxQueue','findOrCreate','forEach','userFaxQueue:save','User','select','field','from','team_has_fax_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','FaxQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','toString','SELECT','every','TeamId','includes','all','union','compact','value','removeTeams','removeAgents','addAgents','omit','spread','emit','isArray','userFaxQueue:remove','getAgents','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','ejs','lodash','squel','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./faxQueue.socket','register','sendStatus','status','count','offset','limit','set','Content-Range','json','apply','reject','save','update','then','get','FaxQueues','destroy','end','stack','name','send','map','FaxQueue','key','model','query','keys','filters','intersection','fields','attributes','length','order','sort','where','filter','merge','VIRTUAL','options'];(function(_0x32e38e,_0x34d0e8){var _0x38de02=function(_0x1c0c26){while(--_0x1c0c26){_0x32e38e['push'](_0x32e38e['shift']());}};_0x38de02(++_0x34d0e8);}(_0x9f48,0x1ee));var _0x89f4=function(_0x46344f,_0x5c0b71){_0x46344f=_0x46344f-0x0;var _0x1c9fc4=_0x9f48[_0x46344f];return _0x1c9fc4;};'use strict';var pdf=require(_0x89f4('0x0'));var emlformat=require(_0x89f4('0x1'));var rimraf=require(_0x89f4('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x89f4('0x3'));var rp=require(_0x89f4('0x4'));var moment=require(_0x89f4('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x89f4('0x6'));var util=require('util');var path=require(_0x89f4('0x7'));var sox=require(_0x89f4('0x8'));var csv=require(_0x89f4('0x9'));var ejs=require(_0x89f4('0xa'));var fs=require('fs');var _=require(_0x89f4('0xb'));var squel=require(_0x89f4('0xc'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x89f4('0x9'));var querystring=require(_0x89f4('0xd'));var Papa=require('papaparse');var Redis=require(_0x89f4('0xe'));var authService=require('../../components/auth/service');var qs=require(_0x89f4('0xf'));var as=require(_0x89f4('0x10'));var hardwareService=require(_0x89f4('0x11'));var logger=require(_0x89f4('0x12'))(_0x89f4('0x13'));var utils=require(_0x89f4('0x14'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x89f4('0x15'))['db'];config[_0x89f4('0x16')]=_[_0x89f4('0x17')](config[_0x89f4('0x16')],{'host':_0x89f4('0x18'),'port':0x18eb});var socket=require(_0x89f4('0x19'))(new Redis(config[_0x89f4('0x16')]));require(_0x89f4('0x1a'))[_0x89f4('0x1b')](socket);function respondWithStatusCode(_0x459657,_0x43d10a){_0x43d10a=_0x43d10a||0xcc;return function(_0x1b33c4){if(_0x1b33c4){return _0x459657[_0x89f4('0x1c')](_0x43d10a);}return _0x459657[_0x89f4('0x1d')](_0x43d10a)['end']();};}function respondWithResult(_0x4b7ad7,_0x2ee292){_0x2ee292=_0x2ee292||0xc8;return function(_0x394436){if(_0x394436){return _0x4b7ad7[_0x89f4('0x1d')](_0x2ee292)['json'](_0x394436);}};}function respondWithFilteredResult(_0x41b8cc,_0xb80d9b){return function(_0x47e88f){if(_0x47e88f){var _0x17891d=_0x47e88f[_0x89f4('0x1e')],_0x4c2007=_0xb80d9b[_0x89f4('0x1f')],_0x4f80f5=_0xb80d9b['offset']+_0xb80d9b[_0x89f4('0x20')],_0x4ddee5;if(_0x4f80f5>=_0x17891d){_0x4f80f5=_0x17891d;_0x4ddee5=0xc8;}else{_0x4ddee5=0xce;}_0x41b8cc[_0x89f4('0x1d')](_0x4ddee5);return _0x41b8cc[_0x89f4('0x21')](_0x89f4('0x22'),_0x4c2007+'-'+_0x4f80f5+'/'+_0x17891d)[_0x89f4('0x23')](_0x47e88f);}return null;};}function patchUpdates(_0x99365b){return function(_0x330465){try{jsonpatch[_0x89f4('0x24')](_0x330465,_0x99365b,!![]);}catch(_0x50ec4b){return BPromise[_0x89f4('0x25')](_0x50ec4b);}return _0x330465[_0x89f4('0x26')]();};}function saveUpdates(_0x2371c3,_0x556bb0){return function(_0x216600){if(_0x216600){return _0x216600[_0x89f4('0x27')](_0x2371c3)[_0x89f4('0x28')](function(_0x2fa8de){return _0x2fa8de;});}return null;};}function removeEntity(_0x114c8f,_0x33e6e3){return function(_0x9f7cdb){if(_0x9f7cdb){return _0x9f7cdb['destroy']()[_0x89f4('0x28')](function(){var _0x41903f=_0x9f7cdb[_0x89f4('0x29')]({'plain':!![]});var _0x5143e1=_0x89f4('0x2a');return db['UserProfileResource'][_0x89f4('0x2b')]({'where':{'type':_0x5143e1,'resourceId':_0x41903f['id']}})[_0x89f4('0x28')](function(){return _0x9f7cdb;});})['then'](function(){_0x114c8f['status'](0xcc)[_0x89f4('0x2c')]();});}};}function handleEntityNotFound(_0x7d132d,_0x269fb0){return function(_0x16785b){if(!_0x16785b){_0x7d132d[_0x89f4('0x1c')](0x194);}return _0x16785b;};}function handleError(_0x19a203,_0x52a404){_0x52a404=_0x52a404||0x1f4;return function(_0x3081df){logger['error'](_0x3081df[_0x89f4('0x2d')]);if(_0x3081df['name']){delete _0x3081df[_0x89f4('0x2e')];}_0x19a203['status'](_0x52a404)[_0x89f4('0x2f')](_0x3081df);};}exports['index']=function(_0x5db4bf,_0x73885c){var _0x4b1946={},_0x5106c4={},_0x5c5b7d={'count':0x0,'rows':[]};var _0xbf2b7f=_[_0x89f4('0x30')](db[_0x89f4('0x31')]['rawAttributes'],function(_0x1d9611){return{'name':_0x1d9611['fieldName'],'type':_0x1d9611['type'][_0x89f4('0x32')]};});_0x5106c4[_0x89f4('0x33')]=_['map'](_0xbf2b7f,_0x89f4('0x2e'));_0x5106c4[_0x89f4('0x34')]=_[_0x89f4('0x35')](_0x5db4bf['query']);_0x5106c4[_0x89f4('0x36')]=_[_0x89f4('0x37')](_0x5106c4[_0x89f4('0x33')],_0x5106c4[_0x89f4('0x34')]);_0x4b1946['attributes']=_[_0x89f4('0x37')](_0x5106c4['model'],qs[_0x89f4('0x38')](_0x5db4bf['query'][_0x89f4('0x38')]));_0x4b1946[_0x89f4('0x39')]=_0x4b1946['attributes'][_0x89f4('0x3a')]?_0x4b1946[_0x89f4('0x39')]:_0x5106c4[_0x89f4('0x33')];if(!_0x5db4bf[_0x89f4('0x34')]['hasOwnProperty']('nolimit')){_0x4b1946[_0x89f4('0x20')]=qs[_0x89f4('0x20')](_0x5db4bf[_0x89f4('0x34')][_0x89f4('0x20')]);_0x4b1946[_0x89f4('0x1f')]=qs[_0x89f4('0x1f')](_0x5db4bf[_0x89f4('0x34')][_0x89f4('0x1f')]);}_0x4b1946[_0x89f4('0x3b')]=qs[_0x89f4('0x3c')](_0x5db4bf[_0x89f4('0x34')][_0x89f4('0x3c')]);_0x4b1946[_0x89f4('0x3d')]=qs['filters'](_['pick'](_0x5db4bf[_0x89f4('0x34')],_0x5106c4[_0x89f4('0x36')]),_0xbf2b7f);if(_0x5db4bf[_0x89f4('0x34')][_0x89f4('0x3e')]){_0x4b1946['where']=_[_0x89f4('0x3f')](_0x4b1946['where'],{'$or':_[_0x89f4('0x30')](_0xbf2b7f,function(_0x2c91fc){if(_0x2c91fc['type']!==_0x89f4('0x40')){var _0x932e7={};_0x932e7[_0x2c91fc[_0x89f4('0x2e')]]={'$like':'%'+_0x5db4bf['query'][_0x89f4('0x3e')]+'%'};return _0x932e7;}})});}_0x4b1946=_[_0x89f4('0x3f')]({},_0x4b1946,_0x5db4bf[_0x89f4('0x41')]);var _0x37cf85={'where':_0x4b1946[_0x89f4('0x3d')]};return db[_0x89f4('0x31')][_0x89f4('0x1e')](_0x37cf85)[_0x89f4('0x28')](function(_0x192202){_0x5c5b7d[_0x89f4('0x1e')]=_0x192202;if(_0x5db4bf['query'][_0x89f4('0x42')]){_0x4b1946[_0x89f4('0x43')]=[{'all':!![]}];}return db['FaxQueue']['findAll'](_0x4b1946);})[_0x89f4('0x28')](function(_0x4cf74b){_0x5c5b7d['rows']=_0x4cf74b;return _0x5c5b7d;})['then'](respondWithFilteredResult(_0x73885c,_0x4b1946))[_0x89f4('0x44')](handleError(_0x73885c,null));};exports['show']=function(_0x189d34,_0x433aed){var _0x4dc206={'raw':!![],'where':{'id':_0x189d34[_0x89f4('0x45')]['id']}},_0x33b21d={};_0x33b21d[_0x89f4('0x33')]=_['keys'](db[_0x89f4('0x31')][_0x89f4('0x46')]);_0x33b21d[_0x89f4('0x34')]=_[_0x89f4('0x35')](_0x189d34[_0x89f4('0x34')]);_0x33b21d[_0x89f4('0x36')]=_[_0x89f4('0x37')](_0x33b21d[_0x89f4('0x33')],_0x33b21d[_0x89f4('0x34')]);_0x4dc206[_0x89f4('0x39')]=_['intersection'](_0x33b21d['model'],qs[_0x89f4('0x38')](_0x189d34[_0x89f4('0x34')][_0x89f4('0x38')]));_0x4dc206[_0x89f4('0x39')]=_0x4dc206[_0x89f4('0x39')]['length']?_0x4dc206['attributes']:_0x33b21d[_0x89f4('0x33')];if(_0x189d34['query']['includeAll']){_0x4dc206[_0x89f4('0x43')]=[{'all':!![]}];}_0x4dc206=_[_0x89f4('0x3f')]({},_0x4dc206,_0x189d34[_0x89f4('0x41')]);return db[_0x89f4('0x31')][_0x89f4('0x47')](_0x4dc206)['then'](handleEntityNotFound(_0x433aed,null))[_0x89f4('0x28')](respondWithResult(_0x433aed,null))[_0x89f4('0x44')](handleError(_0x433aed,null));};exports['create']=function(_0x512aff,_0x46f62a){return db[_0x89f4('0x31')][_0x89f4('0x48')](_0x512aff['body'],{})[_0x89f4('0x28')](function(_0xa1ff16){var _0x5808c5=_0x512aff[_0x89f4('0x49')]['get']({'plain':!![]});if(!_0x5808c5)throw new Error(_0x89f4('0x4a'));if(_0x5808c5[_0x89f4('0x4b')]===_0x89f4('0x49')){var _0x257728=_0xa1ff16[_0x89f4('0x29')]({'plain':!![]});var _0x4db189='FaxQueues';return db['UserProfileSection'][_0x89f4('0x47')]({'where':{'name':_0x4db189,'userProfileId':_0x5808c5['userProfileId']},'raw':!![]})[_0x89f4('0x28')](function(_0xdcc407){if(_0xdcc407&&_0xdcc407[_0x89f4('0x4c')]===0x0){return db[_0x89f4('0x4d')]['create']({'name':_0x257728[_0x89f4('0x2e')],'resourceId':_0x257728['id'],'type':_0xdcc407[_0x89f4('0x2e')],'sectionId':_0xdcc407['id']},{})['then'](function(){return _0xa1ff16;});}else{return _0xa1ff16;}})[_0x89f4('0x44')](function(_0x3060ef){logger['error'](_0x89f4('0x4e'),_0x3060ef);throw _0x3060ef;});}return _0xa1ff16;})['then'](respondWithResult(_0x46f62a,0xc9))['catch'](handleError(_0x46f62a,null));};exports[_0x89f4('0x27')]=function(_0x27a680,_0x78384a){if(_0x27a680[_0x89f4('0x4f')]['id']){delete _0x27a680['body']['id'];}return db[_0x89f4('0x31')][_0x89f4('0x47')]({'where':{'id':_0x27a680[_0x89f4('0x45')]['id']}})['then'](handleEntityNotFound(_0x78384a,null))[_0x89f4('0x28')](saveUpdates(_0x27a680[_0x89f4('0x4f')],null))[_0x89f4('0x28')](respondWithResult(_0x78384a,null))[_0x89f4('0x44')](handleError(_0x78384a,null));};exports[_0x89f4('0x2b')]=function(_0x13a2fe,_0x17a3f4){return db[_0x89f4('0x31')]['find']({'where':{'id':_0x13a2fe[_0x89f4('0x45')]['id']}})[_0x89f4('0x28')](handleEntityNotFound(_0x17a3f4,null))[_0x89f4('0x28')](removeEntity(_0x17a3f4,null))[_0x89f4('0x44')](handleError(_0x17a3f4,null));};exports['describe']=function(_0x25ce90,_0x634c39){return db[_0x89f4('0x31')][_0x89f4('0x50')]()[_0x89f4('0x28')](respondWithResult(_0x634c39,null))['catch'](handleError(_0x634c39,null));};exports[_0x89f4('0x51')]=function(_0x568cab,_0x48c3ba,_0x3e21e5){var _0x59b941={'raw':!![],'where':{}},_0x107ca5={},_0xb44430;return db[_0x89f4('0x31')][_0x89f4('0x52')]({'where':{'id':_0x568cab[_0x89f4('0x45')]['id']}})[_0x89f4('0x28')](handleEntityNotFound(_0x48c3ba,null))[_0x89f4('0x28')](function(_0x281a63){if(_0x281a63){_0xb44430=_0x281a63['get']({'plain':!![]});_0x107ca5['model']=_[_0x89f4('0x35')](db['UserFaxQueue'][_0x89f4('0x46')]);_0x107ca5['query']=_[_0x89f4('0x35')](_0x568cab[_0x89f4('0x34')]);_0x107ca5[_0x89f4('0x36')]=_[_0x89f4('0x37')](_0x107ca5[_0x89f4('0x33')],_0x107ca5['query']);_0x59b941[_0x89f4('0x39')]=_[_0x89f4('0x37')](_0x107ca5[_0x89f4('0x33')],qs['fields'](_0x568cab[_0x89f4('0x34')]['fields']));_0x59b941[_0x89f4('0x39')]=_0x59b941[_0x89f4('0x39')][_0x89f4('0x3a')]?_0x59b941['attributes']:_0x107ca5[_0x89f4('0x33')];if(!_0x568cab['query']['hasOwnProperty'](_0x89f4('0x53'))){_0x59b941[_0x89f4('0x20')]=qs[_0x89f4('0x20')](_0x568cab[_0x89f4('0x34')]['limit']);_0x59b941[_0x89f4('0x1f')]=qs[_0x89f4('0x1f')](_0x568cab[_0x89f4('0x34')][_0x89f4('0x1f')]);}_0x59b941['order']=qs[_0x89f4('0x3c')](_0x568cab['query']['sort']);_0x59b941[_0x89f4('0x3d')]=qs['filters'](_[_0x89f4('0x54')](_0x568cab[_0x89f4('0x34')],_0x107ca5['filters']));_0x59b941['where'][_0x89f4('0x55')]=_0x281a63['id'];if(_0x568cab[_0x89f4('0x34')]['filter']){_0x59b941[_0x89f4('0x3d')]=_[_0x89f4('0x3f')](_0x59b941[_0x89f4('0x3d')],{'$or':_[_0x89f4('0x30')](_0x59b941[_0x89f4('0x39')],function(_0x42a1bd){var _0x31af38={};_0x31af38[_0x42a1bd]={'$like':'%'+_0x568cab['query'][_0x89f4('0x3e')]+'%'};return _0x31af38;})});}_0x59b941=_[_0x89f4('0x3f')]({},_0x59b941,_0x568cab[_0x89f4('0x41')]);return db['UserFaxQueue'][_0x89f4('0x56')](_0x59b941);}})[_0x89f4('0x28')](function(_0x71bde9){if(_0x71bde9){return db['User']['findAndCountAll']({'where':{'id':_['map'](_0x71bde9,'UserId'),'role':_0x89f4('0x57')},'attributes':['id',_0x89f4('0x2e'),_0x89f4('0x58'),_0x89f4('0x59'),_0x89f4('0x5a')]});}})['then'](function(_0x4300bc){if(_0x4300bc){return{'count':_0x4300bc[_0x89f4('0x1e')],'rows':_['map'](_0x4300bc[_0x89f4('0x5b')],function(_0x47a4fa){return{'membername':_0x47a4fa[_0x89f4('0x2e')],'UserId':_0x47a4fa['id'],'queue_name':_0xb44430[_0x89f4('0x2e')],'FaxQueueId':_0xb44430['id'],'interface':util[_0x89f4('0x5c')](_0x89f4('0x5d'),'SIP',_0x47a4fa[_0x89f4('0x2e')]),'penalty':0x0,'paused':_0x47a4fa['faxPause'],'createdAt':_0x47a4fa[_0x89f4('0x5a')],'updatedAt':_0x47a4fa['updatedAt']};})};}else{return{'count':0x0,'rows':[]};}})['then'](respondWithFilteredResult(_0x48c3ba,_0x59b941))[_0x89f4('0x44')](handleError(_0x48c3ba,null));};exports[_0x89f4('0x5e')]=function(_0x56f94f,_0x5ea71a,_0x5932c9){var _0x271d01={};var _0x3cf546={};var _0x404657;var _0x13dae9;return db[_0x89f4('0x31')][_0x89f4('0x52')]({'where':{'id':_0x56f94f['params']['id']}})[_0x89f4('0x28')](handleEntityNotFound(_0x5ea71a,null))[_0x89f4('0x28')](function(_0x214c74){if(_0x214c74){_0x404657=_0x214c74;_0x3cf546[_0x89f4('0x33')]=_['keys'](db['Team'][_0x89f4('0x46')]);_0x3cf546[_0x89f4('0x34')]=_['keys'](_0x56f94f[_0x89f4('0x34')]);_0x3cf546[_0x89f4('0x36')]=_[_0x89f4('0x37')](_0x3cf546[_0x89f4('0x33')],_0x3cf546[_0x89f4('0x34')]);_0x271d01[_0x89f4('0x39')]=_[_0x89f4('0x37')](_0x3cf546['model'],qs[_0x89f4('0x38')](_0x56f94f[_0x89f4('0x34')]['fields']));_0x271d01[_0x89f4('0x39')]=_0x271d01[_0x89f4('0x39')][_0x89f4('0x3a')]?_0x271d01[_0x89f4('0x39')]:_0x3cf546[_0x89f4('0x33')];_0x271d01['order']=qs[_0x89f4('0x3c')](_0x56f94f['query'][_0x89f4('0x3c')]);_0x271d01['where']=qs['filters'](_[_0x89f4('0x54')](_0x56f94f[_0x89f4('0x34')],_0x3cf546[_0x89f4('0x36')]));if(_0x56f94f[_0x89f4('0x34')][_0x89f4('0x3e')]){_0x271d01[_0x89f4('0x3d')]=_[_0x89f4('0x3f')](_0x271d01['where'],{'$or':_[_0x89f4('0x30')](_0x271d01[_0x89f4('0x39')],function(_0xf2bfbf){var _0xb01d56={};_0xb01d56[_0xf2bfbf]={'$like':'%'+_0x56f94f[_0x89f4('0x34')]['filter']+'%'};return _0xb01d56;})});}_0x271d01=_[_0x89f4('0x3f')]({},_0x271d01,_0x56f94f[_0x89f4('0x41')]);return _0x404657[_0x89f4('0x5e')](_0x271d01);}})[_0x89f4('0x28')](function(_0x25f067){if(_0x25f067){_0x13dae9=_0x25f067['length'];if(!_0x56f94f['query'][_0x89f4('0x5f')](_0x89f4('0x53'))){_0x271d01['limit']=qs[_0x89f4('0x20')](_0x56f94f[_0x89f4('0x34')][_0x89f4('0x20')]);_0x271d01[_0x89f4('0x1f')]=qs['offset'](_0x56f94f['query'][_0x89f4('0x1f')]);}return _0x404657[_0x89f4('0x5e')](_0x271d01);}})[_0x89f4('0x28')](function(_0x234a0b){if(_0x234a0b){return _0x234a0b?{'count':_0x13dae9,'rows':_0x234a0b}:null;}})['then'](respondWithResult(_0x5ea71a,null))[_0x89f4('0x44')](handleError(_0x5ea71a,null));};exports['addTeams']=function(_0x3f7f54,_0x372ca4,_0x6ce1b1){var _0x12ce71=_0x3f7f54[_0x89f4('0x4f')][_0x89f4('0x60')];return db[_0x89f4('0x61')][_0x89f4('0x56')]({'where':{'id':_0x12ce71},'attributes':['id'],'include':[{'model':db['User'],'as':_0x89f4('0x62'),'attributes':['id',_0x89f4('0x2e'),'online',_0x89f4('0x63'),_0x89f4('0x64')],'raw':!![]}]})['then'](function(_0x51c953){if(_0x51c953){var _0x323117=_[_0x89f4('0x65')](_0x51c953,function(_0x5844f1){var _0x259724=_0x5844f1[_0x89f4('0x29')]({'plain':!![]});return _0x259724[_0x89f4('0x62')];});return db[_0x89f4('0x31')][_0x89f4('0x47')]({'where':{'id':_0x3f7f54['params']['id']}})['then'](function(_0x8ebdbd){return db[_0x89f4('0x66')][_0x89f4('0x67')](function(_0x3ac837){return _0x8ebdbd[_0x89f4('0x68')](_0x12ce71,{'transaction':_0x3ac837})[_0x89f4('0x28')](function(){return BPromise[_0x89f4('0x69')](_0x323117,function(_0x4a7ad7){return db[_0x89f4('0x6a')][_0x89f4('0x6b')]({'where':{'UserId':_0x4a7ad7['id'],'FaxQueueId':_0x3f7f54[_0x89f4('0x45')]['id']},'transaction':_0x3ac837});});})[_0x89f4('0x28')](function(){_0x323117[_0x89f4('0x6c')](function(_0x151dbc){socket['emit'](_0x89f4('0x6d'),{'UserId':_0x151dbc['id'],'FaxQueueId':_0x8ebdbd['id']});});});});});}})[_0x89f4('0x28')](respondWithStatusCode(_0x372ca4,null))['catch'](handleError(_0x372ca4,null));};exports['removeTeams']=function(_0x14435e,_0x5f543c,_0xceedf9){return db['Team'][_0x89f4('0x56')]({'where':{'id':_0x14435e[_0x89f4('0x34')][_0x89f4('0x60')]},'attributes':['id'],'include':[{'model':db[_0x89f4('0x6e')],'as':_0x89f4('0x62'),'attributes':['id'],'raw':!![]}]})[_0x89f4('0x28')](handleEntityNotFound(_0x5f543c,null))[_0x89f4('0x28')](function(_0x51fd05){var _0xe2ccfc=_['map'](_0x51fd05,'id');var _0x4518de=[];var _0x16ff3e=[];var _0x40093a=squel[_0x89f4('0x6f')]();_0x40093a[_0x89f4('0x70')]('tq.TeamId')[_0x89f4('0x71')](_0x89f4('0x72'),'tq')[_0x89f4('0x73')](_0x89f4('0x74'),'ut',_0x89f4('0x75'))[_0x89f4('0x3d')](_0x89f4('0x76'),_0x14435e[_0x89f4('0x45')]['id']);for(var _0x3934cc=0x0;_0x3934cc<_0x51fd05[_0x89f4('0x3a')];_0x3934cc+=0x1){let _0x5a7c0f=_0x51fd05[_0x3934cc];for(var _0x407967=0x0;_0x407967<_0x5a7c0f[_0x89f4('0x62')][_0x89f4('0x3a')];_0x407967+=0x1){let _0xcd9c17=_0x5a7c0f[_0x89f4('0x62')][_0x407967];var _0x585b2c=_0x40093a[_0x89f4('0x77')]();_0x585b2c[_0x89f4('0x3d')](_0x89f4('0x78'),_0xcd9c17['id']);_0x16ff3e[_0x89f4('0x79')](db[_0x89f4('0x66')][_0x89f4('0x34')](_0x585b2c[_0x89f4('0x7a')](),{'type':db[_0x89f4('0x66')]['QueryTypes'][_0x89f4('0x7b')]})['then'](function(_0xc449ad){if(_0xc449ad['length']===0x1){return _0xcd9c17['id'];}else{var _0x371ccc=_[_0x89f4('0x7c')](_[_0x89f4('0x30')](_0xc449ad,_0x89f4('0x7d')),function(_0x5b1e5f){return _[_0x89f4('0x7e')](_0xe2ccfc,_0x5b1e5f);});if(_0x371ccc){return _0xcd9c17['id'];}}}));}}return BPromise[_0x89f4('0x7f')](_0x16ff3e)[_0x89f4('0x28')](function(_0x270b36){_0x4518de=_(_0x4518de)[_0x89f4('0x80')](_0x270b36)[_0x89f4('0x81')]()[_0x89f4('0x82')]();return db['FaxQueue'][_0x89f4('0x47')]({'where':{'id':_0x14435e['params']['id']}})[_0x89f4('0x28')](function(_0x3a2c81){return db['sequelize'][_0x89f4('0x67')](function(_0x286975){return _0x3a2c81[_0x89f4('0x83')](_0x14435e['query'][_0x89f4('0x60')],{'transaction':_0x286975})[_0x89f4('0x28')](function(){if(!_['isEmpty'](_0x4518de)){return _0x3a2c81[_0x89f4('0x84')](_0x4518de,{'transaction':_0x286975});}})[_0x89f4('0x28')](function(){_0x4518de[_0x89f4('0x6c')](function(_0x15d746){socket['emit']('userFaxQueue:remove',{'UserId':_0x15d746,'FaxQueueId':_0x3a2c81['id']});});});});});});})['then'](respondWithStatusCode(_0x5f543c,null))[_0x89f4('0x44')](handleError(_0x5f543c,null));};exports[_0x89f4('0x85')]=function(_0x5119b6,_0x2b80ff,_0x25e69f){return db[_0x89f4('0x31')][_0x89f4('0x47')]({'where':{'id':_0x5119b6['params']['id']}})['then'](handleEntityNotFound(_0x2b80ff,null))[_0x89f4('0x28')](function(_0x3738d4){if(_0x3738d4){return _0x3738d4[_0x89f4('0x85')](_0x5119b6[_0x89f4('0x4f')][_0x89f4('0x60')],_[_0x89f4('0x86')](_0x5119b6[_0x89f4('0x4f')],[_0x89f4('0x60'),'id'])||{})[_0x89f4('0x87')](function(_0x11026a){for(var _0x3abd35=0x0;_0x3abd35<_0x5119b6['body']['ids'][_0x89f4('0x3a')];_0x3abd35+=0x1){socket[_0x89f4('0x88')](_0x89f4('0x6d'),{'UserId':_0x5119b6[_0x89f4('0x4f')][_0x89f4('0x60')][_0x3abd35],'FaxQueueId':_0x5119b6['params']['id']});}return _0x11026a;});}})[_0x89f4('0x28')](respondWithResult(_0x2b80ff,null))['catch'](handleError(_0x2b80ff,null));};exports['removeAgents']=function(_0x52fe03,_0x2f983e,_0x32ec8a){return db[_0x89f4('0x31')]['find']({'where':{'id':_0x52fe03['params']['id']}})[_0x89f4('0x28')](handleEntityNotFound(_0x2f983e,null))[_0x89f4('0x28')](function(_0x401069){if(_0x401069){return _0x401069[_0x89f4('0x84')](_0x52fe03[_0x89f4('0x34')][_0x89f4('0x60')])['then'](function(){if(_[_0x89f4('0x89')](_0x52fe03[_0x89f4('0x34')][_0x89f4('0x60')])){for(var _0x76d448=0x0;_0x76d448<_0x52fe03['query'][_0x89f4('0x60')][_0x89f4('0x3a')];_0x76d448+=0x1){socket[_0x89f4('0x88')](_0x89f4('0x8a'),{'UserId':Number(_0x52fe03['query'][_0x89f4('0x60')][_0x76d448]),'FaxQueueId':Number(_0x52fe03[_0x89f4('0x45')]['id'])});}}else{socket[_0x89f4('0x88')](_0x89f4('0x8a'),{'UserId':Number(_0x52fe03[_0x89f4('0x34')][_0x89f4('0x60')]),'FaxQueueId':Number(_0x52fe03[_0x89f4('0x45')]['id'])});}});}})[_0x89f4('0x28')](respondWithStatusCode(_0x2f983e,null))['catch'](handleError(_0x2f983e,null));};exports[_0x89f4('0x8b')]=function(_0x1914a2,_0x557ec2,_0x52b3da){var _0x2bd902={};var _0x58f4d5={};var _0x2bf4ca;var _0x225350;return db[_0x89f4('0x31')]['findOne']({'where':{'id':_0x1914a2[_0x89f4('0x45')]['id']}})[_0x89f4('0x28')](handleEntityNotFound(_0x557ec2,null))[_0x89f4('0x28')](function(_0x2a0100){if(_0x2a0100){_0x2bf4ca=_0x2a0100;_0x58f4d5['model']=_[_0x89f4('0x35')](db['User'][_0x89f4('0x46')]);_0x58f4d5[_0x89f4('0x34')]=_[_0x89f4('0x35')](_0x1914a2[_0x89f4('0x34')]);_0x58f4d5[_0x89f4('0x36')]=_['intersection'](_0x58f4d5['model'],_0x58f4d5[_0x89f4('0x34')]);_0x2bd902[_0x89f4('0x39')]=_[_0x89f4('0x37')](_0x58f4d5[_0x89f4('0x33')],qs[_0x89f4('0x38')](_0x1914a2[_0x89f4('0x34')]['fields']));_0x2bd902[_0x89f4('0x39')]=_0x2bd902[_0x89f4('0x39')][_0x89f4('0x3a')]?_0x2bd902[_0x89f4('0x39')]:_0x58f4d5['model'];_0x2bd902[_0x89f4('0x3b')]=qs['sort'](_0x1914a2[_0x89f4('0x34')][_0x89f4('0x3c')]);_0x2bd902[_0x89f4('0x3d')]=qs[_0x89f4('0x36')](_[_0x89f4('0x54')](_0x1914a2['query'],_0x58f4d5[_0x89f4('0x36')]));if(_0x1914a2['query'][_0x89f4('0x3e')]){_0x2bd902[_0x89f4('0x3d')]=_['merge'](_0x2bd902[_0x89f4('0x3d')],{'$or':_[_0x89f4('0x30')](_0x2bd902[_0x89f4('0x39')],function(_0x27490a){var _0x2a79e4={};_0x2a79e4[_0x27490a]={'$like':'%'+_0x1914a2[_0x89f4('0x34')][_0x89f4('0x3e')]+'%'};return _0x2a79e4;})});}_0x2bd902=_[_0x89f4('0x3f')]({},_0x2bd902,_0x1914a2[_0x89f4('0x41')]);return _0x2bf4ca[_0x89f4('0x8b')](_0x2bd902);}})['then'](function(_0x47aedd){if(_0x47aedd){_0x225350=_0x47aedd['length'];if(!_0x1914a2[_0x89f4('0x34')]['hasOwnProperty'](_0x89f4('0x53'))){_0x2bd902[_0x89f4('0x20')]=qs['limit'](_0x1914a2['query'][_0x89f4('0x20')]);_0x2bd902[_0x89f4('0x1f')]=qs['offset'](_0x1914a2['query'][_0x89f4('0x1f')]);}return _0x2bf4ca[_0x89f4('0x8b')](_0x2bd902);}})['then'](function(_0x306ca3){if(_0x306ca3){return _0x306ca3?{'count':_0x225350,'rows':_0x306ca3}:null;}})[_0x89f4('0x28')](respondWithResult(_0x557ec2,null))[_0x89f4('0x44')](handleError(_0x557ec2,null));};