7cbff73565c2ee30b18aed3a2abfcfdfbf49cdbf
[motion2.git] / server / api / voiceExtension / voiceExtension.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 _0xc918=['options','where','includeAll','findAll','rows','catch','show','include','find','params','create','body','outbound','startsWith','exten','concat','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','context','description','recordingFormat','mandatoryDisposition','alias','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','VoiceExtensionId','isApp','createRouting','bulkCreate','findAndCountAll','cast(priority\x20as\x20unsigned)','finally','lodash','ioredis','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','socket.io-emitter','./voiceExtension.socket','sendStatus','end','status','json','offset','undefined','count','limit','set','destroy','inbound','OutboundRoutes','InternalRoutes','internal','filter','map','value','includes','type','name','UserProfileResource','then','error','send','index','VoiceExtension','rawAttributes','fieldName','query','keys','filters','intersection','attributes','model','fields','length','hasOwnProperty','nolimit','sort','merge'];(function(_0x1c3b41,_0x50f776){var _0x41e3fe=function(_0x512069){while(--_0x512069){_0x1c3b41['push'](_0x1c3b41['shift']());}};_0x41e3fe(++_0x50f776);}(_0xc918,0x13a));var _0x8c91=function(_0x1f13e0,_0x4bf225){_0x1f13e0=_0x1f13e0-0x0;var _0x41be47=_0xc918[_0x1f13e0];return _0x41be47;};'use strict';var _=require(_0x8c91('0x0'));var Redis=require(_0x8c91('0x1'));var qs=require('../../components/parsers/qs');var logger=require(_0x8c91('0x2'))(_0x8c91('0x3'));var config=require(_0x8c91('0x4'));var db=require(_0x8c91('0x5'))['db'];config[_0x8c91('0x6')]=_[_0x8c91('0x7')](config[_0x8c91('0x6')],{'host':'localhost','port':0x18eb});var socket=require(_0x8c91('0x8'))(new Redis(config[_0x8c91('0x6')]));require(_0x8c91('0x9'))['register'](socket);function respondWithStatusCode(_0x329553,_0x1c32bf){_0x1c32bf=_0x1c32bf||0xcc;return function(_0xc39677){if(_0xc39677){return _0x329553[_0x8c91('0xa')](_0x1c32bf);}return _0x329553['status'](_0x1c32bf)[_0x8c91('0xb')]();};}function respondWithResult(_0x3a30b6,_0x4b98d9){_0x4b98d9=_0x4b98d9||0xc8;return function(_0x166861){if(_0x166861){return _0x3a30b6[_0x8c91('0xc')](_0x4b98d9)[_0x8c91('0xd')](_0x166861);}};}function respondWithFilteredResult(_0x205bd0,_0x1029ed){return function(_0x4def6a){if(_0x4def6a){var _0x227be7=typeof _0x1029ed[_0x8c91('0xe')]===_0x8c91('0xf')&&typeof _0x1029ed['limit']===_0x8c91('0xf');var _0x20b34b=_0x4def6a[_0x8c91('0x10')];var _0x59872c=_0x227be7?0x0:_0x1029ed[_0x8c91('0xe')];var _0x20e516=_0x227be7?_0x4def6a[_0x8c91('0x10')]:_0x1029ed['offset']+_0x1029ed[_0x8c91('0x11')];var _0x4ce901;if(_0x20e516>=_0x20b34b){_0x20e516=_0x20b34b;_0x4ce901=0xc8;}else{_0x4ce901=0xce;}_0x205bd0[_0x8c91('0xc')](_0x4ce901);return _0x205bd0[_0x8c91('0x12')]('Content-Range',_0x59872c+'-'+_0x20e516+'/'+_0x20b34b)[_0x8c91('0xd')](_0x4def6a);}return null;};}function removeEntity(_0x136e2b){return function(_0x11e4b5){if(_0x11e4b5){return _0x11e4b5[_0x8c91('0x13')]()['then'](function(){var _0x365d8f=_0x11e4b5['get']({'plain':!![]});var _0x4b2028=[{'name':'InboundRoutes','value':_0x8c91('0x14'),'ignore':![]},{'name':_0x8c91('0x15'),'value':'outbound','ignore':![]},{'name':_0x8c91('0x16'),'value':_0x8c91('0x17'),'ignore':![]}];var _0x4cee6c=_(_0x4b2028)[_0x8c91('0x18')]('ignore')[_0x8c91('0x19')](_0x8c91('0x1a'))[_0x8c91('0x1a')]();if(_[_0x8c91('0x1b')](_0x4cee6c,_0x365d8f[_0x8c91('0x1c')])){return;}var _0x5c4675=_['find'](_0x4b2028,[_0x8c91('0x1a'),_0x365d8f['type']])[_0x8c91('0x1d')];return db[_0x8c91('0x1e')][_0x8c91('0x13')]({'where':{'type':_0x5c4675,'resourceId':_0x365d8f['id']}})['then'](function(){return _0x11e4b5;});})[_0x8c91('0x1f')](function(){_0x136e2b[_0x8c91('0xc')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2af222){return function(_0x539bbb){if(!_0x539bbb){_0x2af222[_0x8c91('0xa')](0x194);}return _0x539bbb;};}function handleError(_0xf8a22e,_0x3385d3){_0x3385d3=_0x3385d3||0x1f4;return function(_0x2e0c7c){logger[_0x8c91('0x20')](_0x2e0c7c['stack']);if(_0x2e0c7c[_0x8c91('0x1d')]){delete _0x2e0c7c[_0x8c91('0x1d')];}_0xf8a22e[_0x8c91('0xc')](_0x3385d3)[_0x8c91('0x21')](_0x2e0c7c);};}exports[_0x8c91('0x22')]=function(_0x287230,_0x2fb01f){var _0x15ffea={},_0x5c73a4={},_0x3291fb={'count':0x0,'rows':[]};var _0x58cc2b=_['map'](db[_0x8c91('0x23')][_0x8c91('0x24')],function(_0x569272){return{'name':_0x569272[_0x8c91('0x25')],'type':_0x569272[_0x8c91('0x1c')]['key']};});_0x5c73a4['model']=_[_0x8c91('0x19')](_0x58cc2b,_0x8c91('0x1d'));_0x5c73a4[_0x8c91('0x26')]=_[_0x8c91('0x27')](_0x287230['query']);_0x5c73a4[_0x8c91('0x28')]=_[_0x8c91('0x29')](_0x5c73a4['model'],_0x5c73a4['query']);_0x15ffea[_0x8c91('0x2a')]=_[_0x8c91('0x29')](_0x5c73a4[_0x8c91('0x2b')],qs[_0x8c91('0x2c')](_0x287230['query'][_0x8c91('0x2c')]));_0x15ffea['attributes']=_0x15ffea[_0x8c91('0x2a')][_0x8c91('0x2d')]?_0x15ffea[_0x8c91('0x2a')]:_0x5c73a4[_0x8c91('0x2b')];if(!_0x287230[_0x8c91('0x26')][_0x8c91('0x2e')](_0x8c91('0x2f'))){_0x15ffea[_0x8c91('0x11')]=qs[_0x8c91('0x11')](_0x287230[_0x8c91('0x26')]['limit']);_0x15ffea[_0x8c91('0xe')]=qs[_0x8c91('0xe')](_0x287230['query'][_0x8c91('0xe')]);}_0x15ffea['order']=qs[_0x8c91('0x30')](_0x287230[_0x8c91('0x26')][_0x8c91('0x30')]);_0x15ffea['where']=qs[_0x8c91('0x28')](_['pick'](_0x287230[_0x8c91('0x26')],_0x5c73a4[_0x8c91('0x28')]),_0x58cc2b);if(_0x287230[_0x8c91('0x26')][_0x8c91('0x18')]){_0x15ffea['where']=_[_0x8c91('0x31')](_0x15ffea['where'],{'$or':_[_0x8c91('0x19')](_0x58cc2b,function(_0x36b42e){if(_0x36b42e[_0x8c91('0x1c')]!=='VIRTUAL'){var _0x3ddb44={};_0x3ddb44[_0x36b42e[_0x8c91('0x1d')]]={'$like':'%'+_0x287230[_0x8c91('0x26')][_0x8c91('0x18')]+'%'};return _0x3ddb44;}})});}_0x15ffea=_[_0x8c91('0x31')]({},_0x15ffea,_0x287230[_0x8c91('0x32')]);var _0x307393={'where':_0x15ffea[_0x8c91('0x33')]};return db[_0x8c91('0x23')]['count'](_0x307393)[_0x8c91('0x1f')](function(_0x3c25d0){_0x3291fb[_0x8c91('0x10')]=_0x3c25d0;if(_0x287230[_0x8c91('0x26')][_0x8c91('0x34')]){_0x15ffea['include']=[{'all':!![]}];}return db[_0x8c91('0x23')][_0x8c91('0x35')](_0x15ffea);})[_0x8c91('0x1f')](function(_0x3b6709){_0x3291fb[_0x8c91('0x36')]=_0x3b6709;return _0x3291fb;})[_0x8c91('0x1f')](respondWithFilteredResult(_0x2fb01f,_0x15ffea))[_0x8c91('0x37')](handleError(_0x2fb01f,null));};exports[_0x8c91('0x38')]=function(_0x5b1594,_0x582561){var _0x27a9d0={'raw':![],'where':{'id':_0x5b1594['params']['id']}},_0x27aded={};_0x27aded[_0x8c91('0x2b')]=_[_0x8c91('0x27')](db[_0x8c91('0x23')][_0x8c91('0x24')]);_0x27aded[_0x8c91('0x26')]=_[_0x8c91('0x27')](_0x5b1594[_0x8c91('0x26')]);_0x27aded[_0x8c91('0x28')]=_['intersection'](_0x27aded[_0x8c91('0x2b')],_0x27aded[_0x8c91('0x26')]);_0x27a9d0[_0x8c91('0x2a')]=_['intersection'](_0x27aded[_0x8c91('0x2b')],qs[_0x8c91('0x2c')](_0x5b1594[_0x8c91('0x26')][_0x8c91('0x2c')]));_0x27a9d0[_0x8c91('0x2a')]=_0x27a9d0[_0x8c91('0x2a')][_0x8c91('0x2d')]?_0x27a9d0['attributes']:_0x27aded[_0x8c91('0x2b')];if(_0x5b1594['query']['includeAll']){_0x27a9d0[_0x8c91('0x39')]=[{'all':!![]}];}_0x27a9d0=_[_0x8c91('0x31')]({},_0x27a9d0,_0x5b1594[_0x8c91('0x32')]);return db[_0x8c91('0x23')][_0x8c91('0x3a')](_0x27a9d0)[_0x8c91('0x1f')](handleEntityNotFound(_0x582561,null))[_0x8c91('0x1f')](respondWithResult(_0x582561,null))[_0x8c91('0x37')](handleError(_0x582561,null));};exports[_0x8c91('0x13')]=function(_0x14d4b9,_0x52de95){return db[_0x8c91('0x23')][_0x8c91('0x3a')]({'where':{'id':_0x14d4b9[_0x8c91('0x3b')]['id']}})[_0x8c91('0x1f')](handleEntityNotFound(_0x52de95,null))[_0x8c91('0x1f')](removeEntity(_0x52de95,null))[_0x8c91('0x37')](handleError(_0x52de95,null));};exports[_0x8c91('0x3c')]=function(_0x5c4135,_0x3cc813){if(_0x5c4135[_0x8c91('0x3d')][_0x8c91('0x1c')]===_0x8c91('0x3e')&&!_[_0x8c91('0x3f')](_0x5c4135[_0x8c91('0x3d')]['exten'],'_')){_0x5c4135['body'][_0x8c91('0x40')]='_'[_0x8c91('0x41')](_0x5c4135[_0x8c91('0x3d')][_0x8c91('0x40')]);}return db[_0x8c91('0x23')][_0x8c91('0x3c')](_0x5c4135[_0x8c91('0x3d')],{'raw':![]})[_0x8c91('0x1f')](function(_0x313df8){var _0x249ff1=_0x5c4135[_0x8c91('0x42')][_0x8c91('0x43')]({'plain':!![]});if(!_0x249ff1)throw new Error(_0x8c91('0x44'));if(_0x249ff1[_0x8c91('0x45')]===_0x8c91('0x42')){var _0x5cfc05=_0x313df8[_0x8c91('0x43')]({'plain':!![]});var _0x4acf91=[{'name':'InboundRoutes','value':_0x8c91('0x14')},{'name':_0x8c91('0x15'),'value':_0x8c91('0x3e')},{'name':_0x8c91('0x16'),'value':_0x8c91('0x17')}];var _0x42d188=_[_0x8c91('0x3a')](_0x4acf91,[_0x8c91('0x1a'),_0x5cfc05[_0x8c91('0x1c')]])[_0x8c91('0x1d')];return db[_0x8c91('0x46')][_0x8c91('0x3a')]({'where':{'name':_0x42d188,'userProfileId':_0x249ff1['userProfileId']},'raw':!![]})[_0x8c91('0x1f')](function(_0xf7d044){if(_0xf7d044&&_0xf7d044[_0x8c91('0x47')]===0x0){return db[_0x8c91('0x1e')][_0x8c91('0x3c')]({'name':_0x5cfc05[_0x8c91('0x1d')],'resourceId':_0x5cfc05['id'],'type':_0xf7d044[_0x8c91('0x1d')],'sectionId':_0xf7d044['id']},{})['then'](function(){return _0x313df8;});}else{return _0x313df8;}})['catch'](function(_0x14b87b){logger[_0x8c91('0x20')](_0x8c91('0x48'),_0x14b87b);throw _0x14b87b;});}return _0x313df8;})['then'](respondWithResult(_0x3cc813,0xc9))['catch'](handleError(_0x3cc813,null));};exports[_0x8c91('0x49')]=function(_0x22b222,_0x38e009){if(_0x22b222['body']['id']){delete _0x22b222[_0x8c91('0x3d')]['id'];}return db[_0x8c91('0x23')][_0x8c91('0x3a')]({'where':{'id':_0x22b222[_0x8c91('0x3b')]['id']}})['then'](handleEntityNotFound(_0x38e009,null))[_0x8c91('0x1f')](function(_0x332ead){if(_0x332ead){return db['VoiceExtension'][_0x8c91('0x49')](_['pick'](_0x22b222[_0x8c91('0x3d')],['exten',_0x8c91('0x4a'),_0x8c91('0x4b'),_0x8c91('0x4c'),'cutdigits',_0x8c91('0x4d'),_0x8c91('0x4e')]),{'where':{'context':_0x332ead[_0x8c91('0x4a')],'exten':_0x332ead[_0x8c91('0x40')]},'individualHooks':!![]})[_0x8c91('0x1f')](function(_0x342332){return _0x342332;});}return null;})[_0x8c91('0x1f')](respondWithStatusCode(_0x38e009,null))[_0x8c91('0x37')](handleError(_0x38e009,null));};exports[_0x8c91('0x4f')]=function(_0x3e7858,_0x489f1f){var _0x4330a5=_0x3e7858[_0x8c91('0x3b')]['id'];var _0x76883e=_0x3e7858[_0x8c91('0x3d')];var _0x387f68=0xc8;var _0x24bf49=null;return db[_0x8c91('0x50')][_0x8c91('0x51')]({'isolationLevel':db[_0x8c91('0x50')][_0x8c91('0x52')][_0x8c91('0x53')]['READ_COMMITTED']},function(_0x5df076){return db[_0x8c91('0x23')]['findOne']({'where':{'id':_0x4330a5},'transaction':_0x5df076})[_0x8c91('0x1f')](function(_0x2467ff){if(_0x2467ff){return db[_0x8c91('0x23')][_0x8c91('0x13')]({'where':{'VoiceExtensionId':_0x4330a5},'transaction':_0x5df076})[_0x8c91('0x1f')](function(){var _0x192be4=_[_0x8c91('0x19')](_0x76883e,function(_0x354e64){_0x354e64[_0x8c91('0x54')]=_0x4330a5;_0x354e64[_0x8c91('0x55')]=!![];return _0x354e64;});return _0x2467ff[_0x8c91('0x56')](_0x192be4);})[_0x8c91('0x1f')](function(_0x5b8707){return db[_0x8c91('0x23')][_0x8c91('0x57')](_0x5b8707,{'transaction':_0x5df076});});}else{_0x387f68=0x194;_0x24bf49=[];}});})['then'](function(){if(_0x387f68!==0x194){return db[_0x8c91('0x23')][_0x8c91('0x58')]({'where':{'isApp':!![],'VoiceExtensionId':_0x4330a5},'order':_0x8c91('0x59')})[_0x8c91('0x1f')](function(_0x33d86e){_0x24bf49=_0x33d86e;});}})[_0x8c91('0x37')](function(_0x2412f2){_0x387f68=0x1f4;logger['error'](_0x2412f2['stack']);if(_0x2412f2['name']){delete _0x2412f2[_0x8c91('0x1d')];}_0x24bf49=_0x2412f2;})[_0x8c91('0x5a')](function(){if(_0x24bf49===null){_0x489f1f[_0x8c91('0xa')](_0x387f68);}else{if(_0x387f68===0x1f4){_0x489f1f[_0x8c91('0xc')](_0x387f68)[_0x8c91('0x21')](_0x24bf49);}else{_0x489f1f['status'](_0x387f68)['json'](_0x24bf49);}}});};