Built motion from commit 6362bb75.|2.6.13
[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 _0xbc0c=['../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','json','undefined','limit','offset','count','set','Content-Range','apply','reject','save','update','then','destroy','name','send','map','VoiceMailMessage','rawAttributes','fieldName','key','query','keys','filters','intersection','model','attributes','fields','length','sort','where','pick','filter','merge','type','VIRTUAL','options','includeAll','findAll','rows','catch','show','params','include','find','create','body','download','recording','msg_id','Sequelize','ValidationError','VoiceMailMessage\x20not\x20found','audio/wav','Content-Disposition','attachment;\x20filename=\x22','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware'];(function(_0x246579,_0x1313da){var _0x569760=function(_0x228da5){while(--_0x228da5){_0x246579['push'](_0x246579['shift']());}};_0x569760(++_0x1313da);}(_0xbc0c,0xe9));var _0xcbc0=function(_0x28edaa,_0x118154){_0x28edaa=_0x28edaa-0x0;var _0x24e3a4=_0xbc0c[_0x28edaa];return _0x24e3a4;};'use strict';var emlformat=require(_0xcbc0('0x0'));var rimraf=require(_0xcbc0('0x1'));var zipdir=require(_0xcbc0('0x2'));var jsonpatch=require(_0xcbc0('0x3'));var rp=require(_0xcbc0('0x4'));var moment=require(_0xcbc0('0x5'));var BPromise=require(_0xcbc0('0x6'));var Mustache=require('mustache');var util=require(_0xcbc0('0x7'));var path=require(_0xcbc0('0x8'));var sox=require(_0xcbc0('0x9'));var csv=require('to-csv');var ejs=require(_0xcbc0('0xa'));var fs=require('fs');var fs_extra=require(_0xcbc0('0xb'));var _=require(_0xcbc0('0xc'));var squel=require(_0xcbc0('0xd'));var crypto=require(_0xcbc0('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xcbc0('0xf'));var toCsv=require('to-csv');var querystring=require(_0xcbc0('0x10'));var Papa=require(_0xcbc0('0x11'));var Redis=require(_0xcbc0('0x12'));var authService=require(_0xcbc0('0x13'));var qs=require('../../components/parsers/qs');var as=require(_0xcbc0('0x14'));var hardwareService=require(_0xcbc0('0x15'));var logger=require(_0xcbc0('0x16'))(_0xcbc0('0x17'));var utils=require(_0xcbc0('0x18'));var config=require('../../config/environment');var licenseUtil=require(_0xcbc0('0x19'));var db=require(_0xcbc0('0x1a'))['db'];function respondWithStatusCode(_0x14496d,_0x5f144f){_0x5f144f=_0x5f144f||0xcc;return function(_0x368978){if(_0x368978){return _0x14496d[_0xcbc0('0x1b')](_0x5f144f);}return _0x14496d[_0xcbc0('0x1c')](_0x5f144f)[_0xcbc0('0x1d')]();};}function respondWithResult(_0x1f488d,_0x2ef88b){_0x2ef88b=_0x2ef88b||0xc8;return function(_0x366a4a){if(_0x366a4a){return _0x1f488d['status'](_0x2ef88b)[_0xcbc0('0x1e')](_0x366a4a);}};}function respondWithFilteredResult(_0x34b001,_0x4bec73){return function(_0x3d2c67){if(_0x3d2c67){var _0x3d0f3d=typeof _0x4bec73['offset']===_0xcbc0('0x1f')&&typeof _0x4bec73[_0xcbc0('0x20')]==='undefined';var _0x46a815=_0x3d2c67['count'];var _0x372107=_0x3d0f3d?0x0:_0x4bec73[_0xcbc0('0x21')];var _0x39764=_0x3d0f3d?_0x3d2c67[_0xcbc0('0x22')]:_0x4bec73['offset']+_0x4bec73[_0xcbc0('0x20')];var _0x1aca9c;if(_0x39764>=_0x46a815){_0x39764=_0x46a815;_0x1aca9c=0xc8;}else{_0x1aca9c=0xce;}_0x34b001['status'](_0x1aca9c);return _0x34b001[_0xcbc0('0x23')](_0xcbc0('0x24'),_0x372107+'-'+_0x39764+'/'+_0x46a815)[_0xcbc0('0x1e')](_0x3d2c67);}return null;};}function patchUpdates(_0x184e14){return function(_0x14e922){try{jsonpatch[_0xcbc0('0x25')](_0x14e922,_0x184e14,!![]);}catch(_0x5a8f59){return BPromise[_0xcbc0('0x26')](_0x5a8f59);}return _0x14e922[_0xcbc0('0x27')]();};}function saveUpdates(_0x42a49f,_0x28c4bf){return function(_0x143746){if(_0x143746){return _0x143746[_0xcbc0('0x28')](_0x42a49f)[_0xcbc0('0x29')](function(_0x4af2fe){return _0x4af2fe;});}return null;};}function removeEntity(_0x387d99,_0x5b3a0f){return function(_0x2c677e){if(_0x2c677e){return _0x2c677e[_0xcbc0('0x2a')]()['then'](function(){_0x387d99[_0xcbc0('0x1c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x24a8d7,_0x5dd2cd){return function(_0x1bc4b9){if(!_0x1bc4b9){_0x24a8d7[_0xcbc0('0x1b')](0x194);}return _0x1bc4b9;};}function handleError(_0x5b48ae,_0x29705f){_0x29705f=_0x29705f||0x1f4;return function(_0x2f8c55){logger['error'](_0x2f8c55['stack']);if(_0x2f8c55['name']){delete _0x2f8c55[_0xcbc0('0x2b')];}_0x5b48ae[_0xcbc0('0x1c')](_0x29705f)[_0xcbc0('0x2c')](_0x2f8c55);};}exports['index']=function(_0x598146,_0x33886c){var _0x49b32c={},_0x5693a9={},_0x387fcf={'count':0x0,'rows':[]};var _0x16c2ef=_[_0xcbc0('0x2d')](db[_0xcbc0('0x2e')][_0xcbc0('0x2f')],function(_0x5c656d){return{'name':_0x5c656d[_0xcbc0('0x30')],'type':_0x5c656d['type'][_0xcbc0('0x31')]};});_0x5693a9['model']=_['differenceBy'](_['map'](_0x16c2ef,_0xcbc0('0x2b')),['name']);_0x5693a9[_0xcbc0('0x32')]=_[_0xcbc0('0x33')](_0x598146[_0xcbc0('0x32')]);_0x5693a9[_0xcbc0('0x34')]=_[_0xcbc0('0x35')](_0x5693a9[_0xcbc0('0x36')],_0x5693a9[_0xcbc0('0x32')]);_0x49b32c[_0xcbc0('0x37')]=_['intersection'](_0x5693a9[_0xcbc0('0x36')],qs[_0xcbc0('0x38')](_0x598146[_0xcbc0('0x32')][_0xcbc0('0x38')]));_0x49b32c[_0xcbc0('0x37')]=_0x49b32c[_0xcbc0('0x37')][_0xcbc0('0x39')]?_0x49b32c['attributes']:_0x5693a9[_0xcbc0('0x36')];if(!_0x598146[_0xcbc0('0x32')]['hasOwnProperty']('nolimit')){_0x49b32c['limit']=qs[_0xcbc0('0x20')](_0x598146['query']['limit']);_0x49b32c['offset']=qs['offset'](_0x598146[_0xcbc0('0x32')]['offset']);}_0x49b32c['order']=qs[_0xcbc0('0x3a')](_0x598146[_0xcbc0('0x32')]['sort']);_0x49b32c[_0xcbc0('0x3b')]=qs[_0xcbc0('0x34')](_[_0xcbc0('0x3c')](_0x598146[_0xcbc0('0x32')],_0x5693a9['filters']),_0x16c2ef);if(_0x598146['query'][_0xcbc0('0x3d')]){_0x49b32c[_0xcbc0('0x3b')]=_[_0xcbc0('0x3e')](_0x49b32c[_0xcbc0('0x3b')],{'$or':_['map'](_0x16c2ef,function(_0x40e498){if(_0x40e498[_0xcbc0('0x3f')]!==_0xcbc0('0x40')){var _0x341d92={};_0x341d92[_0x40e498[_0xcbc0('0x2b')]]={'$like':'%'+_0x598146[_0xcbc0('0x32')][_0xcbc0('0x3d')]+'%'};return _0x341d92;}})});}_0x49b32c=_[_0xcbc0('0x3e')]({},_0x49b32c,_0x598146[_0xcbc0('0x41')]);var _0x41d010={'where':_0x49b32c[_0xcbc0('0x3b')]};return db['VoiceMailMessage']['count'](_0x41d010)['then'](function(_0x50a2af){_0x387fcf[_0xcbc0('0x22')]=_0x50a2af;if(_0x598146['query'][_0xcbc0('0x42')]){_0x49b32c['include']=[{'all':!![]}];}return db[_0xcbc0('0x2e')][_0xcbc0('0x43')](_0x49b32c);})['then'](function(_0x4da3a5){_0x387fcf[_0xcbc0('0x44')]=_0x4da3a5;return _0x387fcf;})[_0xcbc0('0x29')](respondWithFilteredResult(_0x33886c,_0x49b32c))[_0xcbc0('0x45')](handleError(_0x33886c,null));};exports[_0xcbc0('0x46')]=function(_0x91eb52,_0x49ce5b){var _0x112f4a={'raw':!![],'where':{'id':_0x91eb52[_0xcbc0('0x47')]['id']}},_0x19e512={};_0x19e512[_0xcbc0('0x36')]=_[_0xcbc0('0x33')](db['VoiceMailMessage'][_0xcbc0('0x2f')]);_0x19e512[_0xcbc0('0x32')]=_[_0xcbc0('0x33')](_0x91eb52[_0xcbc0('0x32')]);_0x19e512[_0xcbc0('0x34')]=_[_0xcbc0('0x35')](_0x19e512[_0xcbc0('0x36')],_0x19e512['query']);_0x112f4a[_0xcbc0('0x37')]=_[_0xcbc0('0x35')](_0x19e512[_0xcbc0('0x36')],qs[_0xcbc0('0x38')](_0x91eb52[_0xcbc0('0x32')][_0xcbc0('0x38')]));_0x112f4a['attributes']=_0x112f4a[_0xcbc0('0x37')][_0xcbc0('0x39')]?_0x112f4a[_0xcbc0('0x37')]:_0x19e512[_0xcbc0('0x36')];if(_0x91eb52[_0xcbc0('0x32')]['includeAll']){_0x112f4a[_0xcbc0('0x48')]=[{'all':!![]}];}_0x112f4a=_[_0xcbc0('0x3e')]({},_0x112f4a,_0x91eb52[_0xcbc0('0x41')]);return db[_0xcbc0('0x2e')][_0xcbc0('0x49')](_0x112f4a)[_0xcbc0('0x29')](handleEntityNotFound(_0x49ce5b,null))[_0xcbc0('0x29')](respondWithResult(_0x49ce5b,null))['catch'](handleError(_0x49ce5b,null));};exports[_0xcbc0('0x4a')]=function(_0x30265c,_0x4291ed){return db[_0xcbc0('0x2e')][_0xcbc0('0x4a')](_0x30265c[_0xcbc0('0x4b')],{})[_0xcbc0('0x29')](respondWithResult(_0x4291ed,0xc9))['catch'](handleError(_0x4291ed,null));};exports[_0xcbc0('0x28')]=function(_0x4af466,_0x427290){if(_0x4af466[_0xcbc0('0x4b')]['id']){delete _0x4af466['body']['id'];}return db[_0xcbc0('0x2e')][_0xcbc0('0x49')]({'where':{'id':_0x4af466[_0xcbc0('0x47')]['id']}})['then'](handleEntityNotFound(_0x427290,null))[_0xcbc0('0x29')](saveUpdates(_0x4af466[_0xcbc0('0x4b')],null))[_0xcbc0('0x29')](respondWithResult(_0x427290,null))[_0xcbc0('0x45')](handleError(_0x427290,null));};exports[_0xcbc0('0x2a')]=function(_0x168767,_0x1368f4){return db[_0xcbc0('0x2e')]['find']({'where':{'id':_0x168767[_0xcbc0('0x47')]['id']}})[_0xcbc0('0x29')](handleEntityNotFound(_0x1368f4,null))['then'](removeEntity(_0x1368f4,null))[_0xcbc0('0x45')](handleError(_0x1368f4,null));};exports[_0xcbc0('0x4c')]=function(_0x40ff4a,_0x51f591,_0xb3a1b0){return db['VoiceMailMessage']['find']({'where':{'id':_0x40ff4a[_0xcbc0('0x47')]['id']},'attributes':['id',_0xcbc0('0x4d'),_0xcbc0('0x4e')]})[_0xcbc0('0x29')](handleEntityNotFound(_0x51f591,null))[_0xcbc0('0x29')](function(_0x4c0b7e){if(_0x4c0b7e){if(!_0x4c0b7e[_0xcbc0('0x4d')]){throw new db[(_0xcbc0('0x4f'))][(_0xcbc0('0x50'))](_0xcbc0('0x51'));}var _0x57455d={'Content-Type':_0xcbc0('0x52'),'Content-Disposition':'attachment'};if(_0x4c0b7e['msg_id']){_0x57455d[_0xcbc0('0x53')]=_0xcbc0('0x54')+_0x4c0b7e[_0xcbc0('0x4e')]+'.wav\x22';}_0x51f591[_0xcbc0('0x23')](_0x57455d);return _0x51f591[_0xcbc0('0x2c')](new Buffer(_0x4c0b7e[_0xcbc0('0x4d')]));}})[_0xcbc0('0x45')](handleError(_0x51f591,null));};