Built motion from commit (unavailable).|2.5.31
[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 _0x39f8=['inbound','OutboundRoutes','outbound','InternalRoutes','internal','filter','ignore','value','includes','type','find','name','UserProfileResource','end','error','stack','index','map','VoiceExtension','rawAttributes','fieldName','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','pick','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','create','body','startsWith','exten','concat','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','userProfileId','autoAssociation','context','description','cutdigits','mandatoryDisposition','addApplications','findOne','sequelize','transaction','VoiceExtensionId','findAndCountAll','cast(priority\x20as\x20unsigned)','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','ejs','fs-extra','squel','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./voiceExtension.socket','register','sendStatus','status','offset','undefined','limit','count','set','Content-Range','json','apply','reject','save','update','then','destroy','InboundRoutes'];(function(_0x9d85e8,_0xc6bb1d){var _0x2815fd=function(_0x1f4190){while(--_0x1f4190){_0x9d85e8['push'](_0x9d85e8['shift']());}};_0x2815fd(++_0xc6bb1d);}(_0x39f8,0xb3));var _0x839f=function(_0x56d445,_0x189103){_0x56d445=_0x56d445-0x0;var _0x21bd4e=_0x39f8[_0x56d445];return _0x21bd4e;};'use strict';var emlformat=require(_0x839f('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x839f('0x1'));var jsonpatch=require(_0x839f('0x2'));var rp=require(_0x839f('0x3'));var moment=require(_0x839f('0x4'));var BPromise=require(_0x839f('0x5'));var Mustache=require(_0x839f('0x6'));var util=require(_0x839f('0x7'));var path=require('path');var sox=require(_0x839f('0x8'));var csv=require('to-csv');var ejs=require(_0x839f('0x9'));var fs=require('fs');var fs_extra=require(_0x839f('0xa'));var _=require('lodash');var squel=require(_0x839f('0xb'));var crypto=require('crypto');var jsforce=require(_0x839f('0xc'));var deskjs=require(_0x839f('0xd'));var toCsv=require(_0x839f('0xe'));var querystring=require(_0x839f('0xf'));var Papa=require(_0x839f('0x10'));var Redis=require(_0x839f('0x11'));var authService=require(_0x839f('0x12'));var qs=require(_0x839f('0x13'));var as=require(_0x839f('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x839f('0x15'));var utils=require(_0x839f('0x16'));var config=require(_0x839f('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x839f('0x18'))['db'];config['redis']=_[_0x839f('0x19')](config[_0x839f('0x1a')],{'host':_0x839f('0x1b'),'port':0x18eb});var socket=require(_0x839f('0x1c'))(new Redis(config[_0x839f('0x1a')]));require(_0x839f('0x1d'))[_0x839f('0x1e')](socket);function respondWithStatusCode(_0x566883,_0x1c69d9){_0x1c69d9=_0x1c69d9||0xcc;return function(_0x3dee67){if(_0x3dee67){return _0x566883[_0x839f('0x1f')](_0x1c69d9);}return _0x566883[_0x839f('0x20')](_0x1c69d9)['end']();};}function respondWithResult(_0x4441ed,_0x4018e6){_0x4018e6=_0x4018e6||0xc8;return function(_0xaac648){if(_0xaac648){return _0x4441ed[_0x839f('0x20')](_0x4018e6)['json'](_0xaac648);}};}function respondWithFilteredResult(_0x1b30f1,_0x43dd2c){return function(_0x3ec6ce){if(_0x3ec6ce){var _0x386170=typeof _0x43dd2c[_0x839f('0x21')]===_0x839f('0x22')&&typeof _0x43dd2c[_0x839f('0x23')]==='undefined';var _0x4f1fce=_0x3ec6ce[_0x839f('0x24')];var _0x326003=_0x386170?0x0:_0x43dd2c['offset'];var _0x1225d9=_0x386170?_0x3ec6ce[_0x839f('0x24')]:_0x43dd2c['offset']+_0x43dd2c[_0x839f('0x23')];var _0xaef648;if(_0x1225d9>=_0x4f1fce){_0x1225d9=_0x4f1fce;_0xaef648=0xc8;}else{_0xaef648=0xce;}_0x1b30f1[_0x839f('0x20')](_0xaef648);return _0x1b30f1[_0x839f('0x25')](_0x839f('0x26'),_0x326003+'-'+_0x1225d9+'/'+_0x4f1fce)[_0x839f('0x27')](_0x3ec6ce);}return null;};}function patchUpdates(_0x345e13){return function(_0x56e280){try{jsonpatch[_0x839f('0x28')](_0x56e280,_0x345e13,!![]);}catch(_0x10aafd){return BPromise[_0x839f('0x29')](_0x10aafd);}return _0x56e280[_0x839f('0x2a')]();};}function saveUpdates(_0x3197c2,_0x42a86b){return function(_0x2a9d4){if(_0x2a9d4){return _0x2a9d4[_0x839f('0x2b')](_0x3197c2)[_0x839f('0x2c')](function(_0x38d131){return _0x38d131;});}return null;};}function removeEntity(_0x4c5a03,_0x3c157a){return function(_0x3c36ff){if(_0x3c36ff){return _0x3c36ff[_0x839f('0x2d')]()[_0x839f('0x2c')](function(){var _0x250582=_0x3c36ff['get']({'plain':!![]});var _0x391198=[{'name':_0x839f('0x2e'),'value':_0x839f('0x2f'),'ignore':![]},{'name':_0x839f('0x30'),'value':_0x839f('0x31'),'ignore':![]},{'name':_0x839f('0x32'),'value':_0x839f('0x33'),'ignore':![]}];var _0x602c5=_(_0x391198)[_0x839f('0x34')](_0x839f('0x35'))['map'](_0x839f('0x36'))[_0x839f('0x36')]();if(_[_0x839f('0x37')](_0x602c5,_0x250582[_0x839f('0x38')])){return;}var _0x5ec155=_[_0x839f('0x39')](_0x391198,[_0x839f('0x36'),_0x250582[_0x839f('0x38')]])[_0x839f('0x3a')];return db[_0x839f('0x3b')][_0x839f('0x2d')]({'where':{'type':_0x5ec155,'resourceId':_0x250582['id']}})['then'](function(){return _0x3c36ff;});})['then'](function(){_0x4c5a03[_0x839f('0x20')](0xcc)[_0x839f('0x3c')]();});}};}function handleEntityNotFound(_0x2847f4,_0x3c08af){return function(_0xe1a030){if(!_0xe1a030){_0x2847f4[_0x839f('0x1f')](0x194);}return _0xe1a030;};}function handleError(_0x19a458,_0x3e658f){_0x3e658f=_0x3e658f||0x1f4;return function(_0x238985){logger[_0x839f('0x3d')](_0x238985[_0x839f('0x3e')]);if(_0x238985[_0x839f('0x3a')]){delete _0x238985[_0x839f('0x3a')];}_0x19a458['status'](_0x3e658f)['send'](_0x238985);};}exports[_0x839f('0x3f')]=function(_0x5d6ca8,_0x3e715a){var _0x5d8adc={},_0x5398e8={},_0x2ba941={'count':0x0,'rows':[]};var _0x484301=_[_0x839f('0x40')](db[_0x839f('0x41')][_0x839f('0x42')],function(_0x51764e){return{'name':_0x51764e[_0x839f('0x43')],'type':_0x51764e[_0x839f('0x38')][_0x839f('0x44')]};});_0x5398e8[_0x839f('0x45')]=_[_0x839f('0x40')](_0x484301,_0x839f('0x3a'));_0x5398e8[_0x839f('0x46')]=_[_0x839f('0x47')](_0x5d6ca8[_0x839f('0x46')]);_0x5398e8[_0x839f('0x48')]=_[_0x839f('0x49')](_0x5398e8['model'],_0x5398e8['query']);_0x5d8adc[_0x839f('0x4a')]=_[_0x839f('0x49')](_0x5398e8[_0x839f('0x45')],qs['fields'](_0x5d6ca8[_0x839f('0x46')][_0x839f('0x4b')]));_0x5d8adc[_0x839f('0x4a')]=_0x5d8adc[_0x839f('0x4a')][_0x839f('0x4c')]?_0x5d8adc[_0x839f('0x4a')]:_0x5398e8[_0x839f('0x45')];if(!_0x5d6ca8[_0x839f('0x46')][_0x839f('0x4d')]('nolimit')){_0x5d8adc[_0x839f('0x23')]=qs[_0x839f('0x23')](_0x5d6ca8[_0x839f('0x46')][_0x839f('0x23')]);_0x5d8adc[_0x839f('0x21')]=qs[_0x839f('0x21')](_0x5d6ca8[_0x839f('0x46')][_0x839f('0x21')]);}_0x5d8adc[_0x839f('0x4e')]=qs[_0x839f('0x4f')](_0x5d6ca8['query'][_0x839f('0x4f')]);_0x5d8adc[_0x839f('0x50')]=qs[_0x839f('0x48')](_[_0x839f('0x51')](_0x5d6ca8[_0x839f('0x46')],_0x5398e8[_0x839f('0x48')]),_0x484301);if(_0x5d6ca8[_0x839f('0x46')][_0x839f('0x34')]){_0x5d8adc[_0x839f('0x50')]=_[_0x839f('0x52')](_0x5d8adc[_0x839f('0x50')],{'$or':_[_0x839f('0x40')](_0x484301,function(_0x2674b7){if(_0x2674b7[_0x839f('0x38')]!==_0x839f('0x53')){var _0x4a0c42={};_0x4a0c42[_0x2674b7[_0x839f('0x3a')]]={'$like':'%'+_0x5d6ca8[_0x839f('0x46')]['filter']+'%'};return _0x4a0c42;}})});}_0x5d8adc=_[_0x839f('0x52')]({},_0x5d8adc,_0x5d6ca8[_0x839f('0x54')]);var _0x5b1287={'where':_0x5d8adc[_0x839f('0x50')]};return db[_0x839f('0x41')][_0x839f('0x24')](_0x5b1287)['then'](function(_0x540990){_0x2ba941['count']=_0x540990;if(_0x5d6ca8[_0x839f('0x46')][_0x839f('0x55')]){_0x5d8adc[_0x839f('0x56')]=[{'all':!![]}];}return db[_0x839f('0x41')][_0x839f('0x57')](_0x5d8adc);})[_0x839f('0x2c')](function(_0x51a353){_0x2ba941[_0x839f('0x58')]=_0x51a353;return _0x2ba941;})[_0x839f('0x2c')](respondWithFilteredResult(_0x3e715a,_0x5d8adc))[_0x839f('0x59')](handleError(_0x3e715a,null));};exports[_0x839f('0x5a')]=function(_0x37a0f2,_0x153fe8){var _0x45303f={'raw':![],'where':{'id':_0x37a0f2[_0x839f('0x5b')]['id']}},_0x35381b={};_0x35381b[_0x839f('0x45')]=_[_0x839f('0x47')](db[_0x839f('0x41')][_0x839f('0x42')]);_0x35381b[_0x839f('0x46')]=_[_0x839f('0x47')](_0x37a0f2['query']);_0x35381b[_0x839f('0x48')]=_[_0x839f('0x49')](_0x35381b[_0x839f('0x45')],_0x35381b[_0x839f('0x46')]);_0x45303f[_0x839f('0x4a')]=_[_0x839f('0x49')](_0x35381b['model'],qs[_0x839f('0x4b')](_0x37a0f2[_0x839f('0x46')][_0x839f('0x4b')]));_0x45303f['attributes']=_0x45303f[_0x839f('0x4a')][_0x839f('0x4c')]?_0x45303f[_0x839f('0x4a')]:_0x35381b[_0x839f('0x45')];if(_0x37a0f2[_0x839f('0x46')]['includeAll']){_0x45303f[_0x839f('0x56')]=[{'all':!![]}];}_0x45303f=_[_0x839f('0x52')]({},_0x45303f,_0x37a0f2[_0x839f('0x54')]);return db['VoiceExtension'][_0x839f('0x39')](_0x45303f)[_0x839f('0x2c')](handleEntityNotFound(_0x153fe8,null))['then'](respondWithResult(_0x153fe8,null))['catch'](handleError(_0x153fe8,null));};exports[_0x839f('0x2d')]=function(_0x5bf55a,_0x28ad01){return db[_0x839f('0x41')][_0x839f('0x39')]({'where':{'id':_0x5bf55a[_0x839f('0x5b')]['id']}})[_0x839f('0x2c')](handleEntityNotFound(_0x28ad01,null))['then'](removeEntity(_0x28ad01,null))[_0x839f('0x59')](handleError(_0x28ad01,null));};exports[_0x839f('0x5c')]=function(_0x143579,_0x14feb4){if(_0x143579[_0x839f('0x5d')][_0x839f('0x38')]===_0x839f('0x31')&&!_[_0x839f('0x5e')](_0x143579[_0x839f('0x5d')][_0x839f('0x5f')],'_')){_0x143579[_0x839f('0x5d')][_0x839f('0x5f')]='_'[_0x839f('0x60')](_0x143579['body'][_0x839f('0x5f')]);}return db[_0x839f('0x41')][_0x839f('0x5c')](_0x143579[_0x839f('0x5d')],{'raw':![]})[_0x839f('0x2c')](function(_0x2e1cfe){var _0x382cd5=_0x143579[_0x839f('0x61')]['get']({'plain':!![]});if(!_0x382cd5)throw new Error(_0x839f('0x62'));if(_0x382cd5['role']===_0x839f('0x61')){var _0x16c126=_0x2e1cfe['get']({'plain':!![]});var _0x2304fa=[{'name':'InboundRoutes','value':_0x839f('0x2f')},{'name':_0x839f('0x30'),'value':_0x839f('0x31')},{'name':'InternalRoutes','value':'internal'}];var _0x42617c=_[_0x839f('0x39')](_0x2304fa,[_0x839f('0x36'),_0x16c126[_0x839f('0x38')]])['name'];return db[_0x839f('0x63')][_0x839f('0x39')]({'where':{'name':_0x42617c,'userProfileId':_0x382cd5[_0x839f('0x64')]},'raw':!![]})[_0x839f('0x2c')](function(_0x3001ac){if(_0x3001ac&&_0x3001ac[_0x839f('0x65')]===0x0){return db[_0x839f('0x3b')][_0x839f('0x5c')]({'name':_0x16c126[_0x839f('0x3a')],'resourceId':_0x16c126['id'],'type':_0x3001ac[_0x839f('0x3a')],'sectionId':_0x3001ac['id']},{})[_0x839f('0x2c')](function(){return _0x2e1cfe;});}else{return _0x2e1cfe;}})[_0x839f('0x59')](function(_0x56f973){logger[_0x839f('0x3d')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x56f973);throw _0x56f973;});}return _0x2e1cfe;})['then'](respondWithResult(_0x14feb4,0xc9))['catch'](handleError(_0x14feb4,null));};exports['update']=function(_0x2780f5,_0xc93f1){if(_0x2780f5[_0x839f('0x5d')]['id']){delete _0x2780f5[_0x839f('0x5d')]['id'];}return db[_0x839f('0x41')]['find']({'where':{'id':_0x2780f5[_0x839f('0x5b')]['id']}})['then'](handleEntityNotFound(_0xc93f1,null))[_0x839f('0x2c')](function(_0x5ee3b6){if(_0x5ee3b6){return db[_0x839f('0x41')][_0x839f('0x2b')](_[_0x839f('0x51')](_0x2780f5[_0x839f('0x5d')],[_0x839f('0x5f'),_0x839f('0x66'),_0x839f('0x67'),'recordingFormat',_0x839f('0x68'),_0x839f('0x69')]),{'where':{'context':_0x5ee3b6['context'],'exten':_0x5ee3b6[_0x839f('0x5f')]},'individualHooks':!![]})[_0x839f('0x2c')](function(_0x1421a8){return _0x1421a8;});}return null;})['then'](respondWithStatusCode(_0xc93f1,null))['catch'](handleError(_0xc93f1,null));};exports[_0x839f('0x6a')]=function(_0x2eaa73,_0xceeb4d,_0x271bff){return db[_0x839f('0x41')][_0x839f('0x6b')]({'where':{'id':_0x2eaa73[_0x839f('0x5b')]['id']}})[_0x839f('0x2c')](handleEntityNotFound(_0xceeb4d,null))[_0x839f('0x2c')](function(_0x348c0b){if(_0x348c0b){return db[_0x839f('0x6c')][_0x839f('0x6d')](function(_0x161ddf){return db['VoiceExtension'][_0x839f('0x2d')]({'where':{'VoiceExtensionId':_0x2eaa73[_0x839f('0x5b')]['id']},'transaction':_0x161ddf})['then'](function(_0x4e684a){var _0x5a45f4=_[_0x839f('0x40')](_0x2eaa73[_0x839f('0x5d')],function(_0x228b89){_0x228b89[_0x839f('0x6e')]=_0x2eaa73[_0x839f('0x5b')]['id'];return _0x228b89;});return db[_0x839f('0x41')]['bulkCreate'](_0x5a45f4,{'transaction':_0x161ddf});});})[_0x839f('0x2c')](function(){return db[_0x839f('0x41')][_0x839f('0x6f')]({'where':{'isApp':!![],'VoiceExtensionId':_0x2eaa73[_0x839f('0x5b')]['id']},'order':_0x839f('0x70')});});}})[_0x839f('0x2c')](respondWithResult(_0xceeb4d,null))['catch'](handleError(_0xceeb4d,null));};