5cf885e127a44ec79fe21691590c46d7be7f24f0
[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 _0x878f=['request-promise','moment','bluebird','mustache','util','path','sox','lodash','squel','to-csv','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../mysqldb','sendStatus','status','end','count','offset','limit','Content-Range','json','apply','reject','then','destroy','error','stack','name','index','map','VoiceMailMessage','fieldName','type','model','keys','filters','intersection','query','attributes','fields','hasOwnProperty','nolimit','sort','where','pick','filter','merge','options','includeAll','findAll','rows','show','rawAttributes','length','include','find','body','catch','update','params','download','recording','msg_id','Sequelize','VoiceMailMessage\x20not\x20found','audio/wav','attachment','eml-format','rimraf','zip-dir','fast-json-patch'];(function(_0x238da4,_0x127bbb){var _0x4b34ee=function(_0x25da00){while(--_0x25da00){_0x238da4['push'](_0x238da4['shift']());}};_0x4b34ee(++_0x127bbb);}(_0x878f,0x173));var _0xf878=function(_0x221092,_0x157f23){_0x221092=_0x221092-0x0;var _0x453372=_0x878f[_0x221092];return _0x453372;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xf878('0x0'));var rimraf=require(_0xf878('0x1'));var zipdir=require(_0xf878('0x2'));var jsonpatch=require(_0xf878('0x3'));var rp=require(_0xf878('0x4'));var moment=require(_0xf878('0x5'));var BPromise=require(_0xf878('0x6'));var Mustache=require(_0xf878('0x7'));var util=require(_0xf878('0x8'));var path=require(_0xf878('0x9'));var sox=require(_0xf878('0xa'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xf878('0xb'));var squel=require(_0xf878('0xc'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xf878('0xd'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xf878('0xe'));var authService=require(_0xf878('0xf'));var qs=require(_0xf878('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf878('0x11'));var logger=require(_0xf878('0x12'))('api');var utils=require(_0xf878('0x13'));var config=require('../../config/environment');var db=require(_0xf878('0x14'))['db'];function respondWithStatusCode(_0x97c396,_0x339c9c){_0x339c9c=_0x339c9c||0xcc;return function(_0x596fb5){if(_0x596fb5){return _0x97c396[_0xf878('0x15')](_0x339c9c);}return _0x97c396[_0xf878('0x16')](_0x339c9c)[_0xf878('0x17')]();};}function respondWithResult(_0x570dcc,_0xe2c2de){_0xe2c2de=_0xe2c2de||0xc8;return function(_0x3902f7){if(_0x3902f7){return _0x570dcc[_0xf878('0x16')](_0xe2c2de)['json'](_0x3902f7);}};}function respondWithFilteredResult(_0x568a3a,_0x4c0948){return function(_0x35ff2d){if(_0x35ff2d){var _0x31d888=_0x35ff2d[_0xf878('0x18')],_0x6dbeca=_0x4c0948[_0xf878('0x19')],_0x44aacc=_0x4c0948[_0xf878('0x19')]+_0x4c0948[_0xf878('0x1a')],_0x186a02;if(_0x44aacc>=_0x31d888){_0x44aacc=_0x31d888;_0x186a02=0xc8;}else{_0x186a02=0xce;}_0x568a3a[_0xf878('0x16')](_0x186a02);return _0x568a3a['set'](_0xf878('0x1b'),_0x6dbeca+'-'+_0x44aacc+'/'+_0x31d888)[_0xf878('0x1c')](_0x35ff2d);}return null;};}function patchUpdates(_0x412de1){return function(_0x622ea8){try{jsonpatch[_0xf878('0x1d')](_0x622ea8,_0x412de1,!![]);}catch(_0x237d15){return BPromise[_0xf878('0x1e')](_0x237d15);}return _0x622ea8['save']();};}function saveUpdates(_0x73f6bf,_0x140866){return function(_0x250f85){if(_0x250f85){return _0x250f85['update'](_0x73f6bf)[_0xf878('0x1f')](function(_0x23590c){return _0x23590c;});}return null;};}function removeEntity(_0xacc440,_0x392822){return function(_0x22d884){if(_0x22d884){return _0x22d884[_0xf878('0x20')]()[_0xf878('0x1f')](function(){_0xacc440[_0xf878('0x16')](0xcc)[_0xf878('0x17')]();});}};}function handleEntityNotFound(_0x1a6506,_0x45e61f){return function(_0x566995){if(!_0x566995){_0x1a6506[_0xf878('0x15')](0x194);}return _0x566995;};}function handleError(_0x5b0b06,_0xa3d3d3){_0xa3d3d3=_0xa3d3d3||0x1f4;return function(_0x12b32f){logger[_0xf878('0x21')](_0x12b32f[_0xf878('0x22')]);if(_0x12b32f[_0xf878('0x23')]){delete _0x12b32f['name'];}_0x5b0b06['status'](_0xa3d3d3)['send'](_0x12b32f);};}exports[_0xf878('0x24')]=function(_0x3baba4,_0x38fa87){var _0x5af87f={},_0xfa3e11={},_0x2e2256={'count':0x0,'rows':[]};var _0x3e848d=_[_0xf878('0x25')](db[_0xf878('0x26')]['rawAttributes'],function(_0x502322){return{'name':_0x502322[_0xf878('0x27')],'type':_0x502322[_0xf878('0x28')]['key']};});_0xfa3e11[_0xf878('0x29')]=_['differenceBy'](_[_0xf878('0x25')](_0x3e848d,'name'),[_0xf878('0x23')]);_0xfa3e11['query']=_[_0xf878('0x2a')](_0x3baba4['query']);_0xfa3e11[_0xf878('0x2b')]=_[_0xf878('0x2c')](_0xfa3e11[_0xf878('0x29')],_0xfa3e11[_0xf878('0x2d')]);_0x5af87f[_0xf878('0x2e')]=_[_0xf878('0x2c')](_0xfa3e11['model'],qs[_0xf878('0x2f')](_0x3baba4[_0xf878('0x2d')][_0xf878('0x2f')]));_0x5af87f[_0xf878('0x2e')]=_0x5af87f[_0xf878('0x2e')]['length']?_0x5af87f[_0xf878('0x2e')]:_0xfa3e11[_0xf878('0x29')];if(!_0x3baba4['query'][_0xf878('0x30')](_0xf878('0x31'))){_0x5af87f[_0xf878('0x1a')]=qs[_0xf878('0x1a')](_0x3baba4[_0xf878('0x2d')]['limit']);_0x5af87f[_0xf878('0x19')]=qs[_0xf878('0x19')](_0x3baba4[_0xf878('0x2d')][_0xf878('0x19')]);}_0x5af87f['order']=qs[_0xf878('0x32')](_0x3baba4['query']['sort']);_0x5af87f[_0xf878('0x33')]=qs[_0xf878('0x2b')](_[_0xf878('0x34')](_0x3baba4[_0xf878('0x2d')],_0xfa3e11[_0xf878('0x2b')]),_0x3e848d);if(_0x3baba4['query'][_0xf878('0x35')]){_0x5af87f['where']=_[_0xf878('0x36')](_0x5af87f[_0xf878('0x33')],{'$or':_['map'](_0x3e848d,function(_0x1489d5){if(_0x1489d5[_0xf878('0x28')]!=='VIRTUAL'){var _0x329f0b={};_0x329f0b[_0x1489d5[_0xf878('0x23')]]={'$like':'%'+_0x3baba4['query'][_0xf878('0x35')]+'%'};return _0x329f0b;}})});}_0x5af87f=_[_0xf878('0x36')]({},_0x5af87f,_0x3baba4[_0xf878('0x37')]);var _0xc8eb91={'where':_0x5af87f[_0xf878('0x33')]};return db[_0xf878('0x26')][_0xf878('0x18')](_0xc8eb91)['then'](function(_0x1179fb){_0x2e2256[_0xf878('0x18')]=_0x1179fb;if(_0x3baba4['query'][_0xf878('0x38')]){_0x5af87f['include']=[{'all':!![]}];}return db['VoiceMailMessage'][_0xf878('0x39')](_0x5af87f);})[_0xf878('0x1f')](function(_0x43b03e){_0x2e2256[_0xf878('0x3a')]=_0x43b03e;return _0x2e2256;})[_0xf878('0x1f')](respondWithFilteredResult(_0x38fa87,_0x5af87f))['catch'](handleError(_0x38fa87,null));};exports[_0xf878('0x3b')]=function(_0x4c4ae4,_0xb09736){var _0x2801b0={'raw':!![],'where':{'id':_0x4c4ae4['params']['id']}},_0x4f6be1={};_0x4f6be1[_0xf878('0x29')]=_[_0xf878('0x2a')](db[_0xf878('0x26')][_0xf878('0x3c')]);_0x4f6be1[_0xf878('0x2d')]=_[_0xf878('0x2a')](_0x4c4ae4[_0xf878('0x2d')]);_0x4f6be1[_0xf878('0x2b')]=_[_0xf878('0x2c')](_0x4f6be1['model'],_0x4f6be1[_0xf878('0x2d')]);_0x2801b0[_0xf878('0x2e')]=_[_0xf878('0x2c')](_0x4f6be1[_0xf878('0x29')],qs[_0xf878('0x2f')](_0x4c4ae4[_0xf878('0x2d')]['fields']));_0x2801b0[_0xf878('0x2e')]=_0x2801b0[_0xf878('0x2e')][_0xf878('0x3d')]?_0x2801b0[_0xf878('0x2e')]:_0x4f6be1[_0xf878('0x29')];if(_0x4c4ae4['query'][_0xf878('0x38')]){_0x2801b0[_0xf878('0x3e')]=[{'all':!![]}];}_0x2801b0=_[_0xf878('0x36')]({},_0x2801b0,_0x4c4ae4[_0xf878('0x37')]);return db['VoiceMailMessage'][_0xf878('0x3f')](_0x2801b0)[_0xf878('0x1f')](handleEntityNotFound(_0xb09736,null))[_0xf878('0x1f')](respondWithResult(_0xb09736,null))['catch'](handleError(_0xb09736,null));};exports['create']=function(_0x9c2fa3,_0x5bf396){return db['VoiceMailMessage']['create'](_0x9c2fa3[_0xf878('0x40')],{})['then'](respondWithResult(_0x5bf396,0xc9))[_0xf878('0x41')](handleError(_0x5bf396,null));};exports[_0xf878('0x42')]=function(_0x1dcb19,_0x1ff60b){if(_0x1dcb19[_0xf878('0x40')]['id']){delete _0x1dcb19[_0xf878('0x40')]['id'];}return db[_0xf878('0x26')]['find']({'where':{'id':_0x1dcb19[_0xf878('0x43')]['id']}})[_0xf878('0x1f')](handleEntityNotFound(_0x1ff60b,null))[_0xf878('0x1f')](saveUpdates(_0x1dcb19[_0xf878('0x40')],null))[_0xf878('0x1f')](respondWithResult(_0x1ff60b,null))['catch'](handleError(_0x1ff60b,null));};exports['destroy']=function(_0xb4f8fb,_0x18c9dc){return db['VoiceMailMessage'][_0xf878('0x3f')]({'where':{'id':_0xb4f8fb['params']['id']}})[_0xf878('0x1f')](handleEntityNotFound(_0x18c9dc,null))[_0xf878('0x1f')](removeEntity(_0x18c9dc,null))[_0xf878('0x41')](handleError(_0x18c9dc,null));};exports[_0xf878('0x44')]=function(_0x5411c2,_0xf0d960,_0xd8fbc9){return db[_0xf878('0x26')]['find']({'where':{'id':_0x5411c2[_0xf878('0x43')]['id']},'attributes':['id',_0xf878('0x45'),_0xf878('0x46')]})[_0xf878('0x1f')](handleEntityNotFound(_0xf0d960,null))['then'](function(_0x112f2a){if(_0x112f2a){if(!_0x112f2a[_0xf878('0x45')]){throw new db[(_0xf878('0x47'))]['ValidationError'](_0xf878('0x48'));}var _0xdfa29b={'Content-Type':_0xf878('0x49'),'Content-Disposition':_0xf878('0x4a')};if(_0x112f2a['msg_id']){_0xdfa29b['Content-Disposition']='attachment;\x20filename=\x22'+_0x112f2a[_0xf878('0x46')]+'.wav\x22';}_0xf0d960['set'](_0xdfa29b);return _0xf0d960['send'](new Buffer(_0x112f2a[_0xf878('0x45')]));}})[_0xf878('0x41')](handleError(_0xf0d960,null));};