Built motion from commit (unavailable).|2.5.31
[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 _0x71cb=['index','map','rawAttributes','fieldName','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','sort','where','pick','filters','merge','type','VIRTUAL','options','VoiceMail','include','findAll','rows','catch','params','includeAll','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','getMessages','findOne','nolimit','order','filter','mailbox','VoiceMailMessage','findAndCountAll','rimraf','zip-dir','request-promise','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/utils','../../mysqldb','sendStatus','status','end','json','undefined','count','offset','limit','Content-Range','reject','save','update','then','destroy','get','Voicemails','error','stack','name'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x71cb,0x84));var _0xb71c=function(_0x5b644e,_0x2e5e07){_0x5b644e=_0x5b644e-0x0;var _0x49c6bf=_0x71cb[_0x5b644e];return _0x49c6bf;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xb71c('0x0'));var zipdir=require(_0xb71c('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xb71c('0x2'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xb71c('0x3'));var util=require(_0xb71c('0x4'));var path=require(_0xb71c('0x5'));var sox=require(_0xb71c('0x6'));var csv=require(_0xb71c('0x7'));var ejs=require(_0xb71c('0x8'));var fs=require('fs');var fs_extra=require(_0xb71c('0x9'));var _=require(_0xb71c('0xa'));var squel=require(_0xb71c('0xb'));var crypto=require(_0xb71c('0xc'));var jsforce=require(_0xb71c('0xd'));var deskjs=require('desk.js');var toCsv=require(_0xb71c('0x7'));var querystring=require(_0xb71c('0xe'));var Papa=require(_0xb71c('0xf'));var Redis=require('ioredis');var authService=require(_0xb71c('0x10'));var qs=require(_0xb71c('0x11'));var as=require(_0xb71c('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0xb71c('0x13'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xb71c('0x14'))['db'];function respondWithStatusCode(_0x5d81cd,_0x4274c4){_0x4274c4=_0x4274c4||0xcc;return function(_0x3d4e58){if(_0x3d4e58){return _0x5d81cd[_0xb71c('0x15')](_0x4274c4);}return _0x5d81cd[_0xb71c('0x16')](_0x4274c4)[_0xb71c('0x17')]();};}function respondWithResult(_0x221f92,_0x24502e){_0x24502e=_0x24502e||0xc8;return function(_0x312693){if(_0x312693){return _0x221f92[_0xb71c('0x16')](_0x24502e)[_0xb71c('0x18')](_0x312693);}};}function respondWithFilteredResult(_0x1c6dbe,_0x15deba){return function(_0x3eb181){if(_0x3eb181){var _0x8902b8=typeof _0x15deba['offset']===_0xb71c('0x19')&&typeof _0x15deba['limit']===_0xb71c('0x19');var _0x5dbeef=_0x3eb181[_0xb71c('0x1a')];var _0x1273ba=_0x8902b8?0x0:_0x15deba[_0xb71c('0x1b')];var _0xf72eaf=_0x8902b8?_0x3eb181[_0xb71c('0x1a')]:_0x15deba['offset']+_0x15deba[_0xb71c('0x1c')];var _0x3fdc7b;if(_0xf72eaf>=_0x5dbeef){_0xf72eaf=_0x5dbeef;_0x3fdc7b=0xc8;}else{_0x3fdc7b=0xce;}_0x1c6dbe['status'](_0x3fdc7b);return _0x1c6dbe['set'](_0xb71c('0x1d'),_0x1273ba+'-'+_0xf72eaf+'/'+_0x5dbeef)['json'](_0x3eb181);}return null;};}function patchUpdates(_0x3d5682){return function(_0x1be459){try{jsonpatch['apply'](_0x1be459,_0x3d5682,!![]);}catch(_0xb61378){return BPromise[_0xb71c('0x1e')](_0xb61378);}return _0x1be459[_0xb71c('0x1f')]();};}function saveUpdates(_0x20a122,_0x40776c){return function(_0x521b1d){if(_0x521b1d){return _0x521b1d[_0xb71c('0x20')](_0x20a122)[_0xb71c('0x21')](function(_0x4fdc03){return _0x4fdc03;});}return null;};}function removeEntity(_0x14ac67,_0x2751ce){return function(_0x21e839){if(_0x21e839){return _0x21e839[_0xb71c('0x22')]()['then'](function(){var _0x2bb973=_0x21e839[_0xb71c('0x23')]({'plain':!![]});var _0x5e8866=_0xb71c('0x24');return db['UserProfileResource'][_0xb71c('0x22')]({'where':{'type':_0x5e8866,'resourceId':_0x2bb973['id']}})[_0xb71c('0x21')](function(){return _0x21e839;});})[_0xb71c('0x21')](function(){_0x14ac67[_0xb71c('0x16')](0xcc)['end']();});}};}function handleEntityNotFound(_0x32a376,_0x19339d){return function(_0x3fdbdb){if(!_0x3fdbdb){_0x32a376[_0xb71c('0x15')](0x194);}return _0x3fdbdb;};}function handleError(_0xcbd922,_0x347ec8){_0x347ec8=_0x347ec8||0x1f4;return function(_0x21ad8a){logger[_0xb71c('0x25')](_0x21ad8a[_0xb71c('0x26')]);if(_0x21ad8a[_0xb71c('0x27')]){delete _0x21ad8a[_0xb71c('0x27')];}_0xcbd922['status'](_0x347ec8)['send'](_0x21ad8a);};}exports[_0xb71c('0x28')]=function(_0x573989,_0x4bebd1){var _0x4b6b24={},_0x1c6858={},_0xd81a09={'count':0x0,'rows':[]};var _0x403d8f=_[_0xb71c('0x29')](db['VoiceMail'][_0xb71c('0x2a')],function(_0x375cd7){return{'name':_0x375cd7[_0xb71c('0x2b')],'type':_0x375cd7['type'][_0xb71c('0x2c')]};});_0x1c6858[_0xb71c('0x2d')]=_[_0xb71c('0x29')](_0x403d8f,_0xb71c('0x27'));_0x1c6858[_0xb71c('0x2e')]=_[_0xb71c('0x2f')](_0x573989[_0xb71c('0x2e')]);_0x1c6858['filters']=_[_0xb71c('0x30')](_0x1c6858[_0xb71c('0x2d')],_0x1c6858[_0xb71c('0x2e')]);_0x4b6b24[_0xb71c('0x31')]=_[_0xb71c('0x30')](_0x1c6858[_0xb71c('0x2d')],qs['fields'](_0x573989[_0xb71c('0x2e')][_0xb71c('0x32')]));_0x4b6b24[_0xb71c('0x31')]=_0x4b6b24[_0xb71c('0x31')][_0xb71c('0x33')]?_0x4b6b24[_0xb71c('0x31')]:_0x1c6858['model'];if(!_0x573989[_0xb71c('0x2e')][_0xb71c('0x34')]('nolimit')){_0x4b6b24[_0xb71c('0x1c')]=qs[_0xb71c('0x1c')](_0x573989[_0xb71c('0x2e')][_0xb71c('0x1c')]);_0x4b6b24['offset']=qs[_0xb71c('0x1b')](_0x573989[_0xb71c('0x2e')][_0xb71c('0x1b')]);}_0x4b6b24['order']=qs[_0xb71c('0x35')](_0x573989[_0xb71c('0x2e')][_0xb71c('0x35')]);_0x4b6b24[_0xb71c('0x36')]=qs['filters'](_[_0xb71c('0x37')](_0x573989[_0xb71c('0x2e')],_0x1c6858[_0xb71c('0x38')]),_0x403d8f);if(_0x573989[_0xb71c('0x2e')]['filter']){_0x4b6b24[_0xb71c('0x36')]=_[_0xb71c('0x39')](_0x4b6b24['where'],{'$or':_['map'](_0x403d8f,function(_0x52028b){if(_0x52028b[_0xb71c('0x3a')]!==_0xb71c('0x3b')){var _0x1ce78a={};_0x1ce78a[_0x52028b['name']]={'$like':'%'+_0x573989[_0xb71c('0x2e')]['filter']+'%'};return _0x1ce78a;}})});}_0x4b6b24=_['merge']({},_0x4b6b24,_0x573989[_0xb71c('0x3c')]);var _0x2f5413={'where':_0x4b6b24[_0xb71c('0x36')]};return db[_0xb71c('0x3d')][_0xb71c('0x1a')](_0x2f5413)[_0xb71c('0x21')](function(_0x344af6){_0xd81a09['count']=_0x344af6;if(_0x573989['query']['includeAll']){_0x4b6b24[_0xb71c('0x3e')]=[{'all':!![]}];}return db[_0xb71c('0x3d')][_0xb71c('0x3f')](_0x4b6b24);})['then'](function(_0x581a3f){_0xd81a09[_0xb71c('0x40')]=_0x581a3f;return _0xd81a09;})[_0xb71c('0x21')](respondWithFilteredResult(_0x4bebd1,_0x4b6b24))[_0xb71c('0x41')](handleError(_0x4bebd1,null));};exports['show']=function(_0x368f4c,_0x5404a5){var _0x365a4c={'raw':!![],'where':{'id':_0x368f4c[_0xb71c('0x42')]['id']}},_0x322ce5={};_0x322ce5[_0xb71c('0x2d')]=_[_0xb71c('0x2f')](db[_0xb71c('0x3d')]['rawAttributes']);_0x322ce5[_0xb71c('0x2e')]=_[_0xb71c('0x2f')](_0x368f4c[_0xb71c('0x2e')]);_0x322ce5[_0xb71c('0x38')]=_[_0xb71c('0x30')](_0x322ce5[_0xb71c('0x2d')],_0x322ce5['query']);_0x365a4c[_0xb71c('0x31')]=_['intersection'](_0x322ce5[_0xb71c('0x2d')],qs[_0xb71c('0x32')](_0x368f4c[_0xb71c('0x2e')][_0xb71c('0x32')]));_0x365a4c[_0xb71c('0x31')]=_0x365a4c['attributes'][_0xb71c('0x33')]?_0x365a4c['attributes']:_0x322ce5[_0xb71c('0x2d')];if(_0x368f4c[_0xb71c('0x2e')][_0xb71c('0x43')]){_0x365a4c['include']=[{'all':!![]}];}_0x365a4c=_[_0xb71c('0x39')]({},_0x365a4c,_0x368f4c[_0xb71c('0x3c')]);return db[_0xb71c('0x3d')][_0xb71c('0x44')](_0x365a4c)['then'](handleEntityNotFound(_0x5404a5,null))['then'](respondWithResult(_0x5404a5,null))[_0xb71c('0x41')](handleError(_0x5404a5,null));};exports[_0xb71c('0x45')]=function(_0x5a79ee,_0x3b635c){return db['VoiceMail']['create'](_0x5a79ee[_0xb71c('0x46')],{})[_0xb71c('0x21')](function(_0x55dce2){var _0x380b32=_0x5a79ee['user'][_0xb71c('0x23')]({'plain':!![]});if(!_0x380b32)throw new Error(_0xb71c('0x47'));if(_0x380b32[_0xb71c('0x48')]==='user'){var _0x3573b5=_0x55dce2[_0xb71c('0x23')]({'plain':!![]});var _0x47fec2=_0xb71c('0x24');return db[_0xb71c('0x49')]['find']({'where':{'name':_0x47fec2,'userProfileId':_0x380b32[_0xb71c('0x4a')]},'raw':!![]})[_0xb71c('0x21')](function(_0x5b5c2c){if(_0x5b5c2c&&_0x5b5c2c[_0xb71c('0x4b')]===0x0){return db[_0xb71c('0x4c')][_0xb71c('0x45')]({'name':_0x3573b5[_0xb71c('0x27')],'resourceId':_0x3573b5['id'],'type':_0x5b5c2c[_0xb71c('0x27')],'sectionId':_0x5b5c2c['id']},{})[_0xb71c('0x21')](function(){return _0x55dce2;});}else{return _0x55dce2;}})[_0xb71c('0x41')](function(_0x133f71){logger['error'](_0xb71c('0x4d'),_0x133f71);throw _0x133f71;});}return _0x55dce2;})['then'](respondWithResult(_0x3b635c,0xc9))[_0xb71c('0x41')](handleError(_0x3b635c,null));};exports[_0xb71c('0x20')]=function(_0x27c218,_0x538442){if(_0x27c218[_0xb71c('0x46')]['id']){delete _0x27c218[_0xb71c('0x46')]['id'];}return db[_0xb71c('0x3d')][_0xb71c('0x44')]({'where':{'id':_0x27c218[_0xb71c('0x42')]['id']}})['then'](handleEntityNotFound(_0x538442,null))[_0xb71c('0x21')](saveUpdates(_0x27c218['body'],null))[_0xb71c('0x21')](respondWithResult(_0x538442,null))[_0xb71c('0x41')](handleError(_0x538442,null));};exports[_0xb71c('0x22')]=function(_0x304d78,_0x33c1c4){return db[_0xb71c('0x3d')][_0xb71c('0x44')]({'where':{'id':_0x304d78['params']['id']}})[_0xb71c('0x21')](handleEntityNotFound(_0x33c1c4,null))[_0xb71c('0x21')](removeEntity(_0x33c1c4,null))[_0xb71c('0x41')](handleError(_0x33c1c4,null));};exports[_0xb71c('0x4e')]=function(_0x33389d,_0x425821,_0x1b43c0){return db[_0xb71c('0x3d')][_0xb71c('0x4f')]({'where':{'id':_0x33389d[_0xb71c('0x42')]['id']}})['then'](handleEntityNotFound(_0x425821,null))[_0xb71c('0x21')](function(_0x590770){var _0x37d50e;var _0x2753de={},_0x166696={};_0x166696[_0xb71c('0x2d')]=_['keys'](db['VoiceMailMessage'][_0xb71c('0x2a')]);_0x166696[_0xb71c('0x2e')]=_[_0xb71c('0x2f')](_0x33389d['query']);_0x166696[_0xb71c('0x38')]=_[_0xb71c('0x30')](_0x166696[_0xb71c('0x2d')],_0x166696[_0xb71c('0x2e')]);_0x2753de['attributes']=_[_0xb71c('0x30')](_0x166696['model'],qs['fields'](_0x33389d[_0xb71c('0x2e')][_0xb71c('0x32')]));_0x2753de['attributes']=_0x2753de[_0xb71c('0x31')][_0xb71c('0x33')]?_0x2753de[_0xb71c('0x31')]:_0x166696[_0xb71c('0x2d')];if(!_0x33389d['query'][_0xb71c('0x34')](_0xb71c('0x50'))){_0x2753de[_0xb71c('0x1c')]=qs[_0xb71c('0x1c')](_0x33389d['query'][_0xb71c('0x1c')]);_0x2753de[_0xb71c('0x1b')]=qs['offset'](_0x33389d[_0xb71c('0x2e')][_0xb71c('0x1b')]);}_0x2753de[_0xb71c('0x51')]=qs[_0xb71c('0x35')](_0x33389d['query'][_0xb71c('0x35')]);_0x2753de[_0xb71c('0x36')]=qs[_0xb71c('0x38')](_[_0xb71c('0x37')](_0x33389d[_0xb71c('0x2e')],_0x166696[_0xb71c('0x38')]));if(_0x33389d[_0xb71c('0x2e')][_0xb71c('0x52')]){_0x2753de[_0xb71c('0x36')]=_[_0xb71c('0x39')](_0x2753de[_0xb71c('0x36')],{'$or':_['map'](_0x2753de[_0xb71c('0x31')],function(_0x2a25db){var _0x4ebb1a={};_0x4ebb1a[_0x2a25db]={'$like':'%'+_0x33389d[_0xb71c('0x2e')][_0xb71c('0x52')]+'%'};return _0x4ebb1a;})});}_0x2753de[_0xb71c('0x36')]=_[_0xb71c('0x39')](_0x2753de[_0xb71c('0x36')],{'mailboxuser':_0x590770[_0xb71c('0x53')]});_0x2753de=_[_0xb71c('0x39')]({},_0x2753de,_0x33389d[_0xb71c('0x3c')]);return db[_0xb71c('0x54')][_0xb71c('0x55')](_0x2753de)[_0xb71c('0x21')](respondWithFilteredResult(_0x425821,_0x2753de));})['catch'](handleError(_0x425821,null));};