Built motion from commit (unavailable).|2.3.0
[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 _0xfac9=['rimraf','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs','lodash','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../config/license/hardware','ioredis','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../mysqldb','sendStatus','status','json','count','offset','Content-Range','apply','reject','update','then','destroy','get','Voicemails','UserProfileResource','end','error','stack','name','send','index','VoiceMail','rawAttributes','model','keys','query','intersection','fields','attributes','length','hasOwnProperty','limit','order','sort','filters','filter','where','merge','map','type','includeAll','include','findAll','options','find','catch','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','nolimit','pick','VoiceMailMessage','findAndCountAll','eml-format'];(function(_0x5ebc04,_0x14a363){var _0x17845c=function(_0x360850){while(--_0x360850){_0x5ebc04['push'](_0x5ebc04['shift']());}};_0x17845c(++_0x14a363);}(_0xfac9,0xa3));var _0x9fac=function(_0x542949,_0x44b5cc){_0x542949=_0x542949-0x0;var _0x1f6fca=_0xfac9[_0x542949];return _0x1f6fca;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x9fac('0x0'));var rimraf=require(_0x9fac('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x9fac('0x2'));var rp=require(_0x9fac('0x3'));var moment=require(_0x9fac('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x9fac('0x5'));var util=require(_0x9fac('0x6'));var path=require(_0x9fac('0x7'));var sox=require(_0x9fac('0x8'));var csv=require(_0x9fac('0x9'));var ejs=require(_0x9fac('0xa'));var fs=require('fs');var _=require(_0x9fac('0xb'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x9fac('0xc'));var deskjs=require(_0x9fac('0xd'));var toCsv=require(_0x9fac('0x9'));var querystring=require(_0x9fac('0xe'));var Papa=require(_0x9fac('0xf'));var authService=require(_0x9fac('0x10'));var hardwareService=require(_0x9fac('0x11'));var Redis=require(_0x9fac('0x12'));var qs=require(_0x9fac('0x13'));var logger=require(_0x9fac('0x14'))(_0x9fac('0x15'));var utils=require(_0x9fac('0x16'));var config=require('../../config/environment');var db=require(_0x9fac('0x17'))['db'];function respondWithStatusCode(_0x54dd33,_0x1a5755){_0x1a5755=_0x1a5755||0xcc;return function(_0x5efe54){if(_0x5efe54){return _0x54dd33[_0x9fac('0x18')](_0x1a5755);}return _0x54dd33[_0x9fac('0x19')](_0x1a5755)['end']();};}function respondWithResult(_0x1b3b0a,_0x37a73e){_0x37a73e=_0x37a73e||0xc8;return function(_0x3fa1be){if(_0x3fa1be){return _0x1b3b0a[_0x9fac('0x19')](_0x37a73e)[_0x9fac('0x1a')](_0x3fa1be);}};}function respondWithFilteredResult(_0x203178,_0x597f43){return function(_0x29dee3){if(_0x29dee3){var _0x4dbab3=_0x29dee3[_0x9fac('0x1b')],_0x1b7910=_0x597f43[_0x9fac('0x1c')],_0x5a65f3=_0x597f43['offset']+_0x597f43['limit'],_0x44ca18;if(_0x5a65f3>=_0x4dbab3){_0x5a65f3=_0x4dbab3;_0x44ca18=0xc8;}else{_0x44ca18=0xce;}_0x203178[_0x9fac('0x19')](_0x44ca18);return _0x203178['set'](_0x9fac('0x1d'),_0x1b7910+'-'+_0x5a65f3+'/'+_0x4dbab3)['json'](_0x29dee3);}return null;};}function patchUpdates(_0x5830d2){return function(_0x49db85){try{jsonpatch[_0x9fac('0x1e')](_0x49db85,_0x5830d2,!![]);}catch(_0x11669a){return BPromise[_0x9fac('0x1f')](_0x11669a);}return _0x49db85['save']();};}function saveUpdates(_0x5f3cdd,_0x4f0336){return function(_0x2ded45){if(_0x2ded45){return _0x2ded45[_0x9fac('0x20')](_0x5f3cdd)[_0x9fac('0x21')](function(_0x17d0a3){return _0x17d0a3;});}return null;};}function removeEntity(_0x24950f,_0x170c7d){return function(_0x4f0563){if(_0x4f0563){return _0x4f0563[_0x9fac('0x22')]()['then'](function(){var _0x47b9b2=_0x4f0563[_0x9fac('0x23')]({'plain':!![]});var _0x3090ca=_0x9fac('0x24');return db[_0x9fac('0x25')][_0x9fac('0x22')]({'where':{'type':_0x3090ca,'resourceId':_0x47b9b2['id']}})[_0x9fac('0x21')](function(){return _0x4f0563;});})[_0x9fac('0x21')](function(){_0x24950f[_0x9fac('0x19')](0xcc)[_0x9fac('0x26')]();});}};}function handleEntityNotFound(_0x492a68,_0x1845c1){return function(_0x3ef300){if(!_0x3ef300){_0x492a68[_0x9fac('0x18')](0x194);}return _0x3ef300;};}function handleError(_0x56353c,_0x3dc1d6){_0x3dc1d6=_0x3dc1d6||0x1f4;return function(_0x1a96b9){logger[_0x9fac('0x27')](_0x1a96b9[_0x9fac('0x28')]);if(_0x1a96b9[_0x9fac('0x29')]){delete _0x1a96b9[_0x9fac('0x29')];}_0x56353c[_0x9fac('0x19')](_0x3dc1d6)[_0x9fac('0x2a')](_0x1a96b9);};}exports[_0x9fac('0x2b')]=function(_0x5a1fe8,_0x331b02){var _0x10dc50={},_0x5eb2bd={},_0x352645={'count':0x0,'rows':[]};var _0x35e0a8=db[_0x9fac('0x2c')][_0x9fac('0x2d')];_0x5eb2bd[_0x9fac('0x2e')]=_[_0x9fac('0x2f')](_0x35e0a8);_0x5eb2bd[_0x9fac('0x30')]=_['keys'](_0x5a1fe8[_0x9fac('0x30')]);_0x5eb2bd['filters']=_['intersection'](_0x5eb2bd[_0x9fac('0x2e')],_0x5eb2bd[_0x9fac('0x30')]);_0x10dc50['attributes']=_[_0x9fac('0x31')](_0x5eb2bd[_0x9fac('0x2e')],qs[_0x9fac('0x32')](_0x5a1fe8['query'][_0x9fac('0x32')]));_0x10dc50[_0x9fac('0x33')]=_0x10dc50[_0x9fac('0x33')][_0x9fac('0x34')]?_0x10dc50['attributes']:_0x5eb2bd[_0x9fac('0x2e')];if(!_0x5a1fe8[_0x9fac('0x30')][_0x9fac('0x35')]('nolimit')){_0x10dc50[_0x9fac('0x36')]=qs[_0x9fac('0x36')](_0x5a1fe8[_0x9fac('0x30')][_0x9fac('0x36')]);_0x10dc50['offset']=qs[_0x9fac('0x1c')](_0x5a1fe8[_0x9fac('0x30')][_0x9fac('0x1c')]);}_0x10dc50[_0x9fac('0x37')]=qs['sort'](_0x5a1fe8[_0x9fac('0x30')][_0x9fac('0x38')]);_0x10dc50['where']=qs[_0x9fac('0x39')](_['pick'](_0x5a1fe8[_0x9fac('0x30')],_0x5eb2bd[_0x9fac('0x39')]));if(_0x5a1fe8[_0x9fac('0x30')][_0x9fac('0x3a')]){_0x10dc50[_0x9fac('0x3b')]=_[_0x9fac('0x3c')](_0x10dc50[_0x9fac('0x3b')],{'$or':_[_0x9fac('0x3d')](_0x35e0a8,function(_0x18ef82){if(_0x18ef82[_0x9fac('0x3e')]['key']!=='VIRTUAL'){var _0x530a66={};_0x530a66[_0x18ef82['field']]={'$like':'%'+_0x5a1fe8[_0x9fac('0x30')][_0x9fac('0x3a')]+'%'};return _0x530a66;}})});}_0x10dc50=_[_0x9fac('0x3c')]({},_0x10dc50,_0x5a1fe8['options']);var _0x3c74c3={'where':_0x10dc50[_0x9fac('0x3b')]};return db[_0x9fac('0x2c')][_0x9fac('0x1b')](_0x3c74c3)[_0x9fac('0x21')](function(_0x34b7f9){_0x352645[_0x9fac('0x1b')]=_0x34b7f9;if(_0x5a1fe8['query'][_0x9fac('0x3f')]){_0x10dc50[_0x9fac('0x40')]=[{'all':!![]}];}return db[_0x9fac('0x2c')][_0x9fac('0x41')](_0x10dc50);})[_0x9fac('0x21')](function(_0x4f252e){_0x352645['rows']=_0x4f252e;return _0x352645;})[_0x9fac('0x21')](respondWithFilteredResult(_0x331b02,_0x10dc50))['catch'](handleError(_0x331b02,null));};exports['show']=function(_0x4a4adc,_0x47d447){var _0xb07c7c={'raw':!![],'where':{'id':_0x4a4adc['params']['id']}},_0x43e083={};_0x43e083[_0x9fac('0x2e')]=_['keys'](db[_0x9fac('0x2c')][_0x9fac('0x2d')]);_0x43e083[_0x9fac('0x30')]=_[_0x9fac('0x2f')](_0x4a4adc['query']);_0x43e083[_0x9fac('0x39')]=_[_0x9fac('0x31')](_0x43e083[_0x9fac('0x2e')],_0x43e083[_0x9fac('0x30')]);_0xb07c7c[_0x9fac('0x33')]=_[_0x9fac('0x31')](_0x43e083[_0x9fac('0x2e')],qs['fields'](_0x4a4adc['query']['fields']));_0xb07c7c['attributes']=_0xb07c7c[_0x9fac('0x33')][_0x9fac('0x34')]?_0xb07c7c[_0x9fac('0x33')]:_0x43e083['model'];if(_0x4a4adc[_0x9fac('0x30')][_0x9fac('0x3f')]){_0xb07c7c[_0x9fac('0x40')]=[{'all':!![]}];}_0xb07c7c=_[_0x9fac('0x3c')]({},_0xb07c7c,_0x4a4adc[_0x9fac('0x42')]);return db[_0x9fac('0x2c')][_0x9fac('0x43')](_0xb07c7c)[_0x9fac('0x21')](handleEntityNotFound(_0x47d447,null))['then'](respondWithResult(_0x47d447,null))[_0x9fac('0x44')](handleError(_0x47d447,null));};exports[_0x9fac('0x45')]=function(_0x2f9c51,_0x552130){return db[_0x9fac('0x2c')][_0x9fac('0x45')](_0x2f9c51[_0x9fac('0x46')],{})['then'](function(_0x44d844){var _0xfaf271=_0x2f9c51[_0x9fac('0x47')][_0x9fac('0x23')]({'plain':!![]});if(!_0xfaf271)throw new Error(_0x9fac('0x48'));if(_0xfaf271['role']===_0x9fac('0x47')){var _0x45693e=_0x44d844[_0x9fac('0x23')]({'plain':!![]});var _0x5e007d='Voicemails';return db[_0x9fac('0x49')]['find']({'where':{'name':_0x5e007d,'userProfileId':_0xfaf271[_0x9fac('0x4a')]},'raw':!![]})[_0x9fac('0x21')](function(_0x387952){if(_0x387952&&_0x387952[_0x9fac('0x4b')]===0x0){return db[_0x9fac('0x25')]['create']({'name':_0x45693e[_0x9fac('0x29')],'resourceId':_0x45693e['id'],'type':_0x387952[_0x9fac('0x29')],'sectionId':_0x387952['id']},{})[_0x9fac('0x21')](function(){return _0x44d844;});}else{return _0x44d844;}})[_0x9fac('0x44')](function(_0x1f55b7){logger[_0x9fac('0x27')](_0x9fac('0x4c'),_0x1f55b7);throw _0x1f55b7;});}return _0x44d844;})[_0x9fac('0x21')](respondWithResult(_0x552130,0xc9))['catch'](handleError(_0x552130,null));};exports[_0x9fac('0x20')]=function(_0x52f14d,_0x598d6a){if(_0x52f14d['body']['id']){delete _0x52f14d[_0x9fac('0x46')]['id'];}return db['VoiceMail'][_0x9fac('0x43')]({'where':{'id':_0x52f14d[_0x9fac('0x4d')]['id']}})[_0x9fac('0x21')](handleEntityNotFound(_0x598d6a,null))['then'](saveUpdates(_0x52f14d['body'],null))['then'](respondWithResult(_0x598d6a,null))['catch'](handleError(_0x598d6a,null));};exports[_0x9fac('0x22')]=function(_0x2b94de,_0x44bf2a){return db[_0x9fac('0x2c')]['find']({'where':{'id':_0x2b94de[_0x9fac('0x4d')]['id']}})['then'](handleEntityNotFound(_0x44bf2a,null))[_0x9fac('0x21')](removeEntity(_0x44bf2a,null))[_0x9fac('0x44')](handleError(_0x44bf2a,null));};exports['getMessages']=function(_0x4e1e87,_0x59649d,_0x183291){return db['VoiceMail']['findOne']({'where':{'id':_0x4e1e87[_0x9fac('0x4d')]['id']}})[_0x9fac('0x21')](handleEntityNotFound(_0x59649d,null))[_0x9fac('0x21')](function(_0xed441){var _0x1e57bb;var _0x45db0e={},_0x52bf4a={};_0x52bf4a[_0x9fac('0x2e')]=_[_0x9fac('0x2f')](db['VoiceMailMessage'][_0x9fac('0x2d')]);_0x52bf4a[_0x9fac('0x30')]=_[_0x9fac('0x2f')](_0x4e1e87[_0x9fac('0x30')]);_0x52bf4a['filters']=_['intersection'](_0x52bf4a[_0x9fac('0x2e')],_0x52bf4a[_0x9fac('0x30')]);_0x45db0e[_0x9fac('0x33')]=_[_0x9fac('0x31')](_0x52bf4a[_0x9fac('0x2e')],qs['fields'](_0x4e1e87['query'][_0x9fac('0x32')]));_0x45db0e[_0x9fac('0x33')]=_0x45db0e[_0x9fac('0x33')][_0x9fac('0x34')]?_0x45db0e[_0x9fac('0x33')]:_0x52bf4a[_0x9fac('0x2e')];if(!_0x4e1e87[_0x9fac('0x30')][_0x9fac('0x35')](_0x9fac('0x4e'))){_0x45db0e[_0x9fac('0x36')]=qs[_0x9fac('0x36')](_0x4e1e87['query'][_0x9fac('0x36')]);_0x45db0e[_0x9fac('0x1c')]=qs[_0x9fac('0x1c')](_0x4e1e87[_0x9fac('0x30')][_0x9fac('0x1c')]);}_0x45db0e[_0x9fac('0x37')]=qs['sort'](_0x4e1e87[_0x9fac('0x30')]['sort']);_0x45db0e[_0x9fac('0x3b')]=qs['filters'](_[_0x9fac('0x4f')](_0x4e1e87['query'],_0x52bf4a[_0x9fac('0x39')]));if(_0x4e1e87['query'][_0x9fac('0x3a')]){_0x45db0e[_0x9fac('0x3b')]=_[_0x9fac('0x3c')](_0x45db0e['where'],{'$or':_[_0x9fac('0x3d')](_0x45db0e[_0x9fac('0x33')],function(_0x372227){var _0x165725={};_0x165725[_0x372227]={'$like':'%'+_0x4e1e87[_0x9fac('0x30')][_0x9fac('0x3a')]+'%'};return _0x165725;})});}_0x45db0e[_0x9fac('0x3b')]=_[_0x9fac('0x3c')](_0x45db0e['where'],{'mailboxuser':_0xed441['mailbox']});_0x45db0e=_[_0x9fac('0x3c')]({},_0x45db0e,_0x4e1e87['options']);return db[_0x9fac('0x50')][_0x9fac('0x51')](_0x45db0e)['then'](respondWithFilteredResult(_0x59649d,_0x45db0e));})['catch'](handleError(_0x59649d,null));};