Built motion from commit d5e4af8c.|2.6.23
[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 _0x3844=['rows','catch','show','params','rawAttributes','options','create','body','startsWith','exten','concat','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','InboundRoutes','OutboundRoutes','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','pick','context','description','recordingFormat','cutdigits','addApplications','sequelize','transaction','Transaction','findOne','VoiceExtensionId','isApp','bulkCreate','findAndCountAll','cast(priority\x20as\x20unsigned)','finally','lodash','../../components/parsers/qs','../../config/logger','../../mysqldb','redis','defaults','socket.io-emitter','./voiceExtension.socket','register','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','destroy','inbound','outbound','InternalRoutes','internal','map','value','includes','type','find','name','UserProfileResource','then','end','error','stack','send','index','VoiceExtension','fieldName','key','model','keys','query','filters','intersection','fields','attributes','length','nolimit','order','sort','where','filter','merge','VIRTUAL','findAll'];(function(_0x5db974,_0x45126b){var _0x32b019=function(_0x49ddd7){while(--_0x49ddd7){_0x5db974['push'](_0x5db974['shift']());}};_0x32b019(++_0x45126b);}(_0x3844,0x83));var _0x4384=function(_0x4e8c09,_0x38eae6){_0x4e8c09=_0x4e8c09-0x0;var _0x5aca42=_0x3844[_0x4e8c09];return _0x5aca42;};'use strict';var _=require(_0x4384('0x0'));var Redis=require('ioredis');var qs=require(_0x4384('0x1'));var logger=require(_0x4384('0x2'))('api');var config=require('../../config/environment');var db=require(_0x4384('0x3'))['db'];config[_0x4384('0x4')]=_[_0x4384('0x5')](config[_0x4384('0x4')],{'host':'localhost','port':0x18eb});var socket=require(_0x4384('0x6'))(new Redis(config[_0x4384('0x4')]));require(_0x4384('0x7'))[_0x4384('0x8')](socket);function respondWithStatusCode(_0x3bf52e,_0x967cdf){_0x967cdf=_0x967cdf||0xcc;return function(_0x4dd03f){if(_0x4dd03f){return _0x3bf52e[_0x4384('0x9')](_0x967cdf);}return _0x3bf52e[_0x4384('0xa')](_0x967cdf)['end']();};}function respondWithResult(_0x4ebb0c,_0x502b16){_0x502b16=_0x502b16||0xc8;return function(_0x3369a6){if(_0x3369a6){return _0x4ebb0c['status'](_0x502b16)[_0x4384('0xb')](_0x3369a6);}};}function respondWithFilteredResult(_0xf3f1af,_0x82b305){return function(_0x21deaa){if(_0x21deaa){var _0xcfa3ee=typeof _0x82b305[_0x4384('0xc')]===_0x4384('0xd')&&typeof _0x82b305[_0x4384('0xe')]==='undefined';var _0x83181=_0x21deaa[_0x4384('0xf')];var _0x48f453=_0xcfa3ee?0x0:_0x82b305[_0x4384('0xc')];var _0x8aa6da=_0xcfa3ee?_0x21deaa[_0x4384('0xf')]:_0x82b305[_0x4384('0xc')]+_0x82b305[_0x4384('0xe')];var _0x44c091;if(_0x8aa6da>=_0x83181){_0x8aa6da=_0x83181;_0x44c091=0xc8;}else{_0x44c091=0xce;}_0xf3f1af[_0x4384('0xa')](_0x44c091);return _0xf3f1af[_0x4384('0x10')](_0x4384('0x11'),_0x48f453+'-'+_0x8aa6da+'/'+_0x83181)['json'](_0x21deaa);}return null;};}function removeEntity(_0x50279d){return function(_0x4785e5){if(_0x4785e5){return _0x4785e5[_0x4384('0x12')]()['then'](function(){var _0x2edf33=_0x4785e5['get']({'plain':!![]});var _0x454bab=[{'name':'InboundRoutes','value':_0x4384('0x13'),'ignore':![]},{'name':'OutboundRoutes','value':_0x4384('0x14'),'ignore':![]},{'name':_0x4384('0x15'),'value':_0x4384('0x16'),'ignore':![]}];var _0x372a50=_(_0x454bab)['filter']('ignore')[_0x4384('0x17')](_0x4384('0x18'))[_0x4384('0x18')]();if(_[_0x4384('0x19')](_0x372a50,_0x2edf33[_0x4384('0x1a')])){return;}var _0x4cc7cb=_[_0x4384('0x1b')](_0x454bab,[_0x4384('0x18'),_0x2edf33['type']])[_0x4384('0x1c')];return db[_0x4384('0x1d')][_0x4384('0x12')]({'where':{'type':_0x4cc7cb,'resourceId':_0x2edf33['id']}})[_0x4384('0x1e')](function(){return _0x4785e5;});})[_0x4384('0x1e')](function(){_0x50279d[_0x4384('0xa')](0xcc)[_0x4384('0x1f')]();});}};}function handleEntityNotFound(_0x22f750){return function(_0x4cfce9){if(!_0x4cfce9){_0x22f750[_0x4384('0x9')](0x194);}return _0x4cfce9;};}function handleError(_0x3ce101,_0x1fa40e){_0x1fa40e=_0x1fa40e||0x1f4;return function(_0x234824){logger[_0x4384('0x20')](_0x234824[_0x4384('0x21')]);if(_0x234824[_0x4384('0x1c')]){delete _0x234824[_0x4384('0x1c')];}_0x3ce101[_0x4384('0xa')](_0x1fa40e)[_0x4384('0x22')](_0x234824);};}exports[_0x4384('0x23')]=function(_0x2835b9,_0x3bd58b){var _0x4351fc={},_0x28f295={},_0x4c2eee={'count':0x0,'rows':[]};var _0x2ec64a=_[_0x4384('0x17')](db[_0x4384('0x24')]['rawAttributes'],function(_0x5614bc){return{'name':_0x5614bc[_0x4384('0x25')],'type':_0x5614bc['type'][_0x4384('0x26')]};});_0x28f295[_0x4384('0x27')]=_[_0x4384('0x17')](_0x2ec64a,_0x4384('0x1c'));_0x28f295['query']=_[_0x4384('0x28')](_0x2835b9[_0x4384('0x29')]);_0x28f295[_0x4384('0x2a')]=_[_0x4384('0x2b')](_0x28f295['model'],_0x28f295[_0x4384('0x29')]);_0x4351fc['attributes']=_[_0x4384('0x2b')](_0x28f295[_0x4384('0x27')],qs[_0x4384('0x2c')](_0x2835b9[_0x4384('0x29')]['fields']));_0x4351fc[_0x4384('0x2d')]=_0x4351fc['attributes'][_0x4384('0x2e')]?_0x4351fc[_0x4384('0x2d')]:_0x28f295['model'];if(!_0x2835b9[_0x4384('0x29')]['hasOwnProperty'](_0x4384('0x2f'))){_0x4351fc[_0x4384('0xe')]=qs[_0x4384('0xe')](_0x2835b9[_0x4384('0x29')]['limit']);_0x4351fc[_0x4384('0xc')]=qs[_0x4384('0xc')](_0x2835b9[_0x4384('0x29')][_0x4384('0xc')]);}_0x4351fc[_0x4384('0x30')]=qs[_0x4384('0x31')](_0x2835b9[_0x4384('0x29')][_0x4384('0x31')]);_0x4351fc[_0x4384('0x32')]=qs[_0x4384('0x2a')](_['pick'](_0x2835b9[_0x4384('0x29')],_0x28f295['filters']),_0x2ec64a);if(_0x2835b9['query'][_0x4384('0x33')]){_0x4351fc[_0x4384('0x32')]=_[_0x4384('0x34')](_0x4351fc[_0x4384('0x32')],{'$or':_['map'](_0x2ec64a,function(_0x2dd033){if(_0x2dd033[_0x4384('0x1a')]!==_0x4384('0x35')){var _0x4a32d0={};_0x4a32d0[_0x2dd033['name']]={'$like':'%'+_0x2835b9[_0x4384('0x29')][_0x4384('0x33')]+'%'};return _0x4a32d0;}})});}_0x4351fc=_['merge']({},_0x4351fc,_0x2835b9['options']);var _0x5b97b4={'where':_0x4351fc[_0x4384('0x32')]};return db[_0x4384('0x24')]['count'](_0x5b97b4)['then'](function(_0x2a8eba){_0x4c2eee['count']=_0x2a8eba;if(_0x2835b9[_0x4384('0x29')]['includeAll']){_0x4351fc['include']=[{'all':!![]}];}return db['VoiceExtension'][_0x4384('0x36')](_0x4351fc);})[_0x4384('0x1e')](function(_0x5a4659){_0x4c2eee[_0x4384('0x37')]=_0x5a4659;return _0x4c2eee;})[_0x4384('0x1e')](respondWithFilteredResult(_0x3bd58b,_0x4351fc))[_0x4384('0x38')](handleError(_0x3bd58b,null));};exports[_0x4384('0x39')]=function(_0x2a156e,_0x5d7df1){var _0x5c9bde={'raw':![],'where':{'id':_0x2a156e[_0x4384('0x3a')]['id']}},_0x3c04f8={};_0x3c04f8[_0x4384('0x27')]=_['keys'](db[_0x4384('0x24')][_0x4384('0x3b')]);_0x3c04f8[_0x4384('0x29')]=_[_0x4384('0x28')](_0x2a156e['query']);_0x3c04f8['filters']=_[_0x4384('0x2b')](_0x3c04f8[_0x4384('0x27')],_0x3c04f8[_0x4384('0x29')]);_0x5c9bde[_0x4384('0x2d')]=_[_0x4384('0x2b')](_0x3c04f8[_0x4384('0x27')],qs[_0x4384('0x2c')](_0x2a156e[_0x4384('0x29')][_0x4384('0x2c')]));_0x5c9bde[_0x4384('0x2d')]=_0x5c9bde[_0x4384('0x2d')][_0x4384('0x2e')]?_0x5c9bde['attributes']:_0x3c04f8[_0x4384('0x27')];if(_0x2a156e['query']['includeAll']){_0x5c9bde['include']=[{'all':!![]}];}_0x5c9bde=_[_0x4384('0x34')]({},_0x5c9bde,_0x2a156e[_0x4384('0x3c')]);return db[_0x4384('0x24')]['find'](_0x5c9bde)[_0x4384('0x1e')](handleEntityNotFound(_0x5d7df1,null))[_0x4384('0x1e')](respondWithResult(_0x5d7df1,null))['catch'](handleError(_0x5d7df1,null));};exports[_0x4384('0x12')]=function(_0x21be65,_0x4672f5){return db['VoiceExtension'][_0x4384('0x1b')]({'where':{'id':_0x21be65['params']['id']}})[_0x4384('0x1e')](handleEntityNotFound(_0x4672f5,null))[_0x4384('0x1e')](removeEntity(_0x4672f5,null))[_0x4384('0x38')](handleError(_0x4672f5,null));};exports[_0x4384('0x3d')]=function(_0x5b7a31,_0x159750){if(_0x5b7a31[_0x4384('0x3e')][_0x4384('0x1a')]===_0x4384('0x14')&&!_[_0x4384('0x3f')](_0x5b7a31[_0x4384('0x3e')][_0x4384('0x40')],'_')){_0x5b7a31[_0x4384('0x3e')][_0x4384('0x40')]='_'[_0x4384('0x41')](_0x5b7a31[_0x4384('0x3e')][_0x4384('0x40')]);}return db[_0x4384('0x24')][_0x4384('0x3d')](_0x5b7a31[_0x4384('0x3e')],{'raw':![]})['then'](function(_0x2eba53){var _0x509ac5=_0x5b7a31['user'][_0x4384('0x42')]({'plain':!![]});if(!_0x509ac5)throw new Error(_0x4384('0x43'));if(_0x509ac5[_0x4384('0x44')]===_0x4384('0x45')){var _0x28352a=_0x2eba53[_0x4384('0x42')]({'plain':!![]});var _0x5249c6=[{'name':_0x4384('0x46'),'value':_0x4384('0x13')},{'name':_0x4384('0x47'),'value':_0x4384('0x14')},{'name':_0x4384('0x15'),'value':_0x4384('0x16')}];var _0x4083c2=_['find'](_0x5249c6,[_0x4384('0x18'),_0x28352a['type']])[_0x4384('0x1c')];return db[_0x4384('0x48')][_0x4384('0x1b')]({'where':{'name':_0x4083c2,'userProfileId':_0x509ac5[_0x4384('0x49')]},'raw':!![]})[_0x4384('0x1e')](function(_0x39f750){if(_0x39f750&&_0x39f750[_0x4384('0x4a')]===0x0){return db['UserProfileResource'][_0x4384('0x3d')]({'name':_0x28352a[_0x4384('0x1c')],'resourceId':_0x28352a['id'],'type':_0x39f750['name'],'sectionId':_0x39f750['id']},{})[_0x4384('0x1e')](function(){return _0x2eba53;});}else{return _0x2eba53;}})[_0x4384('0x38')](function(_0x2c0e53){logger[_0x4384('0x20')](_0x4384('0x4b'),_0x2c0e53);throw _0x2c0e53;});}return _0x2eba53;})[_0x4384('0x1e')](respondWithResult(_0x159750,0xc9))[_0x4384('0x38')](handleError(_0x159750,null));};exports[_0x4384('0x4c')]=function(_0x487f87,_0x7b46ad){if(_0x487f87[_0x4384('0x3e')]['id']){delete _0x487f87[_0x4384('0x3e')]['id'];}return db['VoiceExtension'][_0x4384('0x1b')]({'where':{'id':_0x487f87['params']['id']}})['then'](handleEntityNotFound(_0x7b46ad,null))['then'](function(_0x514391){if(_0x514391){return db['VoiceExtension'][_0x4384('0x4c')](_[_0x4384('0x4d')](_0x487f87[_0x4384('0x3e')],['exten',_0x4384('0x4e'),_0x4384('0x4f'),_0x4384('0x50'),_0x4384('0x51'),'mandatoryDisposition','alias']),{'where':{'context':_0x514391['context'],'exten':_0x514391[_0x4384('0x40')]},'individualHooks':!![]})[_0x4384('0x1e')](function(_0x4a91f0){return _0x4a91f0;});}return null;})[_0x4384('0x1e')](respondWithStatusCode(_0x7b46ad,null))[_0x4384('0x38')](handleError(_0x7b46ad,null));};exports[_0x4384('0x52')]=function(_0x493aa4,_0x353205){var _0x1ed6c0=_0x493aa4['params']['id'];var _0x1f6c7a=_0x493aa4[_0x4384('0x3e')];var _0x5f42d4=0xc8;var _0x2fc282=null;return db[_0x4384('0x53')][_0x4384('0x54')]({'isolationLevel':db[_0x4384('0x53')][_0x4384('0x55')]['ISOLATION_LEVELS']['READ_COMMITTED']},function(_0x3832ba){return db[_0x4384('0x24')][_0x4384('0x56')]({'where':{'id':_0x1ed6c0},'transaction':_0x3832ba})[_0x4384('0x1e')](function(_0x34cced){if(_0x34cced){return db[_0x4384('0x24')]['destroy']({'where':{'VoiceExtensionId':_0x1ed6c0},'transaction':_0x3832ba})['then'](function(){var _0x446ba0=_['map'](_0x1f6c7a,function(_0x271685){_0x271685[_0x4384('0x57')]=_0x1ed6c0;_0x271685[_0x4384('0x58')]=!![];return _0x271685;});return _0x34cced['createRouting'](_0x446ba0);})[_0x4384('0x1e')](function(_0x49d5c9){return db[_0x4384('0x24')][_0x4384('0x59')](_0x49d5c9,{'transaction':_0x3832ba});});}else{_0x5f42d4=0x194;_0x2fc282=[];}});})[_0x4384('0x1e')](function(){if(_0x5f42d4!==0x194){return db[_0x4384('0x24')][_0x4384('0x5a')]({'where':{'isApp':!![],'VoiceExtensionId':_0x1ed6c0},'order':_0x4384('0x5b')})[_0x4384('0x1e')](function(_0x1aac24){_0x2fc282=_0x1aac24;});}})['catch'](function(_0x3141ad){_0x5f42d4=0x1f4;logger['error'](_0x3141ad['stack']);if(_0x3141ad[_0x4384('0x1c')]){delete _0x3141ad[_0x4384('0x1c')];}_0x2fc282=_0x3141ad;})[_0x4384('0x5c')](function(){if(_0x2fc282===null){_0x353205[_0x4384('0x9')](_0x5f42d4);}else{if(_0x5f42d4===0x1f4){_0x353205[_0x4384('0xa')](_0x5f42d4)['send'](_0x2fc282);}else{_0x353205[_0x4384('0xa')](_0x5f42d4)['json'](_0x2fc282);}}});};