Built motion from commit 351e7f9c.|2.6.31
[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 _0xf9f7=['.wav\x22','eml-format','zip-dir','fast-json-patch','request-promise','moment','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','apply','save','update','then','destroy','error','stack','name','send','map','VoiceMailMessage','rawAttributes','key','model','keys','query','filters','intersection','attributes','fields','length','nolimit','order','sort','where','pick','filter','type','VIRTUAL','options','includeAll','include','findAll','catch','show','merge','find','create','body','params','msg_id','recording','Sequelize','ValidationError','VoiceMailMessage\x20not\x20found','audio/wav','attachment','Content-Disposition','attachment;\x20filename=\x22'];(function(_0x42cea2,_0x3eaae5){var _0x4e3494=function(_0xcb0042){while(--_0xcb0042){_0x42cea2['push'](_0x42cea2['shift']());}};_0x4e3494(++_0x3eaae5);}(_0xf9f7,0x1f3));var _0x7f9f=function(_0x4f0f6d,_0x28b6f4){_0x4f0f6d=_0x4f0f6d-0x0;var _0x2b2c98=_0xf9f7[_0x4f0f6d];return _0x2b2c98;};'use strict';var emlformat=require(_0x7f9f('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x7f9f('0x1'));var jsonpatch=require(_0x7f9f('0x2'));var rp=require(_0x7f9f('0x3'));var moment=require(_0x7f9f('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x7f9f('0x5'));var path=require(_0x7f9f('0x6'));var sox=require(_0x7f9f('0x7'));var csv=require(_0x7f9f('0x8'));var ejs=require(_0x7f9f('0x9'));var fs=require('fs');var fs_extra=require(_0x7f9f('0xa'));var _=require(_0x7f9f('0xb'));var squel=require(_0x7f9f('0xc'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x7f9f('0xd'));var toCsv=require(_0x7f9f('0x8'));var querystring=require(_0x7f9f('0xe'));var Papa=require(_0x7f9f('0xf'));var Redis=require(_0x7f9f('0x10'));var authService=require(_0x7f9f('0x11'));var qs=require(_0x7f9f('0x12'));var as=require(_0x7f9f('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x7f9f('0x14'))(_0x7f9f('0x15'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x7f9f('0x16'));var db=require(_0x7f9f('0x17'))['db'];function respondWithStatusCode(_0x12d5cb,_0x5b93b2){_0x5b93b2=_0x5b93b2||0xcc;return function(_0x200062){if(_0x200062){return _0x12d5cb[_0x7f9f('0x18')](_0x5b93b2);}return _0x12d5cb[_0x7f9f('0x19')](_0x5b93b2)['end']();};}function respondWithResult(_0x318491,_0x502a3f){_0x502a3f=_0x502a3f||0xc8;return function(_0x4b3ede){if(_0x4b3ede){return _0x318491[_0x7f9f('0x19')](_0x502a3f)[_0x7f9f('0x1a')](_0x4b3ede);}};}function respondWithFilteredResult(_0x3aa0b5,_0x23c12f){return function(_0x33e9f8){if(_0x33e9f8){var _0x4867ea=typeof _0x23c12f[_0x7f9f('0x1b')]===_0x7f9f('0x1c')&&typeof _0x23c12f[_0x7f9f('0x1d')]===_0x7f9f('0x1c');var _0x54990f=_0x33e9f8[_0x7f9f('0x1e')];var _0x668b62=_0x4867ea?0x0:_0x23c12f[_0x7f9f('0x1b')];var _0x5b1f47=_0x4867ea?_0x33e9f8[_0x7f9f('0x1e')]:_0x23c12f[_0x7f9f('0x1b')]+_0x23c12f[_0x7f9f('0x1d')];var _0x19fbeb;if(_0x5b1f47>=_0x54990f){_0x5b1f47=_0x54990f;_0x19fbeb=0xc8;}else{_0x19fbeb=0xce;}_0x3aa0b5[_0x7f9f('0x19')](_0x19fbeb);return _0x3aa0b5[_0x7f9f('0x1f')](_0x7f9f('0x20'),_0x668b62+'-'+_0x5b1f47+'/'+_0x54990f)[_0x7f9f('0x1a')](_0x33e9f8);}return null;};}function patchUpdates(_0x538c07){return function(_0x2ba899){try{jsonpatch[_0x7f9f('0x21')](_0x2ba899,_0x538c07,!![]);}catch(_0x143221){return BPromise['reject'](_0x143221);}return _0x2ba899[_0x7f9f('0x22')]();};}function saveUpdates(_0x1ed741,_0x4da7a1){return function(_0x3bdd94){if(_0x3bdd94){return _0x3bdd94[_0x7f9f('0x23')](_0x1ed741)[_0x7f9f('0x24')](function(_0x3590b4){return _0x3590b4;});}return null;};}function removeEntity(_0x5dd524,_0x2b1725){return function(_0x2db1ac){if(_0x2db1ac){return _0x2db1ac[_0x7f9f('0x25')]()[_0x7f9f('0x24')](function(){_0x5dd524[_0x7f9f('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5633c2,_0x2b506e){return function(_0x180f26){if(!_0x180f26){_0x5633c2[_0x7f9f('0x18')](0x194);}return _0x180f26;};}function handleError(_0x2d5d82,_0x1d120a){_0x1d120a=_0x1d120a||0x1f4;return function(_0x2867a7){logger[_0x7f9f('0x26')](_0x2867a7[_0x7f9f('0x27')]);if(_0x2867a7['name']){delete _0x2867a7[_0x7f9f('0x28')];}_0x2d5d82[_0x7f9f('0x19')](_0x1d120a)[_0x7f9f('0x29')](_0x2867a7);};}exports['index']=function(_0x45f906,_0x535d2b){var _0x5c50b1={},_0x8ab41f={},_0x28094f={'count':0x0,'rows':[]};var _0x5f1d13=_[_0x7f9f('0x2a')](db[_0x7f9f('0x2b')][_0x7f9f('0x2c')],function(_0x3e7435){return{'name':_0x3e7435['fieldName'],'type':_0x3e7435['type'][_0x7f9f('0x2d')]};});_0x8ab41f[_0x7f9f('0x2e')]=_['differenceBy'](_['map'](_0x5f1d13,_0x7f9f('0x28')),[_0x7f9f('0x28')]);_0x8ab41f['query']=_[_0x7f9f('0x2f')](_0x45f906[_0x7f9f('0x30')]);_0x8ab41f[_0x7f9f('0x31')]=_[_0x7f9f('0x32')](_0x8ab41f['model'],_0x8ab41f[_0x7f9f('0x30')]);_0x5c50b1[_0x7f9f('0x33')]=_[_0x7f9f('0x32')](_0x8ab41f[_0x7f9f('0x2e')],qs[_0x7f9f('0x34')](_0x45f906[_0x7f9f('0x30')][_0x7f9f('0x34')]));_0x5c50b1[_0x7f9f('0x33')]=_0x5c50b1[_0x7f9f('0x33')][_0x7f9f('0x35')]?_0x5c50b1[_0x7f9f('0x33')]:_0x8ab41f[_0x7f9f('0x2e')];if(!_0x45f906[_0x7f9f('0x30')]['hasOwnProperty'](_0x7f9f('0x36'))){_0x5c50b1[_0x7f9f('0x1d')]=qs[_0x7f9f('0x1d')](_0x45f906['query'][_0x7f9f('0x1d')]);_0x5c50b1[_0x7f9f('0x1b')]=qs[_0x7f9f('0x1b')](_0x45f906[_0x7f9f('0x30')][_0x7f9f('0x1b')]);}_0x5c50b1[_0x7f9f('0x37')]=qs[_0x7f9f('0x38')](_0x45f906[_0x7f9f('0x30')][_0x7f9f('0x38')]);_0x5c50b1[_0x7f9f('0x39')]=qs[_0x7f9f('0x31')](_[_0x7f9f('0x3a')](_0x45f906['query'],_0x8ab41f[_0x7f9f('0x31')]),_0x5f1d13);if(_0x45f906['query'][_0x7f9f('0x3b')]){_0x5c50b1[_0x7f9f('0x39')]=_['merge'](_0x5c50b1['where'],{'$or':_[_0x7f9f('0x2a')](_0x5f1d13,function(_0xed29b5){if(_0xed29b5[_0x7f9f('0x3c')]!==_0x7f9f('0x3d')){var _0x27c437={};_0x27c437[_0xed29b5['name']]={'$like':'%'+_0x45f906[_0x7f9f('0x30')][_0x7f9f('0x3b')]+'%'};return _0x27c437;}})});}_0x5c50b1=_['merge']({},_0x5c50b1,_0x45f906[_0x7f9f('0x3e')]);var _0x47d5f5={'where':_0x5c50b1['where']};return db[_0x7f9f('0x2b')][_0x7f9f('0x1e')](_0x47d5f5)[_0x7f9f('0x24')](function(_0xa6e201){_0x28094f['count']=_0xa6e201;if(_0x45f906[_0x7f9f('0x30')][_0x7f9f('0x3f')]){_0x5c50b1[_0x7f9f('0x40')]=[{'all':!![]}];}return db['VoiceMailMessage'][_0x7f9f('0x41')](_0x5c50b1);})['then'](function(_0x31044c){_0x28094f['rows']=_0x31044c;return _0x28094f;})[_0x7f9f('0x24')](respondWithFilteredResult(_0x535d2b,_0x5c50b1))[_0x7f9f('0x42')](handleError(_0x535d2b,null));};exports[_0x7f9f('0x43')]=function(_0x320c06,_0x2df88d){var _0x48c1b0={'raw':!![],'where':{'id':_0x320c06['params']['id']}},_0x1cfded={};_0x1cfded['model']=_[_0x7f9f('0x2f')](db[_0x7f9f('0x2b')][_0x7f9f('0x2c')]);_0x1cfded[_0x7f9f('0x30')]=_[_0x7f9f('0x2f')](_0x320c06[_0x7f9f('0x30')]);_0x1cfded[_0x7f9f('0x31')]=_['intersection'](_0x1cfded[_0x7f9f('0x2e')],_0x1cfded[_0x7f9f('0x30')]);_0x48c1b0['attributes']=_[_0x7f9f('0x32')](_0x1cfded[_0x7f9f('0x2e')],qs[_0x7f9f('0x34')](_0x320c06[_0x7f9f('0x30')][_0x7f9f('0x34')]));_0x48c1b0['attributes']=_0x48c1b0[_0x7f9f('0x33')][_0x7f9f('0x35')]?_0x48c1b0[_0x7f9f('0x33')]:_0x1cfded[_0x7f9f('0x2e')];if(_0x320c06[_0x7f9f('0x30')][_0x7f9f('0x3f')]){_0x48c1b0[_0x7f9f('0x40')]=[{'all':!![]}];}_0x48c1b0=_[_0x7f9f('0x44')]({},_0x48c1b0,_0x320c06['options']);return db['VoiceMailMessage'][_0x7f9f('0x45')](_0x48c1b0)[_0x7f9f('0x24')](handleEntityNotFound(_0x2df88d,null))[_0x7f9f('0x24')](respondWithResult(_0x2df88d,null))[_0x7f9f('0x42')](handleError(_0x2df88d,null));};exports[_0x7f9f('0x46')]=function(_0x425724,_0x4b966a){return db[_0x7f9f('0x2b')][_0x7f9f('0x46')](_0x425724[_0x7f9f('0x47')],{})[_0x7f9f('0x24')](respondWithResult(_0x4b966a,0xc9))[_0x7f9f('0x42')](handleError(_0x4b966a,null));};exports[_0x7f9f('0x23')]=function(_0x30285a,_0x211120){if(_0x30285a['body']['id']){delete _0x30285a[_0x7f9f('0x47')]['id'];}return db[_0x7f9f('0x2b')][_0x7f9f('0x45')]({'where':{'id':_0x30285a[_0x7f9f('0x48')]['id']}})[_0x7f9f('0x24')](handleEntityNotFound(_0x211120,null))[_0x7f9f('0x24')](saveUpdates(_0x30285a[_0x7f9f('0x47')],null))[_0x7f9f('0x24')](respondWithResult(_0x211120,null))[_0x7f9f('0x42')](handleError(_0x211120,null));};exports['destroy']=function(_0xf563ae,_0x12d9e3){return db[_0x7f9f('0x2b')][_0x7f9f('0x45')]({'where':{'id':_0xf563ae['params']['id']}})['then'](handleEntityNotFound(_0x12d9e3,null))[_0x7f9f('0x24')](removeEntity(_0x12d9e3,null))['catch'](handleError(_0x12d9e3,null));};exports['download']=function(_0x225405,_0x4796d1,_0x3f8b99){return db[_0x7f9f('0x2b')]['find']({'where':{'id':_0x225405['params']['id']},'attributes':['id','recording',_0x7f9f('0x49')]})['then'](handleEntityNotFound(_0x4796d1,null))[_0x7f9f('0x24')](function(_0x32008b){if(_0x32008b){if(!_0x32008b[_0x7f9f('0x4a')]){throw new db[(_0x7f9f('0x4b'))][(_0x7f9f('0x4c'))](_0x7f9f('0x4d'));}var _0x5247ad={'Content-Type':_0x7f9f('0x4e'),'Content-Disposition':_0x7f9f('0x4f')};if(_0x32008b[_0x7f9f('0x49')]){_0x5247ad[_0x7f9f('0x50')]=_0x7f9f('0x51')+_0x32008b[_0x7f9f('0x49')]+_0x7f9f('0x52');}_0x4796d1[_0x7f9f('0x1f')](_0x5247ad);return _0x4796d1[_0x7f9f('0x29')](new Buffer(_0x32008b['recording']));}})['catch'](handleError(_0x4796d1,null));};