Built motion from commit 5293bb2a.|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 _0xabf4=['stack','name','index','map','VoiceMailMessage','rawAttributes','type','key','model','differenceBy','keys','filters','query','intersection','fields','length','attributes','hasOwnProperty','nolimit','order','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','show','params','create','body','catch','update','find','download','msg_id','recording','Sequelize','ValidationError','VoiceMailMessage\x20not\x20found','audio/wav','attachment','Content-Disposition','attachment;\x20filename=\x22','.wav\x22','send','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','apply','save','then','destroy','error'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0xabf4,0xe3));var _0x4abf=function(_0x4a795d,_0x3e5ba9){_0x4a795d=_0x4a795d-0x0;var _0x802826=_0xabf4[_0x4a795d];return _0x802826;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x4abf('0x0'));var zipdir=require(_0x4abf('0x1'));var jsonpatch=require(_0x4abf('0x2'));var rp=require(_0x4abf('0x3'));var moment=require(_0x4abf('0x4'));var BPromise=require(_0x4abf('0x5'));var Mustache=require(_0x4abf('0x6'));var util=require('util');var path=require(_0x4abf('0x7'));var sox=require(_0x4abf('0x8'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x4abf('0x9'));var squel=require(_0x4abf('0xa'));var crypto=require(_0x4abf('0xb'));var jsforce=require(_0x4abf('0xc'));var deskjs=require(_0x4abf('0xd'));var toCsv=require(_0x4abf('0xe'));var querystring=require(_0x4abf('0xf'));var Papa=require('papaparse');var Redis=require(_0x4abf('0x10'));var authService=require(_0x4abf('0x11'));var qs=require(_0x4abf('0x12'));var as=require(_0x4abf('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x4abf('0x14'))(_0x4abf('0x15'));var utils=require(_0x4abf('0x16'));var config=require(_0x4abf('0x17'));var licenseUtil=require(_0x4abf('0x18'));var db=require(_0x4abf('0x19'))['db'];function respondWithStatusCode(_0xe15e79,_0x27c6ff){_0x27c6ff=_0x27c6ff||0xcc;return function(_0x109499){if(_0x109499){return _0xe15e79[_0x4abf('0x1a')](_0x27c6ff);}return _0xe15e79[_0x4abf('0x1b')](_0x27c6ff)['end']();};}function respondWithResult(_0x5ca214,_0xf0d042){_0xf0d042=_0xf0d042||0xc8;return function(_0x1d70bb){if(_0x1d70bb){return _0x5ca214['status'](_0xf0d042)[_0x4abf('0x1c')](_0x1d70bb);}};}function respondWithFilteredResult(_0x184fd4,_0x593a21){return function(_0xdf8712){if(_0xdf8712){var _0x571281=typeof _0x593a21[_0x4abf('0x1d')]===_0x4abf('0x1e')&&typeof _0x593a21[_0x4abf('0x1f')]==='undefined';var _0x54039c=_0xdf8712[_0x4abf('0x20')];var _0x115fc8=_0x571281?0x0:_0x593a21[_0x4abf('0x1d')];var _0x2b2706=_0x571281?_0xdf8712[_0x4abf('0x20')]:_0x593a21[_0x4abf('0x1d')]+_0x593a21['limit'];var _0x446c08;if(_0x2b2706>=_0x54039c){_0x2b2706=_0x54039c;_0x446c08=0xc8;}else{_0x446c08=0xce;}_0x184fd4[_0x4abf('0x1b')](_0x446c08);return _0x184fd4[_0x4abf('0x21')](_0x4abf('0x22'),_0x115fc8+'-'+_0x2b2706+'/'+_0x54039c)[_0x4abf('0x1c')](_0xdf8712);}return null;};}function patchUpdates(_0xb32300){return function(_0x31b711){try{jsonpatch[_0x4abf('0x23')](_0x31b711,_0xb32300,!![]);}catch(_0x48c086){return BPromise['reject'](_0x48c086);}return _0x31b711[_0x4abf('0x24')]();};}function saveUpdates(_0x464fa3,_0x59da4e){return function(_0x5973bc){if(_0x5973bc){return _0x5973bc['update'](_0x464fa3)[_0x4abf('0x25')](function(_0x378351){return _0x378351;});}return null;};}function removeEntity(_0x5423c5,_0x1d2f96){return function(_0x49e628){if(_0x49e628){return _0x49e628[_0x4abf('0x26')]()[_0x4abf('0x25')](function(){_0x5423c5[_0x4abf('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4630e5,_0x1bd771){return function(_0x541fe8){if(!_0x541fe8){_0x4630e5[_0x4abf('0x1a')](0x194);}return _0x541fe8;};}function handleError(_0xc7d17c,_0x17e958){_0x17e958=_0x17e958||0x1f4;return function(_0x11ed19){logger[_0x4abf('0x27')](_0x11ed19[_0x4abf('0x28')]);if(_0x11ed19[_0x4abf('0x29')]){delete _0x11ed19[_0x4abf('0x29')];}_0xc7d17c['status'](_0x17e958)['send'](_0x11ed19);};}exports[_0x4abf('0x2a')]=function(_0x5111d4,_0x4659a8){var _0x5dabb1={},_0x6f0aec={},_0x2ac820={'count':0x0,'rows':[]};var _0x8eaf21=_[_0x4abf('0x2b')](db[_0x4abf('0x2c')][_0x4abf('0x2d')],function(_0xbb641b){return{'name':_0xbb641b['fieldName'],'type':_0xbb641b[_0x4abf('0x2e')][_0x4abf('0x2f')]};});_0x6f0aec[_0x4abf('0x30')]=_[_0x4abf('0x31')](_[_0x4abf('0x2b')](_0x8eaf21,_0x4abf('0x29')),[_0x4abf('0x29')]);_0x6f0aec['query']=_[_0x4abf('0x32')](_0x5111d4['query']);_0x6f0aec[_0x4abf('0x33')]=_['intersection'](_0x6f0aec[_0x4abf('0x30')],_0x6f0aec[_0x4abf('0x34')]);_0x5dabb1['attributes']=_[_0x4abf('0x35')](_0x6f0aec[_0x4abf('0x30')],qs[_0x4abf('0x36')](_0x5111d4[_0x4abf('0x34')][_0x4abf('0x36')]));_0x5dabb1['attributes']=_0x5dabb1['attributes'][_0x4abf('0x37')]?_0x5dabb1[_0x4abf('0x38')]:_0x6f0aec[_0x4abf('0x30')];if(!_0x5111d4['query'][_0x4abf('0x39')](_0x4abf('0x3a'))){_0x5dabb1['limit']=qs[_0x4abf('0x1f')](_0x5111d4[_0x4abf('0x34')][_0x4abf('0x1f')]);_0x5dabb1[_0x4abf('0x1d')]=qs[_0x4abf('0x1d')](_0x5111d4['query'][_0x4abf('0x1d')]);}_0x5dabb1[_0x4abf('0x3b')]=qs['sort'](_0x5111d4['query']['sort']);_0x5dabb1[_0x4abf('0x3c')]=qs[_0x4abf('0x33')](_[_0x4abf('0x3d')](_0x5111d4[_0x4abf('0x34')],_0x6f0aec[_0x4abf('0x33')]),_0x8eaf21);if(_0x5111d4[_0x4abf('0x34')][_0x4abf('0x3e')]){_0x5dabb1[_0x4abf('0x3c')]=_[_0x4abf('0x3f')](_0x5dabb1['where'],{'$or':_['map'](_0x8eaf21,function(_0x53058e){if(_0x53058e['type']!==_0x4abf('0x40')){var _0x6f2f70={};_0x6f2f70[_0x53058e[_0x4abf('0x29')]]={'$like':'%'+_0x5111d4['query']['filter']+'%'};return _0x6f2f70;}})});}_0x5dabb1=_[_0x4abf('0x3f')]({},_0x5dabb1,_0x5111d4[_0x4abf('0x41')]);var _0x3c02db={'where':_0x5dabb1['where']};return db['VoiceMailMessage'][_0x4abf('0x20')](_0x3c02db)[_0x4abf('0x25')](function(_0x59438b){_0x2ac820[_0x4abf('0x20')]=_0x59438b;if(_0x5111d4[_0x4abf('0x34')][_0x4abf('0x42')]){_0x5dabb1[_0x4abf('0x43')]=[{'all':!![]}];}return db[_0x4abf('0x2c')][_0x4abf('0x44')](_0x5dabb1);})[_0x4abf('0x25')](function(_0xc124ae){_0x2ac820[_0x4abf('0x45')]=_0xc124ae;return _0x2ac820;})[_0x4abf('0x25')](respondWithFilteredResult(_0x4659a8,_0x5dabb1))['catch'](handleError(_0x4659a8,null));};exports[_0x4abf('0x46')]=function(_0x256440,_0x35e5c0){var _0x31cda9={'raw':!![],'where':{'id':_0x256440[_0x4abf('0x47')]['id']}},_0x3f252a={};_0x3f252a[_0x4abf('0x30')]=_['keys'](db[_0x4abf('0x2c')][_0x4abf('0x2d')]);_0x3f252a['query']=_['keys'](_0x256440[_0x4abf('0x34')]);_0x3f252a['filters']=_[_0x4abf('0x35')](_0x3f252a[_0x4abf('0x30')],_0x3f252a['query']);_0x31cda9[_0x4abf('0x38')]=_['intersection'](_0x3f252a[_0x4abf('0x30')],qs[_0x4abf('0x36')](_0x256440['query'][_0x4abf('0x36')]));_0x31cda9['attributes']=_0x31cda9[_0x4abf('0x38')][_0x4abf('0x37')]?_0x31cda9[_0x4abf('0x38')]:_0x3f252a[_0x4abf('0x30')];if(_0x256440[_0x4abf('0x34')][_0x4abf('0x42')]){_0x31cda9[_0x4abf('0x43')]=[{'all':!![]}];}_0x31cda9=_[_0x4abf('0x3f')]({},_0x31cda9,_0x256440[_0x4abf('0x41')]);return db[_0x4abf('0x2c')]['find'](_0x31cda9)[_0x4abf('0x25')](handleEntityNotFound(_0x35e5c0,null))[_0x4abf('0x25')](respondWithResult(_0x35e5c0,null))['catch'](handleError(_0x35e5c0,null));};exports[_0x4abf('0x48')]=function(_0x53e62e,_0x5310d0){return db[_0x4abf('0x2c')][_0x4abf('0x48')](_0x53e62e[_0x4abf('0x49')],{})[_0x4abf('0x25')](respondWithResult(_0x5310d0,0xc9))[_0x4abf('0x4a')](handleError(_0x5310d0,null));};exports[_0x4abf('0x4b')]=function(_0x5ed958,_0x40b349){if(_0x5ed958['body']['id']){delete _0x5ed958[_0x4abf('0x49')]['id'];}return db[_0x4abf('0x2c')][_0x4abf('0x4c')]({'where':{'id':_0x5ed958[_0x4abf('0x47')]['id']}})['then'](handleEntityNotFound(_0x40b349,null))[_0x4abf('0x25')](saveUpdates(_0x5ed958[_0x4abf('0x49')],null))['then'](respondWithResult(_0x40b349,null))[_0x4abf('0x4a')](handleError(_0x40b349,null));};exports['destroy']=function(_0x30ecdc,_0x1d075e){return db[_0x4abf('0x2c')]['find']({'where':{'id':_0x30ecdc[_0x4abf('0x47')]['id']}})[_0x4abf('0x25')](handleEntityNotFound(_0x1d075e,null))[_0x4abf('0x25')](removeEntity(_0x1d075e,null))['catch'](handleError(_0x1d075e,null));};exports[_0x4abf('0x4d')]=function(_0x184191,_0x4c1672,_0x2eecad){return db['VoiceMailMessage']['find']({'where':{'id':_0x184191['params']['id']},'attributes':['id','recording',_0x4abf('0x4e')]})['then'](handleEntityNotFound(_0x4c1672,null))[_0x4abf('0x25')](function(_0x37a6d5){if(_0x37a6d5){if(!_0x37a6d5[_0x4abf('0x4f')]){throw new db[(_0x4abf('0x50'))][(_0x4abf('0x51'))](_0x4abf('0x52'));}var _0x43bc04={'Content-Type':_0x4abf('0x53'),'Content-Disposition':_0x4abf('0x54')};if(_0x37a6d5['msg_id']){_0x43bc04[_0x4abf('0x55')]=_0x4abf('0x56')+_0x37a6d5[_0x4abf('0x4e')]+_0x4abf('0x57');}_0x4c1672[_0x4abf('0x21')](_0x43bc04);return _0x4c1672[_0x4abf('0x58')](new Buffer(_0x37a6d5[_0x4abf('0x4f')]));}})[_0x4abf('0x4a')](handleError(_0x4c1672,null));};