Built motion from commit 639a1a7f.|2.6.19
[motion2.git] / server / api / voicePrefix / voicePrefix.controller.js
index 0e651fa..6610d29 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf807=['Content-Range','apply','reject','save','update','then','VoicePrefixes','UserProfileResource','destroy','end','sendStatus','name','send','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','pick','where','merge','VIRTUAL','filter','options','VoicePrefix','includeAll','include','catch','show','params','describe','create','transaction','body','get','find','VoiceExtensionId','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','context','from-sip','exten','system','description','Voice\x20Prefix\x20Extension','priority','appdata','prefix','NoOp','VoicePrefixId','VoiceExtension','bulkCreate','Extensions\x20creation\x20failed','CDR(prefix)=','callerIdAll','push','No\x20callerid\x20available','goto','charAt','findById','addAgents','omit','ids','spread','emit','removeAgents','isArray','userVoicePrefix:remove','getAgents','User','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../mysqldb','redis','socket.io-emitter','./voicePrefix.socket','status','json','count','offset'];(function(_0x106167,_0x569305){var _0x3248cc=function(_0x30dcef){while(--_0x30dcef){_0x106167['push'](_0x106167['shift']());}};_0x3248cc(++_0x569305);}(_0xf807,0x147));var _0x7f80=function(_0x51f3a2,_0x3368c7){_0x51f3a2=_0x51f3a2-0x0;var _0x4ba8f7=_0xf807[_0x51f3a2];return _0x4ba8f7;};'use strict';var pdf=require(_0x7f80('0x0'));var emlformat=require(_0x7f80('0x1'));var rimraf=require(_0x7f80('0x2'));var zipdir=require(_0x7f80('0x3'));var jsonpatch=require(_0x7f80('0x4'));var rp=require(_0x7f80('0x5'));var moment=require(_0x7f80('0x6'));var BPromise=require(_0x7f80('0x7'));var Mustache=require(_0x7f80('0x8'));var util=require('util');var path=require(_0x7f80('0x9'));var sox=require(_0x7f80('0xa'));var csv=require(_0x7f80('0xb'));var ejs=require(_0x7f80('0xc'));var fs=require('fs');var _=require('lodash');var squel=require(_0x7f80('0xd'));var crypto=require('crypto');var jsforce=require(_0x7f80('0xe'));var deskjs=require(_0x7f80('0xf'));var toCsv=require(_0x7f80('0xb'));var querystring=require(_0x7f80('0x10'));var Papa=require(_0x7f80('0x11'));var Redis=require(_0x7f80('0x12'));var authService=require(_0x7f80('0x13'));var qs=require(_0x7f80('0x14'));var as=require(_0x7f80('0x15'));var hardwareService=require(_0x7f80('0x16'));var logger=require(_0x7f80('0x17'))(_0x7f80('0x18'));var utils=require('../../config/utils');var config=require('../../config/environment');var db=require(_0x7f80('0x19'))['db'];config[_0x7f80('0x1a')]=_['defaults'](config[_0x7f80('0x1a')],{'host':'localhost','port':0x18eb});var socket=require(_0x7f80('0x1b'))(new Redis(config[_0x7f80('0x1a')]));require(_0x7f80('0x1c'))['register'](socket);function respondWithStatusCode(_0x18a3aa,_0x53e974){_0x53e974=_0x53e974||0xcc;return function(_0x128055){if(_0x128055){return _0x18a3aa['sendStatus'](_0x53e974);}return _0x18a3aa[_0x7f80('0x1d')](_0x53e974)['end']();};}function respondWithResult(_0x25395e,_0x450202){_0x450202=_0x450202||0xc8;return function(_0x208964){if(_0x208964){return _0x25395e[_0x7f80('0x1d')](_0x450202)[_0x7f80('0x1e')](_0x208964);}};}function respondWithFilteredResult(_0x5cf1c7,_0x37d96b){return function(_0x117629){if(_0x117629){var _0x53d7af=_0x117629[_0x7f80('0x1f')],_0xbca696=_0x37d96b[_0x7f80('0x20')],_0x8eb365=_0x37d96b[_0x7f80('0x20')]+_0x37d96b['limit'],_0x54c851;if(_0x8eb365>=_0x53d7af){_0x8eb365=_0x53d7af;_0x54c851=0xc8;}else{_0x54c851=0xce;}_0x5cf1c7[_0x7f80('0x1d')](_0x54c851);return _0x5cf1c7['set'](_0x7f80('0x21'),_0xbca696+'-'+_0x8eb365+'/'+_0x53d7af)[_0x7f80('0x1e')](_0x117629);}return null;};}function patchUpdates(_0xf98fdf){return function(_0x144960){try{jsonpatch[_0x7f80('0x22')](_0x144960,_0xf98fdf,!![]);}catch(_0x364a26){return BPromise[_0x7f80('0x23')](_0x364a26);}return _0x144960[_0x7f80('0x24')]();};}function saveUpdates(_0x1985c0,_0x4936d3){return function(_0xf6c42f){if(_0xf6c42f){return _0xf6c42f[_0x7f80('0x25')](_0x1985c0)[_0x7f80('0x26')](function(_0x205c95){return _0x205c95;});}return null;};}function removeEntity(_0x11bab0,_0x56deba){return function(_0x516a2c){if(_0x516a2c){return _0x516a2c['destroy']()[_0x7f80('0x26')](function(){var _0x565791=_0x516a2c['get']({'plain':!![]});var _0xa5aa5a=_0x7f80('0x27');return db[_0x7f80('0x28')][_0x7f80('0x29')]({'where':{'type':_0xa5aa5a,'resourceId':_0x565791['id']}})[_0x7f80('0x26')](function(){return _0x516a2c;});})[_0x7f80('0x26')](function(){_0x11bab0[_0x7f80('0x1d')](0xcc)[_0x7f80('0x2a')]();});}};}function handleEntityNotFound(_0x1c71b9,_0x347041){return function(_0x2b80c5){if(!_0x2b80c5){_0x1c71b9[_0x7f80('0x2b')](0x194);}return _0x2b80c5;};}function handleError(_0x59cc8f,_0x53da42){_0x53da42=_0x53da42||0x1f4;return function(_0x2a2d10){logger['error'](_0x2a2d10['stack']);if(_0x2a2d10['name']){delete _0x2a2d10[_0x7f80('0x2c')];}_0x59cc8f[_0x7f80('0x1d')](_0x53da42)[_0x7f80('0x2d')](_0x2a2d10);};}exports[_0x7f80('0x2e')]=function(_0x4db8ea,_0xe63160){var _0x32b40a={},_0x1e3cd0={},_0x597a30={'count':0x0,'rows':[]};var _0x5a1b92=_[_0x7f80('0x2f')](db['VoicePrefix'][_0x7f80('0x30')],function(_0x174ff2){return{'name':_0x174ff2[_0x7f80('0x31')],'type':_0x174ff2[_0x7f80('0x32')][_0x7f80('0x33')]};});_0x1e3cd0[_0x7f80('0x34')]=_[_0x7f80('0x2f')](_0x5a1b92,'name');_0x1e3cd0[_0x7f80('0x35')]=_[_0x7f80('0x36')](_0x4db8ea[_0x7f80('0x35')]);_0x1e3cd0[_0x7f80('0x37')]=_[_0x7f80('0x38')](_0x1e3cd0['model'],_0x1e3cd0[_0x7f80('0x35')]);_0x32b40a[_0x7f80('0x39')]=_[_0x7f80('0x38')](_0x1e3cd0['model'],qs[_0x7f80('0x3a')](_0x4db8ea[_0x7f80('0x35')][_0x7f80('0x3a')]));_0x32b40a['attributes']=_0x32b40a[_0x7f80('0x39')][_0x7f80('0x3b')]?_0x32b40a[_0x7f80('0x39')]:_0x1e3cd0[_0x7f80('0x34')];if(!_0x4db8ea['query'][_0x7f80('0x3c')](_0x7f80('0x3d'))){_0x32b40a[_0x7f80('0x3e')]=qs[_0x7f80('0x3e')](_0x4db8ea[_0x7f80('0x35')][_0x7f80('0x3e')]);_0x32b40a[_0x7f80('0x20')]=qs['offset'](_0x4db8ea['query'][_0x7f80('0x20')]);}_0x32b40a[_0x7f80('0x3f')]=qs[_0x7f80('0x40')](_0x4db8ea[_0x7f80('0x35')][_0x7f80('0x40')]);_0x32b40a['where']=qs[_0x7f80('0x37')](_[_0x7f80('0x41')](_0x4db8ea['query'],_0x1e3cd0[_0x7f80('0x37')]),_0x5a1b92);if(_0x4db8ea['query']['filter']){_0x32b40a[_0x7f80('0x42')]=_[_0x7f80('0x43')](_0x32b40a[_0x7f80('0x42')],{'$or':_['map'](_0x5a1b92,function(_0xc92728){if(_0xc92728[_0x7f80('0x32')]!==_0x7f80('0x44')){var _0x1d3868={};_0x1d3868[_0xc92728[_0x7f80('0x2c')]]={'$like':'%'+_0x4db8ea[_0x7f80('0x35')][_0x7f80('0x45')]+'%'};return _0x1d3868;}})});}_0x32b40a=_[_0x7f80('0x43')]({},_0x32b40a,_0x4db8ea[_0x7f80('0x46')]);var _0x141843={'where':_0x32b40a[_0x7f80('0x42')]};return db[_0x7f80('0x47')][_0x7f80('0x1f')](_0x141843)[_0x7f80('0x26')](function(_0x22c3bd){_0x597a30['count']=_0x22c3bd;if(_0x4db8ea[_0x7f80('0x35')][_0x7f80('0x48')]){_0x32b40a[_0x7f80('0x49')]=[{'all':!![]}];}return db['VoicePrefix']['findAll'](_0x32b40a);})[_0x7f80('0x26')](function(_0x3ec3e2){_0x597a30['rows']=_0x3ec3e2;return _0x597a30;})['then'](respondWithFilteredResult(_0xe63160,_0x32b40a))[_0x7f80('0x4a')](handleError(_0xe63160,null));};exports[_0x7f80('0x4b')]=function(_0x1e49cc,_0xda42e8){var _0xe4b60c={'raw':![],'where':{'id':_0x1e49cc[_0x7f80('0x4c')]['id']}},_0x286b35={};_0x286b35[_0x7f80('0x34')]=_['keys'](db[_0x7f80('0x47')]['rawAttributes']);_0x286b35[_0x7f80('0x35')]=_['keys'](_0x1e49cc[_0x7f80('0x35')]);_0x286b35['filters']=_[_0x7f80('0x38')](_0x286b35[_0x7f80('0x34')],_0x286b35[_0x7f80('0x35')]);_0xe4b60c[_0x7f80('0x39')]=_['intersection'](_0x286b35[_0x7f80('0x34')],qs['fields'](_0x1e49cc[_0x7f80('0x35')]['fields']));_0xe4b60c[_0x7f80('0x39')]=_0xe4b60c[_0x7f80('0x39')][_0x7f80('0x3b')]?_0xe4b60c['attributes']:_0x286b35[_0x7f80('0x34')];if(_0x1e49cc[_0x7f80('0x35')][_0x7f80('0x48')]){_0xe4b60c[_0x7f80('0x49')]=[{'all':!![]}];}_0xe4b60c=_[_0x7f80('0x43')]({},_0xe4b60c,_0x1e49cc[_0x7f80('0x46')]);return db['VoicePrefix']['find'](_0xe4b60c)[_0x7f80('0x26')](handleEntityNotFound(_0xda42e8,null))['then'](respondWithResult(_0xda42e8,null))['catch'](handleError(_0xda42e8,null));};exports['destroy']=function(_0x40212f,_0x4f2ccf){return db['VoicePrefix']['find']({'where':{'id':_0x40212f[_0x7f80('0x4c')]['id']}})[_0x7f80('0x26')](handleEntityNotFound(_0x4f2ccf,null))[_0x7f80('0x26')](removeEntity(_0x4f2ccf,null))[_0x7f80('0x4a')](handleError(_0x4f2ccf,null));};exports[_0x7f80('0x4d')]=function(_0x4f4e6b,_0x38a6db){return db['VoicePrefix'][_0x7f80('0x4d')]()['then'](respondWithResult(_0x38a6db,null))[_0x7f80('0x4a')](handleError(_0x38a6db,null));};exports[_0x7f80('0x4e')]=function(_0x500dff,_0x385e17){var _0x5bd90e;return db['sequelize'][_0x7f80('0x4f')](function(_0x50abc0){return db[_0x7f80('0x47')][_0x7f80('0x4e')](_0x500dff[_0x7f80('0x50')],{'transaction':_0x50abc0})[_0x7f80('0x26')](function(_0x4201e0){_0x5bd90e=_0x4201e0[_0x7f80('0x51')]({'plain':!![]});return db['VoiceExtension'][_0x7f80('0x52')]({'where':{'id':_0x5bd90e[_0x7f80('0x53')]},'raw':!![]})['then'](function(_0x23523d){return createVoicePrefixExtensions(_0x5bd90e,_0x23523d,_0x50abc0);});});})[_0x7f80('0x26')](function(){var _0x2e1e9b=_0x500dff[_0x7f80('0x54')][_0x7f80('0x51')]({'plain':!![]});if(!_0x2e1e9b)throw new Error(_0x7f80('0x55'));if(_0x2e1e9b['role']===_0x7f80('0x54')){var _0x15c96c=_0x5bd90e;return db[_0x7f80('0x56')]['find']({'where':{'name':'VoicePrefixes','userProfileId':_0x2e1e9b['userProfileId']},'raw':!![]})[_0x7f80('0x26')](function(_0x5c9c05){if(_0x5c9c05&&_0x5c9c05['autoAssociation']===0x0){return db[_0x7f80('0x28')][_0x7f80('0x4e')]({'name':_0x15c96c[_0x7f80('0x2c')],'resourceId':_0x15c96c['id'],'type':_0x5c9c05[_0x7f80('0x2c')],'sectionId':_0x5c9c05['id']},{})[_0x7f80('0x26')](function(){return _0x5bd90e;});}else{return _0x5bd90e;}})[_0x7f80('0x4a')](function(_0x27a95f){logger[_0x7f80('0x57')](_0x7f80('0x58'),_0x27a95f);throw _0x27a95f;});}return _0x5bd90e;})[_0x7f80('0x26')](respondWithResult(_0x385e17,null))[_0x7f80('0x4a')](handleError(_0x385e17,null));};function Extension(_0x3b759c,_0x2d5723,_0x3076fa,_0x59beae){this[_0x7f80('0x59')]=_0x7f80('0x5a');this[_0x7f80('0x5b')]=_0x3b759c;this['app']=_0x3076fa;this['type']=_0x7f80('0x5c');this[_0x7f80('0x5d')]=_0x7f80('0x5e');this[_0x7f80('0x5f')]=_0x2d5723;this[_0x7f80('0x60')]=_0x59beae;}function createVoicePrefixExtensions(_0x4a4aed,_0x3fd834,_0x5d175a){return new BPromise(function(_0x59abbc,_0x10a191){var _0x3ce52d=new Extension(formatPrefixName(_0x4a4aed[_0x7f80('0x61')]),0x1,_0x7f80('0x62'),'Voice\x20Prefix');_0x3ce52d[_0x7f80('0x63')]=_0x4a4aed['id'];return db['VoiceExtension'][_0x7f80('0x4e')](_0x3ce52d,{'transaction':_0x5d175a})[_0x7f80('0x26')](function(_0x30b60c){var _0x3e66b1=_0x30b60c[_0x7f80('0x51')]({'plain':!![]});var _0xc3c289=_['map'](addVoicePrefixExtensions(_0x4a4aed,_0x3fd834),function(_0x2d97cd){_0x2d97cd[_0x7f80('0x53')]=_0x3e66b1['id'];_0x2d97cd[_0x7f80('0x63')]=_0x4a4aed['id'];return _0x2d97cd;});return db[_0x7f80('0x64')][_0x7f80('0x65')](_0xc3c289,{'transaction':_0x5d175a})[_0x7f80('0x26')](function(_0x57fc3a){if(!_0x57fc3a){return _0x10a191(_0x7f80('0x66'));}else{return _0x59abbc(_0x57fc3a);}})[_0x7f80('0x4a')](function(_0x40c609){return _0x10a191(_0x40c609);});});;});};function addVoicePrefixExtensions(_0x3aa559,_0x4cef57){var _0x318daa=[];var _0x2e11cd=formatPrefixName(_0x3aa559[_0x7f80('0x61')]);_0x318daa['push'](new Extension(_0x2e11cd,0x2,'Set',_0x7f80('0x67')+_0x3aa559[_0x7f80('0x2c')]));if(_0x3aa559[_0x7f80('0x68')]){_0x318daa[_0x7f80('0x69')](new Extension(_0x2e11cd,0x3,'Set','PREFIX-CALLERIDALL='+_0x3aa559[_0x7f80('0x68')]));}else{_0x318daa['push'](new Extension(_0x2e11cd,0x3,_0x7f80('0x62'),_0x7f80('0x6a')));}_0x318daa[_0x7f80('0x69')](new Extension(_0x2e11cd,0x4,_0x7f80('0x6b'),_0x4cef57[_0x7f80('0x59')]+','+'${EXTEN:'+(0x8+_0x3aa559[_0x7f80('0x2c')][_0x7f80('0x3b')])+'}'+','+0x1));return _0x318daa;}function formatPrefixName(_0x357efa){var _0x5b3da8='_';for(var _0x219929=0x0;_0x219929<_0x357efa['length'];_0x219929++){if(_0x357efa[_0x7f80('0x6c')](_0x219929)=='-'){_0x5b3da8+=_0x357efa[_0x7f80('0x6c')](_0x219929);}else{_0x5b3da8+='['+_0x357efa[_0x7f80('0x6c')](_0x219929)+']';}}_0x5b3da8+='.';return _0x5b3da8;}exports[_0x7f80('0x25')]=function(_0x2dd3c6,_0x4bb567,_0x77e6f3){var _0x523827=_0x2dd3c6[_0x7f80('0x50')];_0x523827['prefix']='system-'+_0x523827[_0x7f80('0x2c')]+'-';return db['sequelize'][_0x7f80('0x4f')](function(_0x1dd5e1){return db[_0x7f80('0x47')][_0x7f80('0x25')](_0x523827,{'where':{'id':_0x523827['id']},'transaction':_0x1dd5e1})['then'](function(){return db['VoiceExtension'][_0x7f80('0x29')]({'where':{'VoicePrefixId':_0x523827['id']},'transaction':_0x1dd5e1})[_0x7f80('0x26')](function(){return db[_0x7f80('0x64')][_0x7f80('0x52')]({'where':{'id':_0x523827[_0x7f80('0x53')]},'raw':!![]})[_0x7f80('0x26')](function(_0x48067a){return createVoicePrefixExtensions(_0x523827,_0x48067a,_0x1dd5e1);});});});})['then'](function(){return db[_0x7f80('0x47')][_0x7f80('0x6d')](_0x523827['id']);})[_0x7f80('0x26')](respondWithResult(_0x4bb567,null))[_0x7f80('0x4a')](handleError(_0x4bb567,null));};exports[_0x7f80('0x6e')]=function(_0x2f5afc,_0x28ddc0,_0x4f9628){return db[_0x7f80('0x47')][_0x7f80('0x52')]({'where':{'id':_0x2f5afc['params']['id']}})[_0x7f80('0x26')](handleEntityNotFound(_0x28ddc0,null))[_0x7f80('0x26')](function(_0x49a940){if(_0x49a940){return _0x49a940['addAgents'](_0x2f5afc['body']['ids'],_[_0x7f80('0x6f')](_0x2f5afc[_0x7f80('0x50')],[_0x7f80('0x70'),'id'])||{})[_0x7f80('0x71')](function(_0xe70025){for(var _0x2edfbb=0x0;_0x2edfbb<_0x2f5afc[_0x7f80('0x50')][_0x7f80('0x70')][_0x7f80('0x3b')];_0x2edfbb+=0x1){socket[_0x7f80('0x72')]('userVoicePrefix:save',{'UserId':_0x2f5afc['body'][_0x7f80('0x70')][_0x2edfbb],'VoicePrefixId':_0x2f5afc['params']['id']});}return _0xe70025;});}})['then'](respondWithResult(_0x28ddc0,null))['catch'](handleError(_0x28ddc0,null));};exports['removeAgents']=function(_0x5df0ee,_0x9009d7,_0x3f788a){return db['VoicePrefix']['find']({'where':{'id':_0x5df0ee[_0x7f80('0x4c')]['id']}})['then'](handleEntityNotFound(_0x9009d7,null))[_0x7f80('0x26')](function(_0x1635a9){if(_0x1635a9){return _0x1635a9[_0x7f80('0x73')](_0x5df0ee[_0x7f80('0x35')][_0x7f80('0x70')])[_0x7f80('0x26')](function(){if(_[_0x7f80('0x74')](_0x5df0ee[_0x7f80('0x35')][_0x7f80('0x70')])){for(var _0x57b215=0x0;_0x57b215<_0x5df0ee[_0x7f80('0x35')][_0x7f80('0x70')][_0x7f80('0x3b')];_0x57b215+=0x1){socket['emit'](_0x7f80('0x75'),{'UserId':Number(_0x5df0ee[_0x7f80('0x35')][_0x7f80('0x70')][_0x57b215]),'VoicePrefixId':Number(_0x5df0ee[_0x7f80('0x4c')]['id'])});}}else{socket['emit'](_0x7f80('0x75'),{'UserId':Number(_0x5df0ee[_0x7f80('0x35')][_0x7f80('0x70')]),'VoicePrefixId':Number(_0x5df0ee[_0x7f80('0x4c')]['id'])});}});}})[_0x7f80('0x26')](respondWithStatusCode(_0x9009d7,null))['catch'](handleError(_0x9009d7,null));};exports[_0x7f80('0x76')]=function(_0x50798e,_0x47e212,_0x4d0731){var _0x3b88b0={};var _0x42739c={};var _0xc4021;var _0x198c64;return db[_0x7f80('0x47')]['findOne']({'where':{'id':_0x50798e[_0x7f80('0x4c')]['id']}})[_0x7f80('0x26')](handleEntityNotFound(_0x47e212,null))[_0x7f80('0x26')](function(_0x134b41){if(_0x134b41){_0xc4021=_0x134b41;_0x42739c[_0x7f80('0x34')]=_[_0x7f80('0x36')](db[_0x7f80('0x77')][_0x7f80('0x30')]);_0x42739c[_0x7f80('0x35')]=_[_0x7f80('0x36')](_0x50798e[_0x7f80('0x35')]);_0x42739c[_0x7f80('0x37')]=_[_0x7f80('0x38')](_0x42739c[_0x7f80('0x34')],_0x42739c[_0x7f80('0x35')]);_0x3b88b0['attributes']=_[_0x7f80('0x38')](_0x42739c[_0x7f80('0x34')],qs[_0x7f80('0x3a')](_0x50798e[_0x7f80('0x35')][_0x7f80('0x3a')]));_0x3b88b0[_0x7f80('0x39')]=_0x3b88b0[_0x7f80('0x39')][_0x7f80('0x3b')]?_0x3b88b0['attributes']:_0x42739c[_0x7f80('0x34')];_0x3b88b0[_0x7f80('0x3f')]=qs[_0x7f80('0x40')](_0x50798e['query'][_0x7f80('0x40')]);_0x3b88b0['where']=qs[_0x7f80('0x37')](_[_0x7f80('0x41')](_0x50798e['query'],_0x42739c[_0x7f80('0x37')]));if(_0x50798e[_0x7f80('0x35')][_0x7f80('0x45')]){_0x3b88b0[_0x7f80('0x42')]=_[_0x7f80('0x43')](_0x3b88b0[_0x7f80('0x42')],{'$or':_[_0x7f80('0x2f')](_0x3b88b0['attributes'],function(_0x305c57){var _0x5795ef={};_0x5795ef[_0x305c57]={'$like':'%'+_0x50798e[_0x7f80('0x35')][_0x7f80('0x45')]+'%'};return _0x5795ef;})});}_0x3b88b0=_[_0x7f80('0x43')]({},_0x3b88b0,_0x50798e[_0x7f80('0x46')]);return _0xc4021['getAgents'](_0x3b88b0);}})[_0x7f80('0x26')](function(_0x76956f){if(_0x76956f){_0x198c64=_0x76956f[_0x7f80('0x3b')];if(!_0x50798e[_0x7f80('0x35')][_0x7f80('0x3c')]('nolimit')){_0x3b88b0['limit']=qs['limit'](_0x50798e[_0x7f80('0x35')][_0x7f80('0x3e')]);_0x3b88b0[_0x7f80('0x20')]=qs[_0x7f80('0x20')](_0x50798e[_0x7f80('0x35')][_0x7f80('0x20')]);}return _0xc4021[_0x7f80('0x76')](_0x3b88b0);}})[_0x7f80('0x26')](function(_0x2c286a){if(_0x2c286a){return _0x2c286a?{'count':_0x198c64,'rows':_0x2c286a}:null;}})['then'](respondWithResult(_0x47e212,null))['catch'](handleError(_0x47e212,null));};
\ No newline at end of file
+var _0x5fdc=['fs-extra','lodash','desk.js','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','defaults','redis','localhost','socket.io-emitter','./voicePrefix.socket','register','sendStatus','status','end','offset','undefined','limit','count','json','apply','reject','update','then','get','UserProfileResource','destroy','error','stack','name','index','map','VoicePrefix','rawAttributes','fieldName','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','type','VIRTUAL','includeAll','catch','show','include','options','find','params','describe','create','sequelize','transaction','body','VoiceExtensionId','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','autoAssociation','context','from-sip','exten','app','system','description','Voice\x20Prefix\x20Extension','priority','appdata','prefix','NoOp','Voice\x20Prefix','VoiceExtension','VoicePrefixId','Extensions\x20creation\x20failed','push','callerIdAll','Set','PREFIX-CALLERIDALL=','goto','${EXTEN:','charAt','system-','addAgents','ids','omit','spread','emit','removeAgents','isArray','getAgents','findOne','User','filter','getTeams','Team','findAll','addTeams','each','TeamVoicePrefix','upsert','UserVoicePrefix','findOrCreate','forEach','userVoicePrefix:save','removeTeams','Agents','select','field','tq.TeamId','team_has_voice_prefixes','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','clone','ut.UserId\x20=\x20?','toString','QueryTypes','SELECT','every','includes','all','union','compact','value','isEmpty','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs'];(function(_0x4b2436,_0x452299){var _0x4f5ab2=function(_0x5c6679){while(--_0x5c6679){_0x4b2436['push'](_0x4b2436['shift']());}};_0x4f5ab2(++_0x452299);}(_0x5fdc,0x127));var _0xc5fd=function(_0x1cd8e3,_0x2e5b28){_0x1cd8e3=_0x1cd8e3-0x0;var _0x56c533=_0x5fdc[_0x1cd8e3];return _0x56c533;};'use strict';var emlformat=require(_0xc5fd('0x0'));var rimraf=require(_0xc5fd('0x1'));var zipdir=require(_0xc5fd('0x2'));var jsonpatch=require(_0xc5fd('0x3'));var rp=require(_0xc5fd('0x4'));var moment=require(_0xc5fd('0x5'));var BPromise=require(_0xc5fd('0x6'));var Mustache=require(_0xc5fd('0x7'));var util=require(_0xc5fd('0x8'));var path=require(_0xc5fd('0x9'));var sox=require(_0xc5fd('0xa'));var csv=require(_0xc5fd('0xb'));var ejs=require(_0xc5fd('0xc'));var fs=require('fs');var fs_extra=require(_0xc5fd('0xd'));var _=require(_0xc5fd('0xe'));var squel=require('squel');var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xc5fd('0xf'));var toCsv=require(_0xc5fd('0xb'));var querystring=require(_0xc5fd('0x10'));var Papa=require(_0xc5fd('0x11'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xc5fd('0x12'));var as=require(_0xc5fd('0x13'));var hardwareService=require(_0xc5fd('0x14'));var logger=require(_0xc5fd('0x15'))(_0xc5fd('0x16'));var utils=require(_0xc5fd('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0xc5fd('0x18'));var db=require('../../mysqldb')['db'];config['redis']=_[_0xc5fd('0x19')](config[_0xc5fd('0x1a')],{'host':_0xc5fd('0x1b'),'port':0x18eb});var socket=require(_0xc5fd('0x1c'))(new Redis(config[_0xc5fd('0x1a')]));require(_0xc5fd('0x1d'))[_0xc5fd('0x1e')](socket);function respondWithStatusCode(_0xa7a954,_0x51233a){_0x51233a=_0x51233a||0xcc;return function(_0x124651){if(_0x124651){return _0xa7a954[_0xc5fd('0x1f')](_0x51233a);}return _0xa7a954[_0xc5fd('0x20')](_0x51233a)[_0xc5fd('0x21')]();};}function respondWithResult(_0x4d3636,_0x4fd364){_0x4fd364=_0x4fd364||0xc8;return function(_0x4efafd){if(_0x4efafd){return _0x4d3636['status'](_0x4fd364)['json'](_0x4efafd);}};}function respondWithFilteredResult(_0x35a9d0,_0x430e52){return function(_0x27f611){if(_0x27f611){var _0xd0a9f1=typeof _0x430e52[_0xc5fd('0x22')]===_0xc5fd('0x23')&&typeof _0x430e52[_0xc5fd('0x24')]==='undefined';var _0xb7bab1=_0x27f611[_0xc5fd('0x25')];var _0x32eac2=_0xd0a9f1?0x0:_0x430e52[_0xc5fd('0x22')];var _0x3b3093=_0xd0a9f1?_0x27f611['count']:_0x430e52[_0xc5fd('0x22')]+_0x430e52[_0xc5fd('0x24')];var _0x18048e;if(_0x3b3093>=_0xb7bab1){_0x3b3093=_0xb7bab1;_0x18048e=0xc8;}else{_0x18048e=0xce;}_0x35a9d0[_0xc5fd('0x20')](_0x18048e);return _0x35a9d0['set']('Content-Range',_0x32eac2+'-'+_0x3b3093+'/'+_0xb7bab1)[_0xc5fd('0x26')](_0x27f611);}return null;};}function patchUpdates(_0x2ab935){return function(_0x3d7211){try{jsonpatch[_0xc5fd('0x27')](_0x3d7211,_0x2ab935,!![]);}catch(_0x334401){return BPromise[_0xc5fd('0x28')](_0x334401);}return _0x3d7211['save']();};}function saveUpdates(_0x1a3f21,_0x2701f7){return function(_0x1a5174){if(_0x1a5174){return _0x1a5174[_0xc5fd('0x29')](_0x1a3f21)[_0xc5fd('0x2a')](function(_0x4020af){return _0x4020af;});}return null;};}function removeEntity(_0x475b91,_0x527018){return function(_0x3a86f9){if(_0x3a86f9){return _0x3a86f9['destroy']()[_0xc5fd('0x2a')](function(){var _0x231368=_0x3a86f9[_0xc5fd('0x2b')]({'plain':!![]});var _0x2bee22='VoicePrefixes';return db[_0xc5fd('0x2c')][_0xc5fd('0x2d')]({'where':{'type':_0x2bee22,'resourceId':_0x231368['id']}})[_0xc5fd('0x2a')](function(){return _0x3a86f9;});})[_0xc5fd('0x2a')](function(){_0x475b91[_0xc5fd('0x20')](0xcc)[_0xc5fd('0x21')]();});}};}function handleEntityNotFound(_0x541c12,_0x412ef7){return function(_0x5d4f70){if(!_0x5d4f70){_0x541c12['sendStatus'](0x194);}return _0x5d4f70;};}function handleError(_0x12a962,_0x165ee2){_0x165ee2=_0x165ee2||0x1f4;return function(_0x39b21a){logger[_0xc5fd('0x2e')](_0x39b21a[_0xc5fd('0x2f')]);if(_0x39b21a[_0xc5fd('0x30')]){delete _0x39b21a[_0xc5fd('0x30')];}_0x12a962[_0xc5fd('0x20')](_0x165ee2)['send'](_0x39b21a);};}exports[_0xc5fd('0x31')]=function(_0x1b2957,_0x6bb14d){var _0x3b9699={},_0x14c832={},_0x40ed4d={'count':0x0,'rows':[]};var _0x3c0f64=_[_0xc5fd('0x32')](db[_0xc5fd('0x33')][_0xc5fd('0x34')],function(_0x104f37){return{'name':_0x104f37[_0xc5fd('0x35')],'type':_0x104f37['type'][_0xc5fd('0x36')]};});_0x14c832[_0xc5fd('0x37')]=_[_0xc5fd('0x32')](_0x3c0f64,_0xc5fd('0x30'));_0x14c832[_0xc5fd('0x38')]=_[_0xc5fd('0x39')](_0x1b2957[_0xc5fd('0x38')]);_0x14c832[_0xc5fd('0x3a')]=_[_0xc5fd('0x3b')](_0x14c832['model'],_0x14c832[_0xc5fd('0x38')]);_0x3b9699[_0xc5fd('0x3c')]=_[_0xc5fd('0x3b')](_0x14c832[_0xc5fd('0x37')],qs[_0xc5fd('0x3d')](_0x1b2957[_0xc5fd('0x38')][_0xc5fd('0x3d')]));_0x3b9699['attributes']=_0x3b9699[_0xc5fd('0x3c')][_0xc5fd('0x3e')]?_0x3b9699['attributes']:_0x14c832[_0xc5fd('0x37')];if(!_0x1b2957['query'][_0xc5fd('0x3f')](_0xc5fd('0x40'))){_0x3b9699[_0xc5fd('0x24')]=qs['limit'](_0x1b2957[_0xc5fd('0x38')][_0xc5fd('0x24')]);_0x3b9699['offset']=qs[_0xc5fd('0x22')](_0x1b2957[_0xc5fd('0x38')][_0xc5fd('0x22')]);}_0x3b9699[_0xc5fd('0x41')]=qs[_0xc5fd('0x42')](_0x1b2957[_0xc5fd('0x38')]['sort']);_0x3b9699[_0xc5fd('0x43')]=qs[_0xc5fd('0x3a')](_[_0xc5fd('0x44')](_0x1b2957[_0xc5fd('0x38')],_0x14c832['filters']),_0x3c0f64);if(_0x1b2957['query']['filter']){_0x3b9699[_0xc5fd('0x43')]=_[_0xc5fd('0x45')](_0x3b9699[_0xc5fd('0x43')],{'$or':_[_0xc5fd('0x32')](_0x3c0f64,function(_0x125c02){if(_0x125c02[_0xc5fd('0x46')]!==_0xc5fd('0x47')){var _0x2ef96f={};_0x2ef96f[_0x125c02[_0xc5fd('0x30')]]={'$like':'%'+_0x1b2957['query']['filter']+'%'};return _0x2ef96f;}})});}_0x3b9699=_[_0xc5fd('0x45')]({},_0x3b9699,_0x1b2957['options']);var _0x970623={'where':_0x3b9699[_0xc5fd('0x43')]};return db[_0xc5fd('0x33')]['count'](_0x970623)[_0xc5fd('0x2a')](function(_0x350753){_0x40ed4d['count']=_0x350753;if(_0x1b2957[_0xc5fd('0x38')][_0xc5fd('0x48')]){_0x3b9699['include']=[{'all':!![]}];}return db[_0xc5fd('0x33')]['findAll'](_0x3b9699);})[_0xc5fd('0x2a')](function(_0x17ce12){_0x40ed4d['rows']=_0x17ce12;return _0x40ed4d;})[_0xc5fd('0x2a')](respondWithFilteredResult(_0x6bb14d,_0x3b9699))[_0xc5fd('0x49')](handleError(_0x6bb14d,null));};exports[_0xc5fd('0x4a')]=function(_0x4825fa,_0x408edb){var _0x74a071={'raw':![],'where':{'id':_0x4825fa['params']['id']}},_0x559282={};_0x559282[_0xc5fd('0x37')]=_['keys'](db['VoicePrefix']['rawAttributes']);_0x559282[_0xc5fd('0x38')]=_[_0xc5fd('0x39')](_0x4825fa[_0xc5fd('0x38')]);_0x559282[_0xc5fd('0x3a')]=_[_0xc5fd('0x3b')](_0x559282[_0xc5fd('0x37')],_0x559282['query']);_0x74a071['attributes']=_['intersection'](_0x559282[_0xc5fd('0x37')],qs[_0xc5fd('0x3d')](_0x4825fa[_0xc5fd('0x38')]['fields']));_0x74a071[_0xc5fd('0x3c')]=_0x74a071['attributes'][_0xc5fd('0x3e')]?_0x74a071[_0xc5fd('0x3c')]:_0x559282[_0xc5fd('0x37')];if(_0x4825fa[_0xc5fd('0x38')][_0xc5fd('0x48')]){_0x74a071[_0xc5fd('0x4b')]=[{'all':!![]}];}_0x74a071=_['merge']({},_0x74a071,_0x4825fa[_0xc5fd('0x4c')]);return db[_0xc5fd('0x33')]['find'](_0x74a071)['then'](handleEntityNotFound(_0x408edb,null))[_0xc5fd('0x2a')](respondWithResult(_0x408edb,null))['catch'](handleError(_0x408edb,null));};exports['destroy']=function(_0x6e5626,_0x2436e9){return db['VoicePrefix'][_0xc5fd('0x4d')]({'where':{'id':_0x6e5626[_0xc5fd('0x4e')]['id']}})['then'](handleEntityNotFound(_0x2436e9,null))[_0xc5fd('0x2a')](removeEntity(_0x2436e9,null))[_0xc5fd('0x49')](handleError(_0x2436e9,null));};exports[_0xc5fd('0x4f')]=function(_0x12b847,_0x1940e3){return db[_0xc5fd('0x33')][_0xc5fd('0x4f')]()[_0xc5fd('0x2a')](respondWithResult(_0x1940e3,null))[_0xc5fd('0x49')](handleError(_0x1940e3,null));};exports[_0xc5fd('0x50')]=function(_0x3e1471,_0x4c10a7){var _0x3c9b99;return db[_0xc5fd('0x51')][_0xc5fd('0x52')](function(_0x4989ce){return db[_0xc5fd('0x33')][_0xc5fd('0x50')](_0x3e1471[_0xc5fd('0x53')],{'transaction':_0x4989ce})[_0xc5fd('0x2a')](function(_0x5c7d68){_0x3c9b99=_0x5c7d68[_0xc5fd('0x2b')]({'plain':!![]});return db['VoiceExtension']['find']({'where':{'id':_0x3c9b99[_0xc5fd('0x54')]},'raw':!![]})[_0xc5fd('0x2a')](function(_0x236d04){return createVoicePrefixExtensions(_0x3c9b99,_0x236d04,_0x4989ce);});});})[_0xc5fd('0x2a')](function(){var _0x275e18=_0x3e1471['user']['get']({'plain':!![]});if(!_0x275e18)throw new Error(_0xc5fd('0x55'));if(_0x275e18[_0xc5fd('0x56')]==='user'){var _0x4e9495=_0x3c9b99;return db['UserProfileSection'][_0xc5fd('0x4d')]({'where':{'name':'VoicePrefixes','userProfileId':_0x275e18[_0xc5fd('0x57')]},'raw':!![]})[_0xc5fd('0x2a')](function(_0x2503cd){if(_0x2503cd&&_0x2503cd[_0xc5fd('0x58')]===0x0){return db[_0xc5fd('0x2c')][_0xc5fd('0x50')]({'name':_0x4e9495[_0xc5fd('0x30')],'resourceId':_0x4e9495['id'],'type':_0x2503cd['name'],'sectionId':_0x2503cd['id']},{})[_0xc5fd('0x2a')](function(){return _0x3c9b99;});}else{return _0x3c9b99;}})[_0xc5fd('0x49')](function(_0x228e40){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x228e40);throw _0x228e40;});}return _0x3c9b99;})[_0xc5fd('0x2a')](respondWithResult(_0x4c10a7,null))[_0xc5fd('0x49')](handleError(_0x4c10a7,null));};function Extension(_0x2f30d6,_0x149483,_0x69367,_0x45f9fd){this[_0xc5fd('0x59')]=_0xc5fd('0x5a');this[_0xc5fd('0x5b')]=_0x2f30d6;this[_0xc5fd('0x5c')]=_0x69367;this[_0xc5fd('0x46')]=_0xc5fd('0x5d');this[_0xc5fd('0x5e')]=_0xc5fd('0x5f');this[_0xc5fd('0x60')]=_0x149483;this[_0xc5fd('0x61')]=_0x45f9fd;}function createVoicePrefixExtensions(_0x548b65,_0x404759,_0xc05f80){return new BPromise(function(_0x3eeae0,_0x53a3ee){var _0x32a240=new Extension(formatPrefixName(_0x548b65[_0xc5fd('0x62')]),0x1,_0xc5fd('0x63'),_0xc5fd('0x64'));_0x32a240['VoicePrefixId']=_0x548b65['id'];return db[_0xc5fd('0x65')][_0xc5fd('0x50')](_0x32a240,{'transaction':_0xc05f80})['then'](function(_0x27a1f5){var _0x53ea3d=_0x27a1f5[_0xc5fd('0x2b')]({'plain':!![]});var _0x70a6d=_[_0xc5fd('0x32')](addVoicePrefixExtensions(_0x548b65,_0x404759),function(_0xcaa6b0){_0xcaa6b0[_0xc5fd('0x54')]=_0x53ea3d['id'];_0xcaa6b0[_0xc5fd('0x66')]=_0x548b65['id'];return _0xcaa6b0;});return db['VoiceExtension']['bulkCreate'](_0x70a6d,{'transaction':_0xc05f80})[_0xc5fd('0x2a')](function(_0x1ff40b){if(!_0x1ff40b){return _0x53a3ee(_0xc5fd('0x67'));}else{return _0x3eeae0(_0x1ff40b);}})[_0xc5fd('0x49')](function(_0x27b533){return _0x53a3ee(_0x27b533);});});;});};function addVoicePrefixExtensions(_0x2f4b60,_0x189d7d){var _0x77a940=[];var _0x4d6f97=formatPrefixName(_0x2f4b60[_0xc5fd('0x62')]);_0x77a940[_0xc5fd('0x68')](new Extension(_0x4d6f97,0x2,'Set','CDR(prefix)='+_0x2f4b60[_0xc5fd('0x30')]));if(_0x2f4b60[_0xc5fd('0x69')]){_0x77a940[_0xc5fd('0x68')](new Extension(_0x4d6f97,0x3,_0xc5fd('0x6a'),_0xc5fd('0x6b')+_0x2f4b60[_0xc5fd('0x69')]));}else{_0x77a940[_0xc5fd('0x68')](new Extension(_0x4d6f97,0x3,_0xc5fd('0x63'),'No\x20callerid\x20available'));}_0x77a940[_0xc5fd('0x68')](new Extension(_0x4d6f97,0x4,_0xc5fd('0x6c'),_0x189d7d['context']+','+_0xc5fd('0x6d')+(0x8+_0x2f4b60[_0xc5fd('0x30')]['length'])+'}'+','+0x1));return _0x77a940;}function formatPrefixName(_0x4591be){var _0x2a8c7f='_';for(var _0x5e3f8=0x0;_0x5e3f8<_0x4591be[_0xc5fd('0x3e')];_0x5e3f8++){if(_0x4591be[_0xc5fd('0x6e')](_0x5e3f8)=='-'){_0x2a8c7f+=_0x4591be[_0xc5fd('0x6e')](_0x5e3f8);}else{_0x2a8c7f+='['+_0x4591be[_0xc5fd('0x6e')](_0x5e3f8)+']';}}_0x2a8c7f+='.';return _0x2a8c7f;}exports[_0xc5fd('0x29')]=function(_0x3d1940,_0x130b7b,_0x539c0a){var _0x5131ba=_0x3d1940[_0xc5fd('0x53')];_0x5131ba[_0xc5fd('0x62')]=_0xc5fd('0x6f')+_0x5131ba['name']+'-';return db[_0xc5fd('0x51')][_0xc5fd('0x52')](function(_0x2696be){return db['VoicePrefix'][_0xc5fd('0x29')](_0x5131ba,{'where':{'id':_0x5131ba['id']},'transaction':_0x2696be})[_0xc5fd('0x2a')](function(){return db[_0xc5fd('0x65')]['destroy']({'where':{'VoicePrefixId':_0x5131ba['id']},'transaction':_0x2696be})['then'](function(){return db[_0xc5fd('0x65')][_0xc5fd('0x4d')]({'where':{'id':_0x5131ba['VoiceExtensionId']},'raw':!![]})[_0xc5fd('0x2a')](function(_0x55d691){return createVoicePrefixExtensions(_0x5131ba,_0x55d691,_0x2696be);});});});})[_0xc5fd('0x2a')](function(){return db[_0xc5fd('0x33')]['findById'](_0x5131ba['id']);})['then'](respondWithResult(_0x130b7b,null))[_0xc5fd('0x49')](handleError(_0x130b7b,null));};exports[_0xc5fd('0x70')]=function(_0x39624c,_0x152212,_0x281cf9){return db[_0xc5fd('0x33')]['find']({'where':{'id':_0x39624c[_0xc5fd('0x4e')]['id']}})[_0xc5fd('0x2a')](handleEntityNotFound(_0x152212,null))[_0xc5fd('0x2a')](function(_0x24ecc2){if(_0x24ecc2){return _0x24ecc2[_0xc5fd('0x70')](_0x39624c[_0xc5fd('0x53')][_0xc5fd('0x71')],_[_0xc5fd('0x72')](_0x39624c[_0xc5fd('0x53')],['ids','id'])||{})[_0xc5fd('0x73')](function(_0x58ca76){for(var _0x151d13=0x0;_0x151d13<_0x39624c[_0xc5fd('0x53')][_0xc5fd('0x71')]['length'];_0x151d13+=0x1){socket[_0xc5fd('0x74')]('userVoicePrefix:save',{'UserId':Number(_0x39624c['body'][_0xc5fd('0x71')][_0x151d13]),'VoicePrefixId':Number(_0x39624c[_0xc5fd('0x4e')]['id'])});}return _0x58ca76;});}})[_0xc5fd('0x2a')](respondWithResult(_0x152212,null))[_0xc5fd('0x49')](handleError(_0x152212,null));};exports[_0xc5fd('0x75')]=function(_0x58df99,_0x4b43fc,_0x1ab84b){return db[_0xc5fd('0x33')][_0xc5fd('0x4d')]({'where':{'id':_0x58df99[_0xc5fd('0x4e')]['id']}})[_0xc5fd('0x2a')](handleEntityNotFound(_0x4b43fc,null))['then'](function(_0x3a89a9){if(_0x3a89a9){return _0x3a89a9[_0xc5fd('0x75')](_0x58df99[_0xc5fd('0x38')][_0xc5fd('0x71')])[_0xc5fd('0x2a')](function(){if(_[_0xc5fd('0x76')](_0x58df99[_0xc5fd('0x38')]['ids'])){for(var _0x9e84d2=0x0;_0x9e84d2<_0x58df99[_0xc5fd('0x38')][_0xc5fd('0x71')][_0xc5fd('0x3e')];_0x9e84d2+=0x1){socket['emit']('userVoicePrefix:remove',{'UserId':Number(_0x58df99['query'][_0xc5fd('0x71')][_0x9e84d2]),'VoicePrefixId':Number(_0x58df99[_0xc5fd('0x4e')]['id'])});}}else{socket[_0xc5fd('0x74')]('userVoicePrefix:remove',{'UserId':Number(_0x58df99[_0xc5fd('0x38')][_0xc5fd('0x71')]),'VoicePrefixId':Number(_0x58df99[_0xc5fd('0x4e')]['id'])});}});}})[_0xc5fd('0x2a')](respondWithStatusCode(_0x4b43fc,null))[_0xc5fd('0x49')](handleError(_0x4b43fc,null));};exports[_0xc5fd('0x77')]=function(_0x31fb3d,_0x5199f3,_0x32a6f3){var _0xe69dd8={};var _0x312b34={};var _0x38c97e;var _0x320249;return db[_0xc5fd('0x33')][_0xc5fd('0x78')]({'where':{'id':_0x31fb3d[_0xc5fd('0x4e')]['id']}})[_0xc5fd('0x2a')](handleEntityNotFound(_0x5199f3,null))[_0xc5fd('0x2a')](function(_0x4e67e7){if(_0x4e67e7){_0x38c97e=_0x4e67e7;_0x312b34[_0xc5fd('0x37')]=_[_0xc5fd('0x39')](db[_0xc5fd('0x79')][_0xc5fd('0x34')]);_0x312b34[_0xc5fd('0x38')]=_[_0xc5fd('0x39')](_0x31fb3d[_0xc5fd('0x38')]);_0x312b34['filters']=_[_0xc5fd('0x3b')](_0x312b34['model'],_0x312b34[_0xc5fd('0x38')]);_0xe69dd8[_0xc5fd('0x3c')]=_[_0xc5fd('0x3b')](_0x312b34[_0xc5fd('0x37')],qs[_0xc5fd('0x3d')](_0x31fb3d[_0xc5fd('0x38')]['fields']));_0xe69dd8[_0xc5fd('0x3c')]=_0xe69dd8['attributes'][_0xc5fd('0x3e')]?_0xe69dd8[_0xc5fd('0x3c')]:_0x312b34['model'];_0xe69dd8[_0xc5fd('0x41')]=qs[_0xc5fd('0x42')](_0x31fb3d[_0xc5fd('0x38')][_0xc5fd('0x42')]);_0xe69dd8[_0xc5fd('0x43')]=qs[_0xc5fd('0x3a')](_[_0xc5fd('0x44')](_0x31fb3d[_0xc5fd('0x38')],_0x312b34[_0xc5fd('0x3a')]));if(_0x31fb3d[_0xc5fd('0x38')][_0xc5fd('0x7a')]){_0xe69dd8[_0xc5fd('0x43')]=_['merge'](_0xe69dd8[_0xc5fd('0x43')],{'$or':_['map'](_0xe69dd8[_0xc5fd('0x3c')],function(_0xcab6e8){var _0x5951b4={};_0x5951b4[_0xcab6e8]={'$like':'%'+_0x31fb3d['query'][_0xc5fd('0x7a')]+'%'};return _0x5951b4;})});}_0xe69dd8=_['merge']({},_0xe69dd8,_0x31fb3d['options']);return _0x38c97e[_0xc5fd('0x77')](_0xe69dd8);}})[_0xc5fd('0x2a')](function(_0x58b8ce){if(_0x58b8ce){_0x320249=_0x58b8ce[_0xc5fd('0x3e')];if(!_0x31fb3d[_0xc5fd('0x38')]['hasOwnProperty'](_0xc5fd('0x40'))){_0xe69dd8[_0xc5fd('0x24')]=qs[_0xc5fd('0x24')](_0x31fb3d[_0xc5fd('0x38')][_0xc5fd('0x24')]);_0xe69dd8[_0xc5fd('0x22')]=qs[_0xc5fd('0x22')](_0x31fb3d[_0xc5fd('0x38')][_0xc5fd('0x22')]);}return _0x38c97e['getAgents'](_0xe69dd8);}})[_0xc5fd('0x2a')](function(_0x41d546){if(_0x41d546){return _0x41d546?{'count':_0x320249,'rows':_0x41d546}:null;}})[_0xc5fd('0x2a')](respondWithResult(_0x5199f3,null))[_0xc5fd('0x49')](handleError(_0x5199f3,null));};exports[_0xc5fd('0x7b')]=function(_0x3260de,_0x52f4a2,_0x3b04bb){var _0x54625d={};var _0x8cc5f6={};var _0x1f8bec;var _0x5cccd3;return db[_0xc5fd('0x33')][_0xc5fd('0x78')]({'where':{'id':_0x3260de['params']['id']}})['then'](handleEntityNotFound(_0x52f4a2,null))[_0xc5fd('0x2a')](function(_0x588469){if(_0x588469){_0x1f8bec=_0x588469;_0x8cc5f6[_0xc5fd('0x37')]=_[_0xc5fd('0x39')](db[_0xc5fd('0x7c')][_0xc5fd('0x34')]);_0x8cc5f6[_0xc5fd('0x38')]=_['keys'](_0x3260de[_0xc5fd('0x38')]);_0x8cc5f6[_0xc5fd('0x3a')]=_[_0xc5fd('0x3b')](_0x8cc5f6['model'],_0x8cc5f6[_0xc5fd('0x38')]);_0x54625d[_0xc5fd('0x3c')]=_['intersection'](_0x8cc5f6[_0xc5fd('0x37')],qs[_0xc5fd('0x3d')](_0x3260de['query'][_0xc5fd('0x3d')]));_0x54625d[_0xc5fd('0x3c')]=_0x54625d[_0xc5fd('0x3c')][_0xc5fd('0x3e')]?_0x54625d[_0xc5fd('0x3c')]:_0x8cc5f6[_0xc5fd('0x37')];_0x54625d['order']=qs[_0xc5fd('0x42')](_0x3260de[_0xc5fd('0x38')][_0xc5fd('0x42')]);_0x54625d[_0xc5fd('0x43')]=qs[_0xc5fd('0x3a')](_[_0xc5fd('0x44')](_0x3260de['query'],_0x8cc5f6[_0xc5fd('0x3a')]));if(_0x3260de[_0xc5fd('0x38')]['filter']){_0x54625d[_0xc5fd('0x43')]=_[_0xc5fd('0x45')](_0x54625d[_0xc5fd('0x43')],{'$or':_[_0xc5fd('0x32')](_0x54625d[_0xc5fd('0x3c')],function(_0x431e42){var _0x147657={};_0x147657[_0x431e42]={'$like':'%'+_0x3260de[_0xc5fd('0x38')][_0xc5fd('0x7a')]+'%'};return _0x147657;})});}_0x54625d=_[_0xc5fd('0x45')]({},_0x54625d,_0x3260de['options']);return _0x1f8bec[_0xc5fd('0x7b')](_0x54625d);}})[_0xc5fd('0x2a')](function(_0x815f86){if(_0x815f86){_0x5cccd3=_0x815f86[_0xc5fd('0x3e')];if(!_0x3260de[_0xc5fd('0x38')]['hasOwnProperty'](_0xc5fd('0x40'))){_0x54625d[_0xc5fd('0x24')]=qs[_0xc5fd('0x24')](_0x3260de[_0xc5fd('0x38')][_0xc5fd('0x24')]);_0x54625d[_0xc5fd('0x22')]=qs[_0xc5fd('0x22')](_0x3260de[_0xc5fd('0x38')][_0xc5fd('0x22')]);}return _0x1f8bec['getTeams'](_0x54625d);}})[_0xc5fd('0x2a')](function(_0x1e9c2c){if(_0x1e9c2c){return _0x1e9c2c?{'count':_0x5cccd3,'rows':_0x1e9c2c}:null;}})[_0xc5fd('0x2a')](respondWithResult(_0x52f4a2,null))[_0xc5fd('0x49')](handleError(_0x52f4a2,null));};exports['addTeams']=function(_0x1e5d78,_0x4bcd48,_0x5afaf5){var _0x5e0206=_0x1e5d78['body'][_0xc5fd('0x71')];var _0x5a3c8c;return db[_0xc5fd('0x7c')][_0xc5fd('0x7d')]({'where':{'id':_0x5e0206},'attributes':['id'],'include':[{'model':db[_0xc5fd('0x79')],'as':'Agents','attributes':['id',_0xc5fd('0x30'),'online','voicePause','interface'],'raw':!![]}]})[_0xc5fd('0x2a')](function(_0x1cb1a6){if(_0x1cb1a6){_0x5a3c8c=_0x1cb1a6;var _0x358648=_['flatMap'](_0x1cb1a6,function(_0x56a5d0){var _0x2bf91e=_0x56a5d0[_0xc5fd('0x2b')]({'plain':!![]});return _0x2bf91e['Agents'];});return db[_0xc5fd('0x33')][_0xc5fd('0x4d')]({'where':{'id':_0x1e5d78['params']['id']}})[_0xc5fd('0x2a')](function(_0x3c94ec){return db[_0xc5fd('0x51')][_0xc5fd('0x52')](function(_0x3bd95a){return _0x3c94ec[_0xc5fd('0x7e')](_0x5e0206,{'transaction':_0x3bd95a})[_0xc5fd('0x2a')](function(){return BPromise[_0xc5fd('0x7f')](_0x5a3c8c,function(_0x1e23e7){return db[_0xc5fd('0x80')][_0xc5fd('0x81')]({'TeamId':_0x1e23e7['id'],'VoicePrefixId':_0x1e5d78[_0xc5fd('0x4e')]['id']},{'transaction':_0x3bd95a});});})['then'](function(){return BPromise[_0xc5fd('0x7f')](_0x358648,function(_0x4c3fbb){return db[_0xc5fd('0x82')][_0xc5fd('0x83')]({'where':{'UserId':_0x4c3fbb['id'],'VoicePrefixId':_0x1e5d78[_0xc5fd('0x4e')]['id']},'transaction':_0x3bd95a});});})['then'](function(){_0x358648[_0xc5fd('0x84')](function(_0x5a438e){socket[_0xc5fd('0x74')](_0xc5fd('0x85'),{'UserId':_0x5a438e['id'],'VoicePrefixId':_0x3c94ec['id']});});});});});}})[_0xc5fd('0x2a')](respondWithStatusCode(_0x4bcd48,null))[_0xc5fd('0x49')](handleError(_0x4bcd48,null));};exports[_0xc5fd('0x86')]=function(_0x4065d9,_0xf709eb,_0x241693){return db[_0xc5fd('0x7c')][_0xc5fd('0x7d')]({'where':{'id':_0x4065d9[_0xc5fd('0x38')][_0xc5fd('0x71')]},'attributes':['id'],'include':[{'model':db[_0xc5fd('0x79')],'as':_0xc5fd('0x87'),'attributes':['id'],'raw':!![]}]})[_0xc5fd('0x2a')](handleEntityNotFound(_0xf709eb,null))[_0xc5fd('0x2a')](function(_0x2fb5f4){var _0x281c9e=_[_0xc5fd('0x32')](_0x2fb5f4,'id');var _0x5ca2a9=[];var _0x6594ae=[];var _0x1af269=squel[_0xc5fd('0x88')]();_0x1af269[_0xc5fd('0x89')](_0xc5fd('0x8a'))['from'](_0xc5fd('0x8b'),'tq')['join'](_0xc5fd('0x8c'),'ut',_0xc5fd('0x8d'))['where']('VoicePrefixId\x20=\x20?',_0x4065d9[_0xc5fd('0x4e')]['id']);for(var _0x4debb8=0x0;_0x4debb8<_0x2fb5f4[_0xc5fd('0x3e')];_0x4debb8+=0x1){let _0x474579=_0x2fb5f4[_0x4debb8];for(var _0x2ab188=0x0;_0x2ab188<_0x474579['Agents']['length'];_0x2ab188+=0x1){let _0x516a64=_0x474579[_0xc5fd('0x87')][_0x2ab188];var _0x41a3b6=_0x1af269[_0xc5fd('0x8e')]();_0x41a3b6[_0xc5fd('0x43')](_0xc5fd('0x8f'),_0x516a64['id']);_0x6594ae[_0xc5fd('0x68')](db[_0xc5fd('0x51')][_0xc5fd('0x38')](_0x41a3b6[_0xc5fd('0x90')](),{'type':db[_0xc5fd('0x51')][_0xc5fd('0x91')][_0xc5fd('0x92')]})[_0xc5fd('0x2a')](function(_0x492f78){if(_0x492f78[_0xc5fd('0x3e')]===0x1){return _0x516a64['id'];}else{var _0x12e1a8=_[_0xc5fd('0x93')](_[_0xc5fd('0x32')](_0x492f78,'TeamId'),function(_0x4751af){return _[_0xc5fd('0x94')](_0x281c9e,_0x4751af);});if(_0x12e1a8){return _0x516a64['id'];}}}));}}return BPromise[_0xc5fd('0x95')](_0x6594ae)[_0xc5fd('0x2a')](function(_0x2917b5){_0x5ca2a9=_(_0x5ca2a9)[_0xc5fd('0x96')](_0x2917b5)[_0xc5fd('0x97')]()[_0xc5fd('0x98')]();return db[_0xc5fd('0x33')][_0xc5fd('0x4d')]({'where':{'id':_0x4065d9['params']['id']}})[_0xc5fd('0x2a')](function(_0x21526e){return db[_0xc5fd('0x51')][_0xc5fd('0x52')](function(_0x2456d8){return _0x21526e['removeTeams'](_0x4065d9[_0xc5fd('0x38')][_0xc5fd('0x71')],{'transaction':_0x2456d8})['then'](function(){if(!_[_0xc5fd('0x99')](_0x5ca2a9)){return _0x21526e['removeAgents'](_0x5ca2a9,{'transaction':_0x2456d8});}})[_0xc5fd('0x2a')](function(){_0x5ca2a9['forEach'](function(_0x233398){socket[_0xc5fd('0x74')]('userVoicePrefix:remove',{'UserId':_0x233398,'VoicePrefixId':_0x21526e['id']});});});});});});})['then'](respondWithStatusCode(_0xf709eb,null))['catch'](handleError(_0xf709eb,null));};
\ No newline at end of file