Built motion from commit ff78e754.|2.6.29
[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 _0x3ff9=['api','../../config/environment','../../mysqldb','defaults','redis','socket.io-emitter','./voiceExtension.socket','register','sendStatus','status','end','json','offset','limit','set','Content-Range','destroy','then','get','OutboundRoutes','outbound','InternalRoutes','internal','ignore','map','value','includes','type','find','name','UserProfileResource','error','stack','send','index','VoiceExtension','fieldName','model','query','filters','attributes','fields','hasOwnProperty','order','sort','where','pick','filter','VIRTUAL','merge','options','count','includeAll','include','findAll','rows','catch','params','rawAttributes','keys','intersection','create','body','startsWith','exten','concat','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','inbound','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','context','description','cutdigits','addApplications','sequelize','Transaction','findOne','VoiceExtensionId','bulkCreate','findAndCountAll','cast(priority\x20as\x20unsigned)','finally','ioredis','../../components/parsers/qs','../../config/logger'];(function(_0x371ea9,_0x4c0b76){var _0x31133f=function(_0x389edc){while(--_0x389edc){_0x371ea9['push'](_0x371ea9['shift']());}};_0x31133f(++_0x4c0b76);}(_0x3ff9,0xb1));var _0x93ff=function(_0x199572,_0x33e667){_0x199572=_0x199572-0x0;var _0x13cfa3=_0x3ff9[_0x199572];return _0x13cfa3;};'use strict';var _=require('lodash');var Redis=require(_0x93ff('0x0'));var qs=require(_0x93ff('0x1'));var logger=require(_0x93ff('0x2'))(_0x93ff('0x3'));var config=require(_0x93ff('0x4'));var db=require(_0x93ff('0x5'))['db'];config['redis']=_[_0x93ff('0x6')](config[_0x93ff('0x7')],{'host':'localhost','port':0x18eb});var socket=require(_0x93ff('0x8'))(new Redis(config[_0x93ff('0x7')]));require(_0x93ff('0x9'))[_0x93ff('0xa')](socket);function respondWithStatusCode(_0x3ad9e1,_0x332a66){_0x332a66=_0x332a66||0xcc;return function(_0x3d6298){if(_0x3d6298){return _0x3ad9e1[_0x93ff('0xb')](_0x332a66);}return _0x3ad9e1[_0x93ff('0xc')](_0x332a66)[_0x93ff('0xd')]();};}function respondWithResult(_0x3359,_0x52f2d7){_0x52f2d7=_0x52f2d7||0xc8;return function(_0x2e1fc9){if(_0x2e1fc9){return _0x3359[_0x93ff('0xc')](_0x52f2d7)[_0x93ff('0xe')](_0x2e1fc9);}};}function respondWithFilteredResult(_0x2dfd19,_0x5660f4){return function(_0x3dbdb9){if(_0x3dbdb9){var _0x167040=typeof _0x5660f4[_0x93ff('0xf')]==='undefined'&&typeof _0x5660f4[_0x93ff('0x10')]==='undefined';var _0x5ef281=_0x3dbdb9['count'];var _0x1765b9=_0x167040?0x0:_0x5660f4[_0x93ff('0xf')];var _0x305c01=_0x167040?_0x3dbdb9['count']:_0x5660f4[_0x93ff('0xf')]+_0x5660f4['limit'];var _0x54bdd6;if(_0x305c01>=_0x5ef281){_0x305c01=_0x5ef281;_0x54bdd6=0xc8;}else{_0x54bdd6=0xce;}_0x2dfd19[_0x93ff('0xc')](_0x54bdd6);return _0x2dfd19[_0x93ff('0x11')](_0x93ff('0x12'),_0x1765b9+'-'+_0x305c01+'/'+_0x5ef281)[_0x93ff('0xe')](_0x3dbdb9);}return null;};}function removeEntity(_0x26b535){return function(_0x4949d2){if(_0x4949d2){return _0x4949d2[_0x93ff('0x13')]()[_0x93ff('0x14')](function(){var _0x2c5e4f=_0x4949d2[_0x93ff('0x15')]({'plain':!![]});var _0x2a305b=[{'name':'InboundRoutes','value':'inbound','ignore':![]},{'name':_0x93ff('0x16'),'value':_0x93ff('0x17'),'ignore':![]},{'name':_0x93ff('0x18'),'value':_0x93ff('0x19'),'ignore':![]}];var _0x29e262=_(_0x2a305b)['filter'](_0x93ff('0x1a'))[_0x93ff('0x1b')](_0x93ff('0x1c'))[_0x93ff('0x1c')]();if(_[_0x93ff('0x1d')](_0x29e262,_0x2c5e4f[_0x93ff('0x1e')])){return;}var _0x2de0f7=_[_0x93ff('0x1f')](_0x2a305b,[_0x93ff('0x1c'),_0x2c5e4f[_0x93ff('0x1e')]])[_0x93ff('0x20')];return db[_0x93ff('0x21')][_0x93ff('0x13')]({'where':{'type':_0x2de0f7,'resourceId':_0x2c5e4f['id']}})['then'](function(){return _0x4949d2;});})[_0x93ff('0x14')](function(){_0x26b535[_0x93ff('0xc')](0xcc)[_0x93ff('0xd')]();});}};}function handleEntityNotFound(_0x3799d1){return function(_0xf7d1a2){if(!_0xf7d1a2){_0x3799d1['sendStatus'](0x194);}return _0xf7d1a2;};}function handleError(_0x25e807,_0x24728e){_0x24728e=_0x24728e||0x1f4;return function(_0x584806){logger[_0x93ff('0x22')](_0x584806[_0x93ff('0x23')]);if(_0x584806[_0x93ff('0x20')]){delete _0x584806[_0x93ff('0x20')];}_0x25e807['status'](_0x24728e)[_0x93ff('0x24')](_0x584806);};}exports[_0x93ff('0x25')]=function(_0x3ba147,_0x11e3c7){var _0x25444f={},_0x5ab6e8={},_0x3f20a8={'count':0x0,'rows':[]};var _0x2dadaf=_[_0x93ff('0x1b')](db[_0x93ff('0x26')]['rawAttributes'],function(_0x2e2a31){return{'name':_0x2e2a31[_0x93ff('0x27')],'type':_0x2e2a31['type']['key']};});_0x5ab6e8[_0x93ff('0x28')]=_[_0x93ff('0x1b')](_0x2dadaf,_0x93ff('0x20'));_0x5ab6e8[_0x93ff('0x29')]=_['keys'](_0x3ba147[_0x93ff('0x29')]);_0x5ab6e8[_0x93ff('0x2a')]=_['intersection'](_0x5ab6e8[_0x93ff('0x28')],_0x5ab6e8['query']);_0x25444f[_0x93ff('0x2b')]=_['intersection'](_0x5ab6e8[_0x93ff('0x28')],qs['fields'](_0x3ba147[_0x93ff('0x29')][_0x93ff('0x2c')]));_0x25444f['attributes']=_0x25444f[_0x93ff('0x2b')]['length']?_0x25444f[_0x93ff('0x2b')]:_0x5ab6e8[_0x93ff('0x28')];if(!_0x3ba147[_0x93ff('0x29')][_0x93ff('0x2d')]('nolimit')){_0x25444f[_0x93ff('0x10')]=qs['limit'](_0x3ba147['query'][_0x93ff('0x10')]);_0x25444f[_0x93ff('0xf')]=qs[_0x93ff('0xf')](_0x3ba147[_0x93ff('0x29')][_0x93ff('0xf')]);}_0x25444f[_0x93ff('0x2e')]=qs[_0x93ff('0x2f')](_0x3ba147[_0x93ff('0x29')][_0x93ff('0x2f')]);_0x25444f[_0x93ff('0x30')]=qs[_0x93ff('0x2a')](_[_0x93ff('0x31')](_0x3ba147[_0x93ff('0x29')],_0x5ab6e8['filters']),_0x2dadaf);if(_0x3ba147[_0x93ff('0x29')][_0x93ff('0x32')]){_0x25444f[_0x93ff('0x30')]=_['merge'](_0x25444f[_0x93ff('0x30')],{'$or':_['map'](_0x2dadaf,function(_0x3c0952){if(_0x3c0952[_0x93ff('0x1e')]!==_0x93ff('0x33')){var _0x199cb3={};_0x199cb3[_0x3c0952[_0x93ff('0x20')]]={'$like':'%'+_0x3ba147[_0x93ff('0x29')][_0x93ff('0x32')]+'%'};return _0x199cb3;}})});}_0x25444f=_[_0x93ff('0x34')]({},_0x25444f,_0x3ba147[_0x93ff('0x35')]);var _0x5ac9b0={'where':_0x25444f[_0x93ff('0x30')]};return db[_0x93ff('0x26')][_0x93ff('0x36')](_0x5ac9b0)[_0x93ff('0x14')](function(_0x4f2a93){_0x3f20a8['count']=_0x4f2a93;if(_0x3ba147[_0x93ff('0x29')][_0x93ff('0x37')]){_0x25444f[_0x93ff('0x38')]=[{'all':!![]}];}return db[_0x93ff('0x26')][_0x93ff('0x39')](_0x25444f);})[_0x93ff('0x14')](function(_0x21ea59){_0x3f20a8[_0x93ff('0x3a')]=_0x21ea59;return _0x3f20a8;})[_0x93ff('0x14')](respondWithFilteredResult(_0x11e3c7,_0x25444f))[_0x93ff('0x3b')](handleError(_0x11e3c7,null));};exports['show']=function(_0xcec07c,_0x3b6c87){var _0x4ffe07={'raw':![],'where':{'id':_0xcec07c[_0x93ff('0x3c')]['id']}},_0x527662={};_0x527662[_0x93ff('0x28')]=_['keys'](db[_0x93ff('0x26')][_0x93ff('0x3d')]);_0x527662[_0x93ff('0x29')]=_[_0x93ff('0x3e')](_0xcec07c[_0x93ff('0x29')]);_0x527662[_0x93ff('0x2a')]=_[_0x93ff('0x3f')](_0x527662[_0x93ff('0x28')],_0x527662[_0x93ff('0x29')]);_0x4ffe07[_0x93ff('0x2b')]=_[_0x93ff('0x3f')](_0x527662[_0x93ff('0x28')],qs['fields'](_0xcec07c[_0x93ff('0x29')]['fields']));_0x4ffe07['attributes']=_0x4ffe07[_0x93ff('0x2b')]['length']?_0x4ffe07[_0x93ff('0x2b')]:_0x527662[_0x93ff('0x28')];if(_0xcec07c[_0x93ff('0x29')][_0x93ff('0x37')]){_0x4ffe07[_0x93ff('0x38')]=[{'all':!![]}];}_0x4ffe07=_['merge']({},_0x4ffe07,_0xcec07c[_0x93ff('0x35')]);return db[_0x93ff('0x26')][_0x93ff('0x1f')](_0x4ffe07)['then'](handleEntityNotFound(_0x3b6c87,null))['then'](respondWithResult(_0x3b6c87,null))['catch'](handleError(_0x3b6c87,null));};exports['destroy']=function(_0xb28bd7,_0x59d1f7){return db[_0x93ff('0x26')][_0x93ff('0x1f')]({'where':{'id':_0xb28bd7[_0x93ff('0x3c')]['id']}})[_0x93ff('0x14')](handleEntityNotFound(_0x59d1f7,null))[_0x93ff('0x14')](removeEntity(_0x59d1f7,null))[_0x93ff('0x3b')](handleError(_0x59d1f7,null));};exports[_0x93ff('0x40')]=function(_0x40cc56,_0x4fb870){if(_0x40cc56[_0x93ff('0x41')][_0x93ff('0x1e')]===_0x93ff('0x17')&&!_[_0x93ff('0x42')](_0x40cc56['body'][_0x93ff('0x43')],'_')){_0x40cc56[_0x93ff('0x41')][_0x93ff('0x43')]='_'[_0x93ff('0x44')](_0x40cc56[_0x93ff('0x41')][_0x93ff('0x43')]);}return db[_0x93ff('0x26')][_0x93ff('0x40')](_0x40cc56[_0x93ff('0x41')],{'raw':![]})[_0x93ff('0x14')](function(_0x56087c){var _0x5d4fac=_0x40cc56[_0x93ff('0x45')][_0x93ff('0x15')]({'plain':!![]});if(!_0x5d4fac)throw new Error(_0x93ff('0x46'));if(_0x5d4fac[_0x93ff('0x47')]===_0x93ff('0x45')){var _0x509d4e=_0x56087c['get']({'plain':!![]});var _0x1b2b9a=[{'name':'InboundRoutes','value':_0x93ff('0x48')},{'name':_0x93ff('0x16'),'value':'outbound'},{'name':_0x93ff('0x18'),'value':_0x93ff('0x19')}];var _0x294052=_[_0x93ff('0x1f')](_0x1b2b9a,[_0x93ff('0x1c'),_0x509d4e['type']])[_0x93ff('0x20')];return db[_0x93ff('0x49')][_0x93ff('0x1f')]({'where':{'name':_0x294052,'userProfileId':_0x5d4fac[_0x93ff('0x4a')]},'raw':!![]})[_0x93ff('0x14')](function(_0x2c631e){if(_0x2c631e&&_0x2c631e[_0x93ff('0x4b')]===0x0){return db[_0x93ff('0x21')][_0x93ff('0x40')]({'name':_0x509d4e[_0x93ff('0x20')],'resourceId':_0x509d4e['id'],'type':_0x2c631e[_0x93ff('0x20')],'sectionId':_0x2c631e['id']},{})[_0x93ff('0x14')](function(){return _0x56087c;});}else{return _0x56087c;}})[_0x93ff('0x3b')](function(_0x168fa8){logger['error'](_0x93ff('0x4c'),_0x168fa8);throw _0x168fa8;});}return _0x56087c;})[_0x93ff('0x14')](respondWithResult(_0x4fb870,0xc9))['catch'](handleError(_0x4fb870,null));};exports['update']=function(_0x29e786,_0x2776e7){if(_0x29e786[_0x93ff('0x41')]['id']){delete _0x29e786[_0x93ff('0x41')]['id'];}return db[_0x93ff('0x26')][_0x93ff('0x1f')]({'where':{'id':_0x29e786[_0x93ff('0x3c')]['id']}})[_0x93ff('0x14')](handleEntityNotFound(_0x2776e7,null))[_0x93ff('0x14')](function(_0x83b55c){if(_0x83b55c){return db[_0x93ff('0x26')][_0x93ff('0x4d')](_[_0x93ff('0x31')](_0x29e786[_0x93ff('0x41')],[_0x93ff('0x43'),_0x93ff('0x4e'),_0x93ff('0x4f'),'recordingFormat',_0x93ff('0x50'),'mandatoryDisposition','alias']),{'where':{'context':_0x83b55c[_0x93ff('0x4e')],'exten':_0x83b55c['exten']},'individualHooks':!![]})[_0x93ff('0x14')](function(_0x16ff8d){return _0x16ff8d;});}return null;})['then'](respondWithStatusCode(_0x2776e7,null))[_0x93ff('0x3b')](handleError(_0x2776e7,null));};exports[_0x93ff('0x51')]=function(_0x41c299,_0x48174f){var _0x45b8ec=_0x41c299[_0x93ff('0x3c')]['id'];var _0x3cdc51=_0x41c299['body'];var _0x357310=0xc8;var _0xfa8478=null;return db['sequelize']['transaction']({'isolationLevel':db[_0x93ff('0x52')][_0x93ff('0x53')]['ISOLATION_LEVELS']['READ_COMMITTED']},function(_0x469a42){return db[_0x93ff('0x26')][_0x93ff('0x54')]({'where':{'id':_0x45b8ec},'transaction':_0x469a42})[_0x93ff('0x14')](function(_0x223b10){if(_0x223b10){return db[_0x93ff('0x26')]['destroy']({'where':{'VoiceExtensionId':_0x45b8ec},'transaction':_0x469a42})[_0x93ff('0x14')](function(){var _0x500da9=_[_0x93ff('0x1b')](_0x3cdc51,function(_0x3b543b){_0x3b543b[_0x93ff('0x55')]=_0x45b8ec;_0x3b543b['isApp']=!![];return _0x3b543b;});return _0x223b10['createRouting'](_0x500da9);})[_0x93ff('0x14')](function(_0x5e3010){return db[_0x93ff('0x26')][_0x93ff('0x56')](_0x5e3010,{'transaction':_0x469a42});});}else{_0x357310=0x194;_0xfa8478=[];}});})['then'](function(){if(_0x357310!==0x194){return db[_0x93ff('0x26')][_0x93ff('0x57')]({'where':{'isApp':!![],'VoiceExtensionId':_0x45b8ec},'order':_0x93ff('0x58')})['then'](function(_0x537a80){_0xfa8478=_0x537a80;});}})['catch'](function(_0x1a0a0c){_0x357310=0x1f4;logger['error'](_0x1a0a0c[_0x93ff('0x23')]);if(_0x1a0a0c[_0x93ff('0x20')]){delete _0x1a0a0c[_0x93ff('0x20')];}_0xfa8478=_0x1a0a0c;})[_0x93ff('0x59')](function(){if(_0xfa8478===null){_0x48174f[_0x93ff('0xb')](_0x357310);}else{if(_0x357310===0x1f4){_0x48174f[_0x93ff('0xc')](_0x357310)[_0x93ff('0x24')](_0xfa8478);}else{_0x48174f[_0x93ff('0xc')](_0x357310)[_0x93ff('0xe')](_0xfa8478);}}});};