aea7ea126412ab1b7fed86a9af7ca8c614f9f0da
[motion2.git] / server / api / voiceMail / voiceMail.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 _0xf911=['index','map','VoiceMail','rawAttributes','fieldName','type','model','keys','query','attributes','intersection','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','filters','filter','VIRTUAL','merge','options','includeAll','include','findAll','rows','catch','show','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','getMessages','findOne','VoiceMailMessage','findAndCountAll','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','json','count','offset','status','set','Content-Range','apply','reject','save','update','destroy','get','Voicemails','UserProfileResource','then','error','stack','name'];(function(_0xfae23b,_0x2be4ba){var _0x200640=function(_0x4ae258){while(--_0x4ae258){_0xfae23b['push'](_0xfae23b['shift']());}};_0x200640(++_0x2be4ba);}(_0xf911,0xe2));var _0x1f91=function(_0x58fa9f,_0x5a4566){_0x58fa9f=_0x58fa9f-0x0;var _0x239fc5=_0xf911[_0x58fa9f];return _0x239fc5;};'use strict';var pdf=require(_0x1f91('0x0'));var emlformat=require(_0x1f91('0x1'));var rimraf=require(_0x1f91('0x2'));var zipdir=require(_0x1f91('0x3'));var jsonpatch=require(_0x1f91('0x4'));var rp=require(_0x1f91('0x5'));var moment=require(_0x1f91('0x6'));var BPromise=require(_0x1f91('0x7'));var Mustache=require('mustache');var util=require(_0x1f91('0x8'));var path=require(_0x1f91('0x9'));var sox=require(_0x1f91('0xa'));var csv=require(_0x1f91('0xb'));var ejs=require(_0x1f91('0xc'));var fs=require('fs');var _=require(_0x1f91('0xd'));var squel=require(_0x1f91('0xe'));var crypto=require('crypto');var jsforce=require(_0x1f91('0xf'));var deskjs=require(_0x1f91('0x10'));var toCsv=require(_0x1f91('0xb'));var querystring=require(_0x1f91('0x11'));var Papa=require(_0x1f91('0x12'));var Redis=require(_0x1f91('0x13'));var authService=require(_0x1f91('0x14'));var qs=require(_0x1f91('0x15'));var as=require(_0x1f91('0x16'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x1f91('0x17'))(_0x1f91('0x18'));var utils=require(_0x1f91('0x19'));var config=require(_0x1f91('0x1a'));var db=require(_0x1f91('0x1b'))['db'];function respondWithStatusCode(_0x4e688e,_0xb538a7){_0xb538a7=_0xb538a7||0xcc;return function(_0xf38020){if(_0xf38020){return _0x4e688e[_0x1f91('0x1c')](_0xb538a7);}return _0x4e688e['status'](_0xb538a7)['end']();};}function respondWithResult(_0x16dc0a,_0x58100c){_0x58100c=_0x58100c||0xc8;return function(_0x4a93f1){if(_0x4a93f1){return _0x16dc0a['status'](_0x58100c)[_0x1f91('0x1d')](_0x4a93f1);}};}function respondWithFilteredResult(_0x3ef5d5,_0x48b387){return function(_0x39b34e){if(_0x39b34e){var _0x4e575e=_0x39b34e[_0x1f91('0x1e')],_0x26bbe0=_0x48b387[_0x1f91('0x1f')],_0x248882=_0x48b387['offset']+_0x48b387['limit'],_0x1e495a;if(_0x248882>=_0x4e575e){_0x248882=_0x4e575e;_0x1e495a=0xc8;}else{_0x1e495a=0xce;}_0x3ef5d5[_0x1f91('0x20')](_0x1e495a);return _0x3ef5d5[_0x1f91('0x21')](_0x1f91('0x22'),_0x26bbe0+'-'+_0x248882+'/'+_0x4e575e)[_0x1f91('0x1d')](_0x39b34e);}return null;};}function patchUpdates(_0x25cc1a){return function(_0x1f69ac){try{jsonpatch[_0x1f91('0x23')](_0x1f69ac,_0x25cc1a,!![]);}catch(_0x181319){return BPromise[_0x1f91('0x24')](_0x181319);}return _0x1f69ac[_0x1f91('0x25')]();};}function saveUpdates(_0x50d2cd,_0x512c00){return function(_0x43353f){if(_0x43353f){return _0x43353f[_0x1f91('0x26')](_0x50d2cd)['then'](function(_0x24c1c6){return _0x24c1c6;});}return null;};}function removeEntity(_0x29b8ec,_0x10ec47){return function(_0x49f246){if(_0x49f246){return _0x49f246[_0x1f91('0x27')]()['then'](function(){var _0x3ba743=_0x49f246[_0x1f91('0x28')]({'plain':!![]});var _0x12edd5=_0x1f91('0x29');return db[_0x1f91('0x2a')][_0x1f91('0x27')]({'where':{'type':_0x12edd5,'resourceId':_0x3ba743['id']}})[_0x1f91('0x2b')](function(){return _0x49f246;});})[_0x1f91('0x2b')](function(){_0x29b8ec[_0x1f91('0x20')](0xcc)['end']();});}};}function handleEntityNotFound(_0x49e4e9,_0x3dcddc){return function(_0x26730b){if(!_0x26730b){_0x49e4e9[_0x1f91('0x1c')](0x194);}return _0x26730b;};}function handleError(_0x3b80c1,_0x229c8c){_0x229c8c=_0x229c8c||0x1f4;return function(_0x5749c2){logger[_0x1f91('0x2c')](_0x5749c2[_0x1f91('0x2d')]);if(_0x5749c2[_0x1f91('0x2e')]){delete _0x5749c2['name'];}_0x3b80c1[_0x1f91('0x20')](_0x229c8c)['send'](_0x5749c2);};}exports[_0x1f91('0x2f')]=function(_0x4e4552,_0x483b3f){var _0x838277={},_0xcb72af={},_0x28eb04={'count':0x0,'rows':[]};var _0x14c3d3=_[_0x1f91('0x30')](db[_0x1f91('0x31')][_0x1f91('0x32')],function(_0x173abe){return{'name':_0x173abe[_0x1f91('0x33')],'type':_0x173abe[_0x1f91('0x34')]['key']};});_0xcb72af[_0x1f91('0x35')]=_[_0x1f91('0x30')](_0x14c3d3,_0x1f91('0x2e'));_0xcb72af['query']=_[_0x1f91('0x36')](_0x4e4552[_0x1f91('0x37')]);_0xcb72af['filters']=_['intersection'](_0xcb72af[_0x1f91('0x35')],_0xcb72af[_0x1f91('0x37')]);_0x838277[_0x1f91('0x38')]=_[_0x1f91('0x39')](_0xcb72af[_0x1f91('0x35')],qs[_0x1f91('0x3a')](_0x4e4552[_0x1f91('0x37')]['fields']));_0x838277[_0x1f91('0x38')]=_0x838277[_0x1f91('0x38')][_0x1f91('0x3b')]?_0x838277[_0x1f91('0x38')]:_0xcb72af[_0x1f91('0x35')];if(!_0x4e4552[_0x1f91('0x37')][_0x1f91('0x3c')](_0x1f91('0x3d'))){_0x838277[_0x1f91('0x3e')]=qs[_0x1f91('0x3e')](_0x4e4552['query'][_0x1f91('0x3e')]);_0x838277['offset']=qs[_0x1f91('0x1f')](_0x4e4552['query'][_0x1f91('0x1f')]);}_0x838277[_0x1f91('0x3f')]=qs[_0x1f91('0x40')](_0x4e4552[_0x1f91('0x37')][_0x1f91('0x40')]);_0x838277[_0x1f91('0x41')]=qs['filters'](_[_0x1f91('0x42')](_0x4e4552[_0x1f91('0x37')],_0xcb72af[_0x1f91('0x43')]));if(_0x4e4552[_0x1f91('0x37')][_0x1f91('0x44')]){_0x838277[_0x1f91('0x41')]=_['merge'](_0x838277['where'],{'$or':_[_0x1f91('0x30')](_0x14c3d3,function(_0x33e701){if(_0x33e701[_0x1f91('0x34')]!==_0x1f91('0x45')){var _0x11e171={};_0x11e171[_0x33e701[_0x1f91('0x2e')]]={'$like':'%'+_0x4e4552[_0x1f91('0x37')][_0x1f91('0x44')]+'%'};return _0x11e171;}})});}_0x838277=_[_0x1f91('0x46')]({},_0x838277,_0x4e4552[_0x1f91('0x47')]);var _0x4b9b7e={'where':_0x838277[_0x1f91('0x41')]};return db['VoiceMail'][_0x1f91('0x1e')](_0x4b9b7e)[_0x1f91('0x2b')](function(_0x1852e2){_0x28eb04[_0x1f91('0x1e')]=_0x1852e2;if(_0x4e4552[_0x1f91('0x37')][_0x1f91('0x48')]){_0x838277[_0x1f91('0x49')]=[{'all':!![]}];}return db[_0x1f91('0x31')][_0x1f91('0x4a')](_0x838277);})[_0x1f91('0x2b')](function(_0x2c04db){_0x28eb04[_0x1f91('0x4b')]=_0x2c04db;return _0x28eb04;})[_0x1f91('0x2b')](respondWithFilteredResult(_0x483b3f,_0x838277))[_0x1f91('0x4c')](handleError(_0x483b3f,null));};exports[_0x1f91('0x4d')]=function(_0x480bf9,_0x4c8c16){var _0x15400c={'raw':!![],'where':{'id':_0x480bf9['params']['id']}},_0x316937={};_0x316937[_0x1f91('0x35')]=_[_0x1f91('0x36')](db[_0x1f91('0x31')]['rawAttributes']);_0x316937[_0x1f91('0x37')]=_[_0x1f91('0x36')](_0x480bf9['query']);_0x316937['filters']=_[_0x1f91('0x39')](_0x316937[_0x1f91('0x35')],_0x316937['query']);_0x15400c[_0x1f91('0x38')]=_[_0x1f91('0x39')](_0x316937[_0x1f91('0x35')],qs[_0x1f91('0x3a')](_0x480bf9[_0x1f91('0x37')][_0x1f91('0x3a')]));_0x15400c[_0x1f91('0x38')]=_0x15400c[_0x1f91('0x38')][_0x1f91('0x3b')]?_0x15400c['attributes']:_0x316937['model'];if(_0x480bf9[_0x1f91('0x37')]['includeAll']){_0x15400c[_0x1f91('0x49')]=[{'all':!![]}];}_0x15400c=_['merge']({},_0x15400c,_0x480bf9['options']);return db[_0x1f91('0x31')][_0x1f91('0x4e')](_0x15400c)[_0x1f91('0x2b')](handleEntityNotFound(_0x4c8c16,null))[_0x1f91('0x2b')](respondWithResult(_0x4c8c16,null))['catch'](handleError(_0x4c8c16,null));};exports[_0x1f91('0x4f')]=function(_0x291525,_0x4e32bf){return db['VoiceMail']['create'](_0x291525[_0x1f91('0x50')],{})[_0x1f91('0x2b')](function(_0x4566f4){var _0x105cd2=_0x291525[_0x1f91('0x51')][_0x1f91('0x28')]({'plain':!![]});if(!_0x105cd2)throw new Error(_0x1f91('0x52'));if(_0x105cd2[_0x1f91('0x53')]==='user'){var _0x7bee0c=_0x4566f4[_0x1f91('0x28')]({'plain':!![]});var _0x3bd24f=_0x1f91('0x29');return db['UserProfileSection'][_0x1f91('0x4e')]({'where':{'name':_0x3bd24f,'userProfileId':_0x105cd2[_0x1f91('0x54')]},'raw':!![]})[_0x1f91('0x2b')](function(_0x2bac17){if(_0x2bac17&&_0x2bac17['autoAssociation']===0x0){return db['UserProfileResource']['create']({'name':_0x7bee0c['name'],'resourceId':_0x7bee0c['id'],'type':_0x2bac17['name'],'sectionId':_0x2bac17['id']},{})[_0x1f91('0x2b')](function(){return _0x4566f4;});}else{return _0x4566f4;}})[_0x1f91('0x4c')](function(_0x17cf0e){logger[_0x1f91('0x2c')](_0x1f91('0x55'),_0x17cf0e);throw _0x17cf0e;});}return _0x4566f4;})['then'](respondWithResult(_0x4e32bf,0xc9))[_0x1f91('0x4c')](handleError(_0x4e32bf,null));};exports[_0x1f91('0x26')]=function(_0xb78521,_0x5f3391){if(_0xb78521['body']['id']){delete _0xb78521['body']['id'];}return db['VoiceMail']['find']({'where':{'id':_0xb78521['params']['id']}})['then'](handleEntityNotFound(_0x5f3391,null))[_0x1f91('0x2b')](saveUpdates(_0xb78521[_0x1f91('0x50')],null))[_0x1f91('0x2b')](respondWithResult(_0x5f3391,null))['catch'](handleError(_0x5f3391,null));};exports[_0x1f91('0x27')]=function(_0x55cdde,_0x8ef81){return db[_0x1f91('0x31')][_0x1f91('0x4e')]({'where':{'id':_0x55cdde[_0x1f91('0x56')]['id']}})[_0x1f91('0x2b')](handleEntityNotFound(_0x8ef81,null))[_0x1f91('0x2b')](removeEntity(_0x8ef81,null))[_0x1f91('0x4c')](handleError(_0x8ef81,null));};exports[_0x1f91('0x57')]=function(_0x2c7654,_0x2d8ef3,_0x5b06dc){return db[_0x1f91('0x31')][_0x1f91('0x58')]({'where':{'id':_0x2c7654[_0x1f91('0x56')]['id']}})[_0x1f91('0x2b')](handleEntityNotFound(_0x2d8ef3,null))[_0x1f91('0x2b')](function(_0x383eec){var _0x2d4260;var _0x325eeb={},_0x55f8d7={};_0x55f8d7[_0x1f91('0x35')]=_[_0x1f91('0x36')](db[_0x1f91('0x59')][_0x1f91('0x32')]);_0x55f8d7[_0x1f91('0x37')]=_[_0x1f91('0x36')](_0x2c7654[_0x1f91('0x37')]);_0x55f8d7['filters']=_['intersection'](_0x55f8d7[_0x1f91('0x35')],_0x55f8d7[_0x1f91('0x37')]);_0x325eeb['attributes']=_[_0x1f91('0x39')](_0x55f8d7[_0x1f91('0x35')],qs[_0x1f91('0x3a')](_0x2c7654[_0x1f91('0x37')][_0x1f91('0x3a')]));_0x325eeb[_0x1f91('0x38')]=_0x325eeb[_0x1f91('0x38')][_0x1f91('0x3b')]?_0x325eeb[_0x1f91('0x38')]:_0x55f8d7[_0x1f91('0x35')];if(!_0x2c7654[_0x1f91('0x37')][_0x1f91('0x3c')](_0x1f91('0x3d'))){_0x325eeb[_0x1f91('0x3e')]=qs[_0x1f91('0x3e')](_0x2c7654['query'][_0x1f91('0x3e')]);_0x325eeb[_0x1f91('0x1f')]=qs[_0x1f91('0x1f')](_0x2c7654[_0x1f91('0x37')]['offset']);}_0x325eeb['order']=qs[_0x1f91('0x40')](_0x2c7654[_0x1f91('0x37')][_0x1f91('0x40')]);_0x325eeb[_0x1f91('0x41')]=qs[_0x1f91('0x43')](_['pick'](_0x2c7654[_0x1f91('0x37')],_0x55f8d7[_0x1f91('0x43')]));if(_0x2c7654[_0x1f91('0x37')]['filter']){_0x325eeb[_0x1f91('0x41')]=_[_0x1f91('0x46')](_0x325eeb[_0x1f91('0x41')],{'$or':_[_0x1f91('0x30')](_0x325eeb[_0x1f91('0x38')],function(_0x163c5f){var _0x460b14={};_0x460b14[_0x163c5f]={'$like':'%'+_0x2c7654[_0x1f91('0x37')][_0x1f91('0x44')]+'%'};return _0x460b14;})});}_0x325eeb[_0x1f91('0x41')]=_[_0x1f91('0x46')](_0x325eeb['where'],{'mailboxuser':_0x383eec['mailbox']});_0x325eeb=_['merge']({},_0x325eeb,_0x2c7654[_0x1f91('0x47')]);return db[_0x1f91('0x59')][_0x1f91('0x5a')](_0x325eeb)[_0x1f91('0x2b')](respondWithFilteredResult(_0x2d8ef3,_0x325eeb));})[_0x1f91('0x4c')](handleError(_0x2d8ef3,null));};