Built motion from commit c116dc8b.|2.6.30
[motion2.git] / server / api / voiceMailMessage / voiceMailMessage.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 _0x54bb=['name','index','rawAttributes','fieldName','type','model','differenceBy','query','filters','intersection','attributes','fields','length','nolimit','sort','where','pick','filter','merge','VIRTUAL','options','VoiceMailMessage','includeAll','include','then','rows','catch','show','params','keys','find','create','body','download','recording','msg_id','Sequelize','ValidationError','VoiceMailMessage\x20not\x20found','audio/wav','Content-Disposition','attachment;\x20filename=\x22','send','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','json','apply','reject','save','update','destroy','error','stack'];(function(_0x5a99db,_0x1cece5){var _0x3aad62=function(_0x334cb7){while(--_0x334cb7){_0x5a99db['push'](_0x5a99db['shift']());}};_0x3aad62(++_0x1cece5);}(_0x54bb,0xd5));var _0xb54b=function(_0x4e7bb4,_0x42572c){_0x4e7bb4=_0x4e7bb4-0x0;var _0x456e48=_0x54bb[_0x4e7bb4];return _0x456e48;};'use strict';var emlformat=require(_0xb54b('0x0'));var rimraf=require(_0xb54b('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xb54b('0x2'));var rp=require(_0xb54b('0x3'));var moment=require('moment');var BPromise=require(_0xb54b('0x4'));var Mustache=require(_0xb54b('0x5'));var util=require(_0xb54b('0x6'));var path=require(_0xb54b('0x7'));var sox=require('sox');var csv=require(_0xb54b('0x8'));var ejs=require(_0xb54b('0x9'));var fs=require('fs');var fs_extra=require(_0xb54b('0xa'));var _=require(_0xb54b('0xb'));var squel=require(_0xb54b('0xc'));var crypto=require(_0xb54b('0xd'));var jsforce=require(_0xb54b('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xb54b('0x8'));var querystring=require(_0xb54b('0xf'));var Papa=require(_0xb54b('0x10'));var Redis=require(_0xb54b('0x11'));var authService=require(_0xb54b('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0xb54b('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xb54b('0x14'));var utils=require(_0xb54b('0x15'));var config=require(_0xb54b('0x16'));var licenseUtil=require(_0xb54b('0x17'));var db=require(_0xb54b('0x18'))['db'];function respondWithStatusCode(_0x17bef0,_0x2a2c8e){_0x2a2c8e=_0x2a2c8e||0xcc;return function(_0x266fd9){if(_0x266fd9){return _0x17bef0[_0xb54b('0x19')](_0x2a2c8e);}return _0x17bef0[_0xb54b('0x1a')](_0x2a2c8e)[_0xb54b('0x1b')]();};}function respondWithResult(_0x382205,_0x2d358d){_0x2d358d=_0x2d358d||0xc8;return function(_0x2ac341){if(_0x2ac341){return _0x382205[_0xb54b('0x1a')](_0x2d358d)['json'](_0x2ac341);}};}function respondWithFilteredResult(_0x43a033,_0x255bd0){return function(_0x156c6c){if(_0x156c6c){var _0x15028f=typeof _0x255bd0[_0xb54b('0x1c')]===_0xb54b('0x1d')&&typeof _0x255bd0[_0xb54b('0x1e')]===_0xb54b('0x1d');var _0x15bc7f=_0x156c6c[_0xb54b('0x1f')];var _0x295b70=_0x15028f?0x0:_0x255bd0[_0xb54b('0x1c')];var _0x3a8604=_0x15028f?_0x156c6c['count']:_0x255bd0['offset']+_0x255bd0[_0xb54b('0x1e')];var _0x375739;if(_0x3a8604>=_0x15bc7f){_0x3a8604=_0x15bc7f;_0x375739=0xc8;}else{_0x375739=0xce;}_0x43a033['status'](_0x375739);return _0x43a033[_0xb54b('0x20')](_0xb54b('0x21'),_0x295b70+'-'+_0x3a8604+'/'+_0x15bc7f)[_0xb54b('0x22')](_0x156c6c);}return null;};}function patchUpdates(_0x2bce3a){return function(_0x5a7689){try{jsonpatch[_0xb54b('0x23')](_0x5a7689,_0x2bce3a,!![]);}catch(_0x390d1a){return BPromise[_0xb54b('0x24')](_0x390d1a);}return _0x5a7689[_0xb54b('0x25')]();};}function saveUpdates(_0x4a8355,_0x5b789b){return function(_0x10f545){if(_0x10f545){return _0x10f545[_0xb54b('0x26')](_0x4a8355)['then'](function(_0x3ff444){return _0x3ff444;});}return null;};}function removeEntity(_0x4788e4,_0x198725){return function(_0x5f38d1){if(_0x5f38d1){return _0x5f38d1[_0xb54b('0x27')]()['then'](function(){_0x4788e4[_0xb54b('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x49b7c4,_0xcbc47e){return function(_0xd67eca){if(!_0xd67eca){_0x49b7c4[_0xb54b('0x19')](0x194);}return _0xd67eca;};}function handleError(_0x43807c,_0x1468ac){_0x1468ac=_0x1468ac||0x1f4;return function(_0x40472a){logger[_0xb54b('0x28')](_0x40472a[_0xb54b('0x29')]);if(_0x40472a[_0xb54b('0x2a')]){delete _0x40472a[_0xb54b('0x2a')];}_0x43807c[_0xb54b('0x1a')](_0x1468ac)['send'](_0x40472a);};}exports[_0xb54b('0x2b')]=function(_0x46977a,_0x40fe32){var _0x24e713={},_0x54f424={},_0x928af={'count':0x0,'rows':[]};var _0x55aa18=_['map'](db['VoiceMailMessage'][_0xb54b('0x2c')],function(_0x380acf){return{'name':_0x380acf[_0xb54b('0x2d')],'type':_0x380acf[_0xb54b('0x2e')]['key']};});_0x54f424[_0xb54b('0x2f')]=_[_0xb54b('0x30')](_['map'](_0x55aa18,_0xb54b('0x2a')),[_0xb54b('0x2a')]);_0x54f424[_0xb54b('0x31')]=_['keys'](_0x46977a[_0xb54b('0x31')]);_0x54f424[_0xb54b('0x32')]=_[_0xb54b('0x33')](_0x54f424[_0xb54b('0x2f')],_0x54f424[_0xb54b('0x31')]);_0x24e713[_0xb54b('0x34')]=_[_0xb54b('0x33')](_0x54f424[_0xb54b('0x2f')],qs[_0xb54b('0x35')](_0x46977a[_0xb54b('0x31')][_0xb54b('0x35')]));_0x24e713['attributes']=_0x24e713[_0xb54b('0x34')][_0xb54b('0x36')]?_0x24e713[_0xb54b('0x34')]:_0x54f424[_0xb54b('0x2f')];if(!_0x46977a['query']['hasOwnProperty'](_0xb54b('0x37'))){_0x24e713[_0xb54b('0x1e')]=qs['limit'](_0x46977a[_0xb54b('0x31')][_0xb54b('0x1e')]);_0x24e713['offset']=qs['offset'](_0x46977a[_0xb54b('0x31')][_0xb54b('0x1c')]);}_0x24e713['order']=qs[_0xb54b('0x38')](_0x46977a[_0xb54b('0x31')]['sort']);_0x24e713[_0xb54b('0x39')]=qs[_0xb54b('0x32')](_[_0xb54b('0x3a')](_0x46977a[_0xb54b('0x31')],_0x54f424[_0xb54b('0x32')]),_0x55aa18);if(_0x46977a[_0xb54b('0x31')][_0xb54b('0x3b')]){_0x24e713['where']=_[_0xb54b('0x3c')](_0x24e713[_0xb54b('0x39')],{'$or':_['map'](_0x55aa18,function(_0xdcb2c0){if(_0xdcb2c0['type']!==_0xb54b('0x3d')){var _0x4f07ac={};_0x4f07ac[_0xdcb2c0[_0xb54b('0x2a')]]={'$like':'%'+_0x46977a[_0xb54b('0x31')][_0xb54b('0x3b')]+'%'};return _0x4f07ac;}})});}_0x24e713=_[_0xb54b('0x3c')]({},_0x24e713,_0x46977a[_0xb54b('0x3e')]);var _0xa26f86={'where':_0x24e713[_0xb54b('0x39')]};return db[_0xb54b('0x3f')][_0xb54b('0x1f')](_0xa26f86)['then'](function(_0x35ba1f){_0x928af['count']=_0x35ba1f;if(_0x46977a[_0xb54b('0x31')][_0xb54b('0x40')]){_0x24e713[_0xb54b('0x41')]=[{'all':!![]}];}return db[_0xb54b('0x3f')]['findAll'](_0x24e713);})[_0xb54b('0x42')](function(_0x1142a8){_0x928af[_0xb54b('0x43')]=_0x1142a8;return _0x928af;})['then'](respondWithFilteredResult(_0x40fe32,_0x24e713))[_0xb54b('0x44')](handleError(_0x40fe32,null));};exports[_0xb54b('0x45')]=function(_0x2362ea,_0x7ae8c9){var _0x4c1779={'raw':!![],'where':{'id':_0x2362ea[_0xb54b('0x46')]['id']}},_0x53852c={};_0x53852c[_0xb54b('0x2f')]=_[_0xb54b('0x47')](db[_0xb54b('0x3f')][_0xb54b('0x2c')]);_0x53852c[_0xb54b('0x31')]=_[_0xb54b('0x47')](_0x2362ea[_0xb54b('0x31')]);_0x53852c['filters']=_['intersection'](_0x53852c[_0xb54b('0x2f')],_0x53852c['query']);_0x4c1779[_0xb54b('0x34')]=_[_0xb54b('0x33')](_0x53852c[_0xb54b('0x2f')],qs[_0xb54b('0x35')](_0x2362ea[_0xb54b('0x31')]['fields']));_0x4c1779['attributes']=_0x4c1779['attributes'][_0xb54b('0x36')]?_0x4c1779[_0xb54b('0x34')]:_0x53852c[_0xb54b('0x2f')];if(_0x2362ea['query'][_0xb54b('0x40')]){_0x4c1779[_0xb54b('0x41')]=[{'all':!![]}];}_0x4c1779=_['merge']({},_0x4c1779,_0x2362ea[_0xb54b('0x3e')]);return db[_0xb54b('0x3f')][_0xb54b('0x48')](_0x4c1779)[_0xb54b('0x42')](handleEntityNotFound(_0x7ae8c9,null))[_0xb54b('0x42')](respondWithResult(_0x7ae8c9,null))[_0xb54b('0x44')](handleError(_0x7ae8c9,null));};exports[_0xb54b('0x49')]=function(_0x1181de,_0x32b5b3){return db[_0xb54b('0x3f')]['create'](_0x1181de[_0xb54b('0x4a')],{})[_0xb54b('0x42')](respondWithResult(_0x32b5b3,0xc9))['catch'](handleError(_0x32b5b3,null));};exports['update']=function(_0x3233e6,_0x3e843b){if(_0x3233e6[_0xb54b('0x4a')]['id']){delete _0x3233e6[_0xb54b('0x4a')]['id'];}return db[_0xb54b('0x3f')]['find']({'where':{'id':_0x3233e6[_0xb54b('0x46')]['id']}})[_0xb54b('0x42')](handleEntityNotFound(_0x3e843b,null))[_0xb54b('0x42')](saveUpdates(_0x3233e6[_0xb54b('0x4a')],null))[_0xb54b('0x42')](respondWithResult(_0x3e843b,null))[_0xb54b('0x44')](handleError(_0x3e843b,null));};exports[_0xb54b('0x27')]=function(_0x336bee,_0x2a35a6){return db[_0xb54b('0x3f')][_0xb54b('0x48')]({'where':{'id':_0x336bee[_0xb54b('0x46')]['id']}})[_0xb54b('0x42')](handleEntityNotFound(_0x2a35a6,null))['then'](removeEntity(_0x2a35a6,null))[_0xb54b('0x44')](handleError(_0x2a35a6,null));};exports[_0xb54b('0x4b')]=function(_0x2b2341,_0x31a503,_0x20fe0e){return db[_0xb54b('0x3f')]['find']({'where':{'id':_0x2b2341[_0xb54b('0x46')]['id']},'attributes':['id',_0xb54b('0x4c'),_0xb54b('0x4d')]})[_0xb54b('0x42')](handleEntityNotFound(_0x31a503,null))[_0xb54b('0x42')](function(_0xb2576f){if(_0xb2576f){if(!_0xb2576f[_0xb54b('0x4c')]){throw new db[(_0xb54b('0x4e'))][(_0xb54b('0x4f'))](_0xb54b('0x50'));}var _0x5e8350={'Content-Type':_0xb54b('0x51'),'Content-Disposition':'attachment'};if(_0xb2576f['msg_id']){_0x5e8350[_0xb54b('0x52')]=_0xb54b('0x53')+_0xb2576f[_0xb54b('0x4d')]+'.wav\x22';}_0x31a503[_0xb54b('0x20')](_0x5e8350);return _0x31a503[_0xb54b('0x54')](new Buffer(_0xb2576f[_0xb54b('0x4c')]));}})[_0xb54b('0x44')](handleError(_0x31a503,null));};