eb7b4ced9e220d71c6215be3f30a87b46953c9f4
[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 _0xb4b0=['addApplications','transaction','sequelize','Transaction','VoiceExtensionId','isApp','createRouting','bulkCreate','findAndCountAll','cast(priority\x20as\x20unsigned)','ioredis','../../components/parsers/qs','api','../../config/environment','redis','defaults','localhost','./voiceExtension.socket','register','status','end','undefined','limit','offset','count','json','destroy','then','get','InboundRoutes','inbound','OutboundRoutes','outbound','InternalRoutes','internal','ignore','map','includes','find','value','UserProfileResource','sendStatus','stack','name','send','index','VoiceExtension','rawAttributes','fieldName','type','model','keys','query','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','filter','VIRTUAL','merge','options','includeAll','include','findAll','rows','show','params','catch','body','startsWith','exten','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','pick','context','description','recordingFormat','mandatoryDisposition'];(function(_0x4ae6ef,_0xc2af80){var _0x3cbb4e=function(_0x569ad5){while(--_0x569ad5){_0x4ae6ef['push'](_0x4ae6ef['shift']());}};_0x3cbb4e(++_0xc2af80);}(_0xb4b0,0xbc));var _0x0b4b=function(_0x24b156,_0x6e3d6){_0x24b156=_0x24b156-0x0;var _0x1fa205=_0xb4b0[_0x24b156];return _0x1fa205;};'use strict';var _=require('lodash');var Redis=require(_0x0b4b('0x0'));var qs=require(_0x0b4b('0x1'));var logger=require('../../config/logger')(_0x0b4b('0x2'));var config=require(_0x0b4b('0x3'));var db=require('../../mysqldb')['db'];config[_0x0b4b('0x4')]=_[_0x0b4b('0x5')](config[_0x0b4b('0x4')],{'host':_0x0b4b('0x6'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x0b4b('0x7'))[_0x0b4b('0x8')](socket);function respondWithStatusCode(_0x14144b,_0x536187){_0x536187=_0x536187||0xcc;return function(_0xb9acd5){if(_0xb9acd5){return _0x14144b['sendStatus'](_0x536187);}return _0x14144b[_0x0b4b('0x9')](_0x536187)[_0x0b4b('0xa')]();};}function respondWithResult(_0x21736b,_0x31f7cc){_0x31f7cc=_0x31f7cc||0xc8;return function(_0xb6c465){if(_0xb6c465){return _0x21736b['status'](_0x31f7cc)['json'](_0xb6c465);}};}function respondWithFilteredResult(_0x1c28fe,_0x569a91){return function(_0x5a88ff){if(_0x5a88ff){var _0x418309=typeof _0x569a91['offset']===_0x0b4b('0xb')&&typeof _0x569a91[_0x0b4b('0xc')]===_0x0b4b('0xb');var _0x4074b1=_0x5a88ff['count'];var _0x550125=_0x418309?0x0:_0x569a91[_0x0b4b('0xd')];var _0x145b79=_0x418309?_0x5a88ff[_0x0b4b('0xe')]:_0x569a91[_0x0b4b('0xd')]+_0x569a91[_0x0b4b('0xc')];var _0x13ce3e;if(_0x145b79>=_0x4074b1){_0x145b79=_0x4074b1;_0x13ce3e=0xc8;}else{_0x13ce3e=0xce;}_0x1c28fe[_0x0b4b('0x9')](_0x13ce3e);return _0x1c28fe['set']('Content-Range',_0x550125+'-'+_0x145b79+'/'+_0x4074b1)[_0x0b4b('0xf')](_0x5a88ff);}return null;};}function removeEntity(_0x56bdb9){return function(_0x28fda7){if(_0x28fda7){return _0x28fda7[_0x0b4b('0x10')]()[_0x0b4b('0x11')](function(){var _0x132871=_0x28fda7[_0x0b4b('0x12')]({'plain':!![]});var _0x2ad73c=[{'name':_0x0b4b('0x13'),'value':_0x0b4b('0x14'),'ignore':![]},{'name':_0x0b4b('0x15'),'value':_0x0b4b('0x16'),'ignore':![]},{'name':_0x0b4b('0x17'),'value':_0x0b4b('0x18'),'ignore':![]}];var _0x5164fc=_(_0x2ad73c)['filter'](_0x0b4b('0x19'))[_0x0b4b('0x1a')]('value')['value']();if(_[_0x0b4b('0x1b')](_0x5164fc,_0x132871['type'])){return;}var _0x16c0ee=_[_0x0b4b('0x1c')](_0x2ad73c,[_0x0b4b('0x1d'),_0x132871['type']])['name'];return db[_0x0b4b('0x1e')][_0x0b4b('0x10')]({'where':{'type':_0x16c0ee,'resourceId':_0x132871['id']}})['then'](function(){return _0x28fda7;});})['then'](function(){_0x56bdb9['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x203377){return function(_0x1549af){if(!_0x1549af){_0x203377[_0x0b4b('0x1f')](0x194);}return _0x1549af;};}function handleError(_0x36e702,_0x268d7e){_0x268d7e=_0x268d7e||0x1f4;return function(_0x1d93e4){logger['error'](_0x1d93e4[_0x0b4b('0x20')]);if(_0x1d93e4[_0x0b4b('0x21')]){delete _0x1d93e4['name'];}_0x36e702[_0x0b4b('0x9')](_0x268d7e)[_0x0b4b('0x22')](_0x1d93e4);};}exports[_0x0b4b('0x23')]=function(_0x2887ad,_0x479b3f){var _0x454066={},_0xae566a={},_0x5a1282={'count':0x0,'rows':[]};var _0x1e9aee=_['map'](db[_0x0b4b('0x24')][_0x0b4b('0x25')],function(_0x4954ec){return{'name':_0x4954ec[_0x0b4b('0x26')],'type':_0x4954ec[_0x0b4b('0x27')]['key']};});_0xae566a[_0x0b4b('0x28')]=_[_0x0b4b('0x1a')](_0x1e9aee,'name');_0xae566a['query']=_[_0x0b4b('0x29')](_0x2887ad[_0x0b4b('0x2a')]);_0xae566a['filters']=_['intersection'](_0xae566a[_0x0b4b('0x28')],_0xae566a[_0x0b4b('0x2a')]);_0x454066[_0x0b4b('0x2b')]=_[_0x0b4b('0x2c')](_0xae566a[_0x0b4b('0x28')],qs[_0x0b4b('0x2d')](_0x2887ad[_0x0b4b('0x2a')][_0x0b4b('0x2d')]));_0x454066[_0x0b4b('0x2b')]=_0x454066[_0x0b4b('0x2b')][_0x0b4b('0x2e')]?_0x454066[_0x0b4b('0x2b')]:_0xae566a[_0x0b4b('0x28')];if(!_0x2887ad[_0x0b4b('0x2a')][_0x0b4b('0x2f')](_0x0b4b('0x30'))){_0x454066['limit']=qs[_0x0b4b('0xc')](_0x2887ad['query'][_0x0b4b('0xc')]);_0x454066['offset']=qs['offset'](_0x2887ad[_0x0b4b('0x2a')]['offset']);}_0x454066[_0x0b4b('0x31')]=qs['sort'](_0x2887ad[_0x0b4b('0x2a')][_0x0b4b('0x32')]);_0x454066[_0x0b4b('0x33')]=qs[_0x0b4b('0x34')](_['pick'](_0x2887ad['query'],_0xae566a[_0x0b4b('0x34')]),_0x1e9aee);if(_0x2887ad[_0x0b4b('0x2a')][_0x0b4b('0x35')]){_0x454066['where']=_['merge'](_0x454066[_0x0b4b('0x33')],{'$or':_[_0x0b4b('0x1a')](_0x1e9aee,function(_0x70237b){if(_0x70237b['type']!==_0x0b4b('0x36')){var _0x5e79f1={};_0x5e79f1[_0x70237b[_0x0b4b('0x21')]]={'$like':'%'+_0x2887ad[_0x0b4b('0x2a')][_0x0b4b('0x35')]+'%'};return _0x5e79f1;}})});}_0x454066=_[_0x0b4b('0x37')]({},_0x454066,_0x2887ad[_0x0b4b('0x38')]);var _0x32bde5={'where':_0x454066[_0x0b4b('0x33')]};return db[_0x0b4b('0x24')]['count'](_0x32bde5)[_0x0b4b('0x11')](function(_0x225f20){_0x5a1282['count']=_0x225f20;if(_0x2887ad[_0x0b4b('0x2a')][_0x0b4b('0x39')]){_0x454066[_0x0b4b('0x3a')]=[{'all':!![]}];}return db['VoiceExtension'][_0x0b4b('0x3b')](_0x454066);})[_0x0b4b('0x11')](function(_0x570515){_0x5a1282[_0x0b4b('0x3c')]=_0x570515;return _0x5a1282;})[_0x0b4b('0x11')](respondWithFilteredResult(_0x479b3f,_0x454066))['catch'](handleError(_0x479b3f,null));};exports[_0x0b4b('0x3d')]=function(_0x45a61e,_0x77434c){var _0x15fbe3={'raw':![],'where':{'id':_0x45a61e[_0x0b4b('0x3e')]['id']}},_0x4251b8={};_0x4251b8[_0x0b4b('0x28')]=_[_0x0b4b('0x29')](db[_0x0b4b('0x24')][_0x0b4b('0x25')]);_0x4251b8[_0x0b4b('0x2a')]=_[_0x0b4b('0x29')](_0x45a61e['query']);_0x4251b8[_0x0b4b('0x34')]=_[_0x0b4b('0x2c')](_0x4251b8[_0x0b4b('0x28')],_0x4251b8['query']);_0x15fbe3[_0x0b4b('0x2b')]=_[_0x0b4b('0x2c')](_0x4251b8[_0x0b4b('0x28')],qs[_0x0b4b('0x2d')](_0x45a61e['query']['fields']));_0x15fbe3['attributes']=_0x15fbe3[_0x0b4b('0x2b')]['length']?_0x15fbe3['attributes']:_0x4251b8[_0x0b4b('0x28')];if(_0x45a61e['query']['includeAll']){_0x15fbe3['include']=[{'all':!![]}];}_0x15fbe3=_['merge']({},_0x15fbe3,_0x45a61e[_0x0b4b('0x38')]);return db[_0x0b4b('0x24')][_0x0b4b('0x1c')](_0x15fbe3)[_0x0b4b('0x11')](handleEntityNotFound(_0x77434c,null))[_0x0b4b('0x11')](respondWithResult(_0x77434c,null))[_0x0b4b('0x3f')](handleError(_0x77434c,null));};exports['destroy']=function(_0x8f864e,_0x391de5){return db[_0x0b4b('0x24')][_0x0b4b('0x1c')]({'where':{'id':_0x8f864e[_0x0b4b('0x3e')]['id']}})[_0x0b4b('0x11')](handleEntityNotFound(_0x391de5,null))[_0x0b4b('0x11')](removeEntity(_0x391de5,null))[_0x0b4b('0x3f')](handleError(_0x391de5,null));};exports['create']=function(_0x4e5df5,_0x44e1d5){if(_0x4e5df5[_0x0b4b('0x40')][_0x0b4b('0x27')]===_0x0b4b('0x16')&&!_[_0x0b4b('0x41')](_0x4e5df5[_0x0b4b('0x40')]['exten'],'_')){_0x4e5df5[_0x0b4b('0x40')][_0x0b4b('0x42')]='_'['concat'](_0x4e5df5[_0x0b4b('0x40')][_0x0b4b('0x42')]);}return db[_0x0b4b('0x24')]['create'](_0x4e5df5['body'],{'raw':![]})[_0x0b4b('0x11')](function(_0x23fb40){var _0x42737e=_0x4e5df5[_0x0b4b('0x43')]['get']({'plain':!![]});if(!_0x42737e)throw new Error(_0x0b4b('0x44'));if(_0x42737e[_0x0b4b('0x45')]===_0x0b4b('0x43')){var _0x396da6=_0x23fb40[_0x0b4b('0x12')]({'plain':!![]});var _0xb47575=[{'name':'InboundRoutes','value':_0x0b4b('0x14')},{'name':_0x0b4b('0x15'),'value':_0x0b4b('0x16')},{'name':'InternalRoutes','value':_0x0b4b('0x18')}];var _0x3ceeaf=_[_0x0b4b('0x1c')](_0xb47575,[_0x0b4b('0x1d'),_0x396da6['type']])[_0x0b4b('0x21')];return db['UserProfileSection']['find']({'where':{'name':_0x3ceeaf,'userProfileId':_0x42737e[_0x0b4b('0x46')]},'raw':!![]})[_0x0b4b('0x11')](function(_0x2c61fd){if(_0x2c61fd&&_0x2c61fd[_0x0b4b('0x47')]===0x0){return db[_0x0b4b('0x1e')]['create']({'name':_0x396da6[_0x0b4b('0x21')],'resourceId':_0x396da6['id'],'type':_0x2c61fd['name'],'sectionId':_0x2c61fd['id']},{})['then'](function(){return _0x23fb40;});}else{return _0x23fb40;}})[_0x0b4b('0x3f')](function(_0x4aeb5f){logger['error'](_0x0b4b('0x48'),_0x4aeb5f);throw _0x4aeb5f;});}return _0x23fb40;})[_0x0b4b('0x11')](respondWithResult(_0x44e1d5,0xc9))[_0x0b4b('0x3f')](handleError(_0x44e1d5,null));};exports[_0x0b4b('0x49')]=function(_0x234d93,_0x2495ae){if(_0x234d93['body']['id']){delete _0x234d93[_0x0b4b('0x40')]['id'];}return db[_0x0b4b('0x24')]['find']({'where':{'id':_0x234d93['params']['id']}})[_0x0b4b('0x11')](handleEntityNotFound(_0x2495ae,null))['then'](function(_0xd64771){if(_0xd64771){return db[_0x0b4b('0x24')][_0x0b4b('0x49')](_[_0x0b4b('0x4a')](_0x234d93[_0x0b4b('0x40')],[_0x0b4b('0x42'),_0x0b4b('0x4b'),_0x0b4b('0x4c'),_0x0b4b('0x4d'),'cutdigits',_0x0b4b('0x4e'),'alias']),{'where':{'context':_0xd64771[_0x0b4b('0x4b')],'exten':_0xd64771[_0x0b4b('0x42')]},'individualHooks':!![]})[_0x0b4b('0x11')](function(_0x38522a){return _0x38522a;});}return null;})[_0x0b4b('0x11')](respondWithStatusCode(_0x2495ae,null))[_0x0b4b('0x3f')](handleError(_0x2495ae,null));};exports[_0x0b4b('0x4f')]=function(_0x55d085,_0x576810){var _0x196321=_0x55d085[_0x0b4b('0x3e')]['id'];var _0x5e4db0=_0x55d085[_0x0b4b('0x40')];var _0x4a9229=0xc8;var _0x370e2b=null;return db['sequelize'][_0x0b4b('0x50')]({'isolationLevel':db[_0x0b4b('0x51')][_0x0b4b('0x52')]['ISOLATION_LEVELS']['READ_COMMITTED']},function(_0xb82f61){return db['VoiceExtension']['findOne']({'where':{'id':_0x196321},'transaction':_0xb82f61})[_0x0b4b('0x11')](function(_0x48d5f3){if(_0x48d5f3){return db['VoiceExtension'][_0x0b4b('0x10')]({'where':{'VoiceExtensionId':_0x196321},'transaction':_0xb82f61})[_0x0b4b('0x11')](function(){var _0x28cc15=_[_0x0b4b('0x1a')](_0x5e4db0,function(_0x278a47){_0x278a47[_0x0b4b('0x53')]=_0x196321;_0x278a47[_0x0b4b('0x54')]=!![];return _0x278a47;});return _0x48d5f3[_0x0b4b('0x55')](_0x28cc15);})[_0x0b4b('0x11')](function(_0x165bbb){return db[_0x0b4b('0x24')][_0x0b4b('0x56')](_0x165bbb,{'transaction':_0xb82f61});});}else{_0x4a9229=0x194;_0x370e2b=[];}});})[_0x0b4b('0x11')](function(){if(_0x4a9229!==0x194){return db[_0x0b4b('0x24')][_0x0b4b('0x57')]({'where':{'isApp':!![],'VoiceExtensionId':_0x196321},'order':_0x0b4b('0x58')})[_0x0b4b('0x11')](function(_0x4834b5){_0x370e2b=_0x4834b5;});}})[_0x0b4b('0x3f')](function(_0x3b4957){_0x4a9229=0x1f4;logger['error'](_0x3b4957[_0x0b4b('0x20')]);if(_0x3b4957['name']){delete _0x3b4957[_0x0b4b('0x21')];}_0x370e2b=_0x3b4957;})['finally'](function(){if(_0x370e2b===null){_0x576810[_0x0b4b('0x1f')](_0x4a9229);}else{if(_0x4a9229===0x1f4){_0x576810[_0x0b4b('0x9')](_0x4a9229)[_0x0b4b('0x22')](_0x370e2b);}else{_0x576810[_0x0b4b('0x9')](_0x4a9229)[_0x0b4b('0xf')](_0x370e2b);}}});};