Built motion from commit 85328c08.|2.5.50
[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 _0xe5b5=['stack','name','map','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','limit','sort','filter','where','merge','options','VoiceMail','includeAll','include','findAll','catch','length','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','params','getMessages','VoiceMailMessage','pick','mailbox','findAndCountAll','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','sendStatus','status','end','offset','undefined','count','Content-Range','json','apply','reject','save','update','then','destroy','get','Voicemails','UserProfileResource','error'];(function(_0x59c301,_0x359c50){var _0x3866b9=function(_0x2d380e){while(--_0x2d380e){_0x59c301['push'](_0x59c301['shift']());}};_0x3866b9(++_0x359c50);}(_0xe5b5,0x12b));var _0x5e5b=function(_0x559a80,_0x3d193d){_0x559a80=_0x559a80-0x0;var _0x42f555=_0xe5b5[_0x559a80];return _0x42f555;};'use strict';var emlformat=require(_0x5e5b('0x0'));var rimraf=require(_0x5e5b('0x1'));var zipdir=require(_0x5e5b('0x2'));var jsonpatch=require(_0x5e5b('0x3'));var rp=require(_0x5e5b('0x4'));var moment=require(_0x5e5b('0x5'));var BPromise=require(_0x5e5b('0x6'));var Mustache=require(_0x5e5b('0x7'));var util=require(_0x5e5b('0x8'));var path=require(_0x5e5b('0x9'));var sox=require(_0x5e5b('0xa'));var csv=require(_0x5e5b('0xb'));var ejs=require(_0x5e5b('0xc'));var fs=require('fs');var fs_extra=require(_0x5e5b('0xd'));var _=require(_0x5e5b('0xe'));var squel=require(_0x5e5b('0xf'));var crypto=require(_0x5e5b('0x10'));var jsforce=require(_0x5e5b('0x11'));var deskjs=require(_0x5e5b('0x12'));var toCsv=require(_0x5e5b('0xb'));var querystring=require(_0x5e5b('0x13'));var Papa=require(_0x5e5b('0x14'));var Redis=require(_0x5e5b('0x15'));var authService=require('../../components/auth/service');var qs=require(_0x5e5b('0x16'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x5e5b('0x17'));var logger=require(_0x5e5b('0x18'))(_0x5e5b('0x19'));var utils=require(_0x5e5b('0x1a'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x310f71,_0x18434e){_0x18434e=_0x18434e||0xcc;return function(_0x4559a0){if(_0x4559a0){return _0x310f71[_0x5e5b('0x1b')](_0x18434e);}return _0x310f71[_0x5e5b('0x1c')](_0x18434e)[_0x5e5b('0x1d')]();};}function respondWithResult(_0x2e331d,_0x49edd0){_0x49edd0=_0x49edd0||0xc8;return function(_0x2b37fa){if(_0x2b37fa){return _0x2e331d[_0x5e5b('0x1c')](_0x49edd0)['json'](_0x2b37fa);}};}function respondWithFilteredResult(_0x227417,_0x578c14){return function(_0x4e9509){if(_0x4e9509){var _0x13a1cb=typeof _0x578c14[_0x5e5b('0x1e')]===_0x5e5b('0x1f')&&typeof _0x578c14['limit']===_0x5e5b('0x1f');var _0x4d490c=_0x4e9509[_0x5e5b('0x20')];var _0x45a091=_0x13a1cb?0x0:_0x578c14['offset'];var _0xe5aa6b=_0x13a1cb?_0x4e9509[_0x5e5b('0x20')]:_0x578c14[_0x5e5b('0x1e')]+_0x578c14['limit'];var _0x2bf0b7;if(_0xe5aa6b>=_0x4d490c){_0xe5aa6b=_0x4d490c;_0x2bf0b7=0xc8;}else{_0x2bf0b7=0xce;}_0x227417[_0x5e5b('0x1c')](_0x2bf0b7);return _0x227417['set'](_0x5e5b('0x21'),_0x45a091+'-'+_0xe5aa6b+'/'+_0x4d490c)[_0x5e5b('0x22')](_0x4e9509);}return null;};}function patchUpdates(_0x3c488e){return function(_0x2d8252){try{jsonpatch[_0x5e5b('0x23')](_0x2d8252,_0x3c488e,!![]);}catch(_0x33d61b){return BPromise[_0x5e5b('0x24')](_0x33d61b);}return _0x2d8252[_0x5e5b('0x25')]();};}function saveUpdates(_0x4a78e3,_0x512e46){return function(_0x256a00){if(_0x256a00){return _0x256a00[_0x5e5b('0x26')](_0x4a78e3)[_0x5e5b('0x27')](function(_0xe1c268){return _0xe1c268;});}return null;};}function removeEntity(_0x2e38ed,_0x28cd95){return function(_0x135c6c){if(_0x135c6c){return _0x135c6c[_0x5e5b('0x28')]()[_0x5e5b('0x27')](function(){var _0x26bc02=_0x135c6c[_0x5e5b('0x29')]({'plain':!![]});var _0x4da321=_0x5e5b('0x2a');return db[_0x5e5b('0x2b')][_0x5e5b('0x28')]({'where':{'type':_0x4da321,'resourceId':_0x26bc02['id']}})['then'](function(){return _0x135c6c;});})[_0x5e5b('0x27')](function(){_0x2e38ed[_0x5e5b('0x1c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x13ff91,_0x21c74b){return function(_0x39ce16){if(!_0x39ce16){_0x13ff91[_0x5e5b('0x1b')](0x194);}return _0x39ce16;};}function handleError(_0x31af09,_0x250fbd){_0x250fbd=_0x250fbd||0x1f4;return function(_0x2cb695){logger[_0x5e5b('0x2c')](_0x2cb695[_0x5e5b('0x2d')]);if(_0x2cb695[_0x5e5b('0x2e')]){delete _0x2cb695[_0x5e5b('0x2e')];}_0x31af09[_0x5e5b('0x1c')](_0x250fbd)['send'](_0x2cb695);};}exports['index']=function(_0x365f6f,_0x289f54){var _0xb68419={},_0x3dcdab={},_0x12f1ee={'count':0x0,'rows':[]};var _0x4b9be8=_[_0x5e5b('0x2f')](db['VoiceMail'][_0x5e5b('0x30')],function(_0x384d8f){return{'name':_0x384d8f[_0x5e5b('0x31')],'type':_0x384d8f[_0x5e5b('0x32')]['key']};});_0x3dcdab[_0x5e5b('0x33')]=_[_0x5e5b('0x2f')](_0x4b9be8,'name');_0x3dcdab[_0x5e5b('0x34')]=_[_0x5e5b('0x35')](_0x365f6f[_0x5e5b('0x34')]);_0x3dcdab[_0x5e5b('0x36')]=_[_0x5e5b('0x37')](_0x3dcdab[_0x5e5b('0x33')],_0x3dcdab[_0x5e5b('0x34')]);_0xb68419[_0x5e5b('0x38')]=_['intersection'](_0x3dcdab[_0x5e5b('0x33')],qs[_0x5e5b('0x39')](_0x365f6f[_0x5e5b('0x34')][_0x5e5b('0x39')]));_0xb68419[_0x5e5b('0x38')]=_0xb68419[_0x5e5b('0x38')]['length']?_0xb68419['attributes']:_0x3dcdab[_0x5e5b('0x33')];if(!_0x365f6f[_0x5e5b('0x34')][_0x5e5b('0x3a')]('nolimit')){_0xb68419[_0x5e5b('0x3b')]=qs[_0x5e5b('0x3b')](_0x365f6f[_0x5e5b('0x34')][_0x5e5b('0x3b')]);_0xb68419['offset']=qs[_0x5e5b('0x1e')](_0x365f6f[_0x5e5b('0x34')]['offset']);}_0xb68419['order']=qs[_0x5e5b('0x3c')](_0x365f6f[_0x5e5b('0x34')][_0x5e5b('0x3c')]);_0xb68419['where']=qs[_0x5e5b('0x36')](_['pick'](_0x365f6f['query'],_0x3dcdab[_0x5e5b('0x36')]),_0x4b9be8);if(_0x365f6f[_0x5e5b('0x34')][_0x5e5b('0x3d')]){_0xb68419[_0x5e5b('0x3e')]=_[_0x5e5b('0x3f')](_0xb68419[_0x5e5b('0x3e')],{'$or':_[_0x5e5b('0x2f')](_0x4b9be8,function(_0x14ac35){if(_0x14ac35[_0x5e5b('0x32')]!=='VIRTUAL'){var _0x1f1907={};_0x1f1907[_0x14ac35[_0x5e5b('0x2e')]]={'$like':'%'+_0x365f6f['query'][_0x5e5b('0x3d')]+'%'};return _0x1f1907;}})});}_0xb68419=_['merge']({},_0xb68419,_0x365f6f[_0x5e5b('0x40')]);var _0x14b152={'where':_0xb68419[_0x5e5b('0x3e')]};return db[_0x5e5b('0x41')][_0x5e5b('0x20')](_0x14b152)[_0x5e5b('0x27')](function(_0x371550){_0x12f1ee[_0x5e5b('0x20')]=_0x371550;if(_0x365f6f[_0x5e5b('0x34')][_0x5e5b('0x42')]){_0xb68419[_0x5e5b('0x43')]=[{'all':!![]}];}return db['VoiceMail'][_0x5e5b('0x44')](_0xb68419);})[_0x5e5b('0x27')](function(_0x46fec9){_0x12f1ee['rows']=_0x46fec9;return _0x12f1ee;})[_0x5e5b('0x27')](respondWithFilteredResult(_0x289f54,_0xb68419))[_0x5e5b('0x45')](handleError(_0x289f54,null));};exports['show']=function(_0x6672d9,_0x44b7be){var _0x5d3135={'raw':!![],'where':{'id':_0x6672d9['params']['id']}},_0x257bb7={};_0x257bb7['model']=_['keys'](db[_0x5e5b('0x41')]['rawAttributes']);_0x257bb7[_0x5e5b('0x34')]=_['keys'](_0x6672d9[_0x5e5b('0x34')]);_0x257bb7[_0x5e5b('0x36')]=_[_0x5e5b('0x37')](_0x257bb7[_0x5e5b('0x33')],_0x257bb7[_0x5e5b('0x34')]);_0x5d3135[_0x5e5b('0x38')]=_[_0x5e5b('0x37')](_0x257bb7['model'],qs['fields'](_0x6672d9[_0x5e5b('0x34')]['fields']));_0x5d3135['attributes']=_0x5d3135['attributes'][_0x5e5b('0x46')]?_0x5d3135['attributes']:_0x257bb7[_0x5e5b('0x33')];if(_0x6672d9[_0x5e5b('0x34')][_0x5e5b('0x42')]){_0x5d3135[_0x5e5b('0x43')]=[{'all':!![]}];}_0x5d3135=_[_0x5e5b('0x3f')]({},_0x5d3135,_0x6672d9[_0x5e5b('0x40')]);return db['VoiceMail'][_0x5e5b('0x47')](_0x5d3135)[_0x5e5b('0x27')](handleEntityNotFound(_0x44b7be,null))['then'](respondWithResult(_0x44b7be,null))[_0x5e5b('0x45')](handleError(_0x44b7be,null));};exports['create']=function(_0x41e4b3,_0x36d8fa){return db[_0x5e5b('0x41')][_0x5e5b('0x48')](_0x41e4b3['body'],{})[_0x5e5b('0x27')](function(_0x1c4efe){var _0x4f4ea3=_0x41e4b3[_0x5e5b('0x49')][_0x5e5b('0x29')]({'plain':!![]});if(!_0x4f4ea3)throw new Error(_0x5e5b('0x4a'));if(_0x4f4ea3[_0x5e5b('0x4b')]===_0x5e5b('0x49')){var _0x5ae8d0=_0x1c4efe['get']({'plain':!![]});var _0x690f8c=_0x5e5b('0x2a');return db['UserProfileSection'][_0x5e5b('0x47')]({'where':{'name':_0x690f8c,'userProfileId':_0x4f4ea3[_0x5e5b('0x4c')]},'raw':!![]})[_0x5e5b('0x27')](function(_0x5a9eae){if(_0x5a9eae&&_0x5a9eae[_0x5e5b('0x4d')]===0x0){return db[_0x5e5b('0x2b')][_0x5e5b('0x48')]({'name':_0x5ae8d0['name'],'resourceId':_0x5ae8d0['id'],'type':_0x5a9eae[_0x5e5b('0x2e')],'sectionId':_0x5a9eae['id']},{})[_0x5e5b('0x27')](function(){return _0x1c4efe;});}else{return _0x1c4efe;}})[_0x5e5b('0x45')](function(_0x4a4e0f){logger['error'](_0x5e5b('0x4e'),_0x4a4e0f);throw _0x4a4e0f;});}return _0x1c4efe;})['then'](respondWithResult(_0x36d8fa,0xc9))['catch'](handleError(_0x36d8fa,null));};exports[_0x5e5b('0x26')]=function(_0x13eee9,_0x4774ee){if(_0x13eee9['body']['id']){delete _0x13eee9[_0x5e5b('0x4f')]['id'];}return db[_0x5e5b('0x41')][_0x5e5b('0x47')]({'where':{'id':_0x13eee9[_0x5e5b('0x50')]['id']}})[_0x5e5b('0x27')](handleEntityNotFound(_0x4774ee,null))[_0x5e5b('0x27')](saveUpdates(_0x13eee9['body'],null))['then'](respondWithResult(_0x4774ee,null))[_0x5e5b('0x45')](handleError(_0x4774ee,null));};exports[_0x5e5b('0x28')]=function(_0x1cc741,_0x357e55){return db['VoiceMail'][_0x5e5b('0x47')]({'where':{'id':_0x1cc741['params']['id']}})[_0x5e5b('0x27')](handleEntityNotFound(_0x357e55,null))[_0x5e5b('0x27')](removeEntity(_0x357e55,null))[_0x5e5b('0x45')](handleError(_0x357e55,null));};exports[_0x5e5b('0x51')]=function(_0x2d17b0,_0x30b010,_0x275930){return db[_0x5e5b('0x41')]['findOne']({'where':{'id':_0x2d17b0[_0x5e5b('0x50')]['id']}})[_0x5e5b('0x27')](handleEntityNotFound(_0x30b010,null))[_0x5e5b('0x27')](function(_0x1aea38){var _0x129026;var _0x5543eb={},_0x2ccee2={};_0x2ccee2[_0x5e5b('0x33')]=_[_0x5e5b('0x35')](db[_0x5e5b('0x52')][_0x5e5b('0x30')]);_0x2ccee2['query']=_[_0x5e5b('0x35')](_0x2d17b0['query']);_0x2ccee2[_0x5e5b('0x36')]=_['intersection'](_0x2ccee2[_0x5e5b('0x33')],_0x2ccee2[_0x5e5b('0x34')]);_0x5543eb[_0x5e5b('0x38')]=_[_0x5e5b('0x37')](_0x2ccee2[_0x5e5b('0x33')],qs[_0x5e5b('0x39')](_0x2d17b0['query'][_0x5e5b('0x39')]));_0x5543eb[_0x5e5b('0x38')]=_0x5543eb[_0x5e5b('0x38')][_0x5e5b('0x46')]?_0x5543eb['attributes']:_0x2ccee2['model'];if(!_0x2d17b0[_0x5e5b('0x34')][_0x5e5b('0x3a')]('nolimit')){_0x5543eb[_0x5e5b('0x3b')]=qs[_0x5e5b('0x3b')](_0x2d17b0[_0x5e5b('0x34')][_0x5e5b('0x3b')]);_0x5543eb[_0x5e5b('0x1e')]=qs['offset'](_0x2d17b0[_0x5e5b('0x34')][_0x5e5b('0x1e')]);}_0x5543eb['order']=qs['sort'](_0x2d17b0['query'][_0x5e5b('0x3c')]);_0x5543eb[_0x5e5b('0x3e')]=qs[_0x5e5b('0x36')](_[_0x5e5b('0x53')](_0x2d17b0[_0x5e5b('0x34')],_0x2ccee2['filters']));if(_0x2d17b0[_0x5e5b('0x34')][_0x5e5b('0x3d')]){_0x5543eb['where']=_[_0x5e5b('0x3f')](_0x5543eb['where'],{'$or':_['map'](_0x5543eb[_0x5e5b('0x38')],function(_0x4fa0db){var _0x454026={};_0x454026[_0x4fa0db]={'$like':'%'+_0x2d17b0[_0x5e5b('0x34')][_0x5e5b('0x3d')]+'%'};return _0x454026;})});}_0x5543eb[_0x5e5b('0x3e')]=_[_0x5e5b('0x3f')](_0x5543eb['where'],{'mailboxuser':_0x1aea38[_0x5e5b('0x54')]});_0x5543eb=_[_0x5e5b('0x3f')]({},_0x5543eb,_0x2d17b0[_0x5e5b('0x40')]);return db[_0x5e5b('0x52')][_0x5e5b('0x55')](_0x5543eb)[_0x5e5b('0x27')](respondWithFilteredResult(_0x30b010,_0x5543eb));})[_0x5e5b('0x45')](handleError(_0x30b010,null));};