f367e69877c695565ec0b682a4677d2dd98af01d
[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 _0xf099=['map','VIRTUAL','options','include','rows','show','params','includeAll','find','catch','create','body','update','download','recording','msg_id','ValidationError','VoiceMailMessage\x20not\x20found','audio/wav','attachment','Content-Disposition','attachment;\x20filename=\x22','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','Content-Range','apply','save','then','destroy','error','stack','name','send','index','VoiceMailMessage','rawAttributes','fieldName','type','key','model','keys','query','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','sort','pick','filter','where','merge'];(function(_0x500419,_0x549162){var _0x241c1a=function(_0x3bea1a){while(--_0x3bea1a){_0x500419['push'](_0x500419['shift']());}};_0x241c1a(++_0x549162);}(_0xf099,0x6e));var _0x9f09=function(_0x1f7839,_0x2a26e6){_0x1f7839=_0x1f7839-0x0;var _0x36b42e=_0xf099[_0x1f7839];return _0x36b42e;};'use strict';var emlformat=require(_0x9f09('0x0'));var rimraf=require(_0x9f09('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x9f09('0x2'));var rp=require(_0x9f09('0x3'));var moment=require(_0x9f09('0x4'));var BPromise=require(_0x9f09('0x5'));var Mustache=require(_0x9f09('0x6'));var util=require(_0x9f09('0x7'));var path=require(_0x9f09('0x8'));var sox=require(_0x9f09('0x9'));var csv=require('to-csv');var ejs=require(_0x9f09('0xa'));var fs=require('fs');var fs_extra=require(_0x9f09('0xb'));var _=require(_0x9f09('0xc'));var squel=require(_0x9f09('0xd'));var crypto=require(_0x9f09('0xe'));var jsforce=require(_0x9f09('0xf'));var deskjs=require(_0x9f09('0x10'));var toCsv=require(_0x9f09('0x11'));var querystring=require(_0x9f09('0x12'));var Papa=require(_0x9f09('0x13'));var Redis=require(_0x9f09('0x14'));var authService=require(_0x9f09('0x15'));var qs=require(_0x9f09('0x16'));var as=require(_0x9f09('0x17'));var hardwareService=require(_0x9f09('0x18'));var logger=require(_0x9f09('0x19'))('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x9f09('0x1a'));var db=require(_0x9f09('0x1b'))['db'];function respondWithStatusCode(_0x5cc8b1,_0x496876){_0x496876=_0x496876||0xcc;return function(_0x262419){if(_0x262419){return _0x5cc8b1[_0x9f09('0x1c')](_0x496876);}return _0x5cc8b1[_0x9f09('0x1d')](_0x496876)[_0x9f09('0x1e')]();};}function respondWithResult(_0x2586da,_0x2198b9){_0x2198b9=_0x2198b9||0xc8;return function(_0x299734){if(_0x299734){return _0x2586da[_0x9f09('0x1d')](_0x2198b9)[_0x9f09('0x1f')](_0x299734);}};}function respondWithFilteredResult(_0x184fd5,_0x3ae924){return function(_0x3a738a){if(_0x3a738a){var _0xbd4a0=typeof _0x3ae924[_0x9f09('0x20')]===_0x9f09('0x21')&&typeof _0x3ae924[_0x9f09('0x22')]==='undefined';var _0x4ddd1d=_0x3a738a[_0x9f09('0x23')];var _0x299d59=_0xbd4a0?0x0:_0x3ae924['offset'];var _0x1832cf=_0xbd4a0?_0x3a738a[_0x9f09('0x23')]:_0x3ae924[_0x9f09('0x20')]+_0x3ae924['limit'];var _0x560839;if(_0x1832cf>=_0x4ddd1d){_0x1832cf=_0x4ddd1d;_0x560839=0xc8;}else{_0x560839=0xce;}_0x184fd5[_0x9f09('0x1d')](_0x560839);return _0x184fd5['set'](_0x9f09('0x24'),_0x299d59+'-'+_0x1832cf+'/'+_0x4ddd1d)['json'](_0x3a738a);}return null;};}function patchUpdates(_0x4064b9){return function(_0x47abff){try{jsonpatch[_0x9f09('0x25')](_0x47abff,_0x4064b9,!![]);}catch(_0x3a1353){return BPromise['reject'](_0x3a1353);}return _0x47abff[_0x9f09('0x26')]();};}function saveUpdates(_0x43a7c2,_0x56fc42){return function(_0xe9d8b2){if(_0xe9d8b2){return _0xe9d8b2['update'](_0x43a7c2)[_0x9f09('0x27')](function(_0x1004cb){return _0x1004cb;});}return null;};}function removeEntity(_0x2626f9,_0x34a413){return function(_0x5708a2){if(_0x5708a2){return _0x5708a2[_0x9f09('0x28')]()[_0x9f09('0x27')](function(){_0x2626f9['status'](0xcc)[_0x9f09('0x1e')]();});}};}function handleEntityNotFound(_0x34f6f1,_0x3165e5){return function(_0x1ac497){if(!_0x1ac497){_0x34f6f1['sendStatus'](0x194);}return _0x1ac497;};}function handleError(_0x2ba015,_0x31a9c6){_0x31a9c6=_0x31a9c6||0x1f4;return function(_0x1c9995){logger[_0x9f09('0x29')](_0x1c9995[_0x9f09('0x2a')]);if(_0x1c9995[_0x9f09('0x2b')]){delete _0x1c9995[_0x9f09('0x2b')];}_0x2ba015[_0x9f09('0x1d')](_0x31a9c6)[_0x9f09('0x2c')](_0x1c9995);};}exports[_0x9f09('0x2d')]=function(_0x292a46,_0x3ff4c6){var _0x5bc7ff={},_0x69ae5a={},_0x55a038={'count':0x0,'rows':[]};var _0x3365c6=_['map'](db[_0x9f09('0x2e')][_0x9f09('0x2f')],function(_0x39abcf){return{'name':_0x39abcf[_0x9f09('0x30')],'type':_0x39abcf[_0x9f09('0x31')][_0x9f09('0x32')]};});_0x69ae5a[_0x9f09('0x33')]=_['differenceBy'](_['map'](_0x3365c6,_0x9f09('0x2b')),[_0x9f09('0x2b')]);_0x69ae5a['query']=_[_0x9f09('0x34')](_0x292a46[_0x9f09('0x35')]);_0x69ae5a[_0x9f09('0x36')]=_['intersection'](_0x69ae5a['model'],_0x69ae5a['query']);_0x5bc7ff[_0x9f09('0x37')]=_[_0x9f09('0x38')](_0x69ae5a['model'],qs[_0x9f09('0x39')](_0x292a46['query']['fields']));_0x5bc7ff[_0x9f09('0x37')]=_0x5bc7ff[_0x9f09('0x37')][_0x9f09('0x3a')]?_0x5bc7ff[_0x9f09('0x37')]:_0x69ae5a['model'];if(!_0x292a46[_0x9f09('0x35')][_0x9f09('0x3b')](_0x9f09('0x3c'))){_0x5bc7ff[_0x9f09('0x22')]=qs[_0x9f09('0x22')](_0x292a46[_0x9f09('0x35')][_0x9f09('0x22')]);_0x5bc7ff['offset']=qs[_0x9f09('0x20')](_0x292a46[_0x9f09('0x35')][_0x9f09('0x20')]);}_0x5bc7ff['order']=qs[_0x9f09('0x3d')](_0x292a46[_0x9f09('0x35')][_0x9f09('0x3d')]);_0x5bc7ff['where']=qs['filters'](_[_0x9f09('0x3e')](_0x292a46['query'],_0x69ae5a[_0x9f09('0x36')]),_0x3365c6);if(_0x292a46[_0x9f09('0x35')][_0x9f09('0x3f')]){_0x5bc7ff[_0x9f09('0x40')]=_[_0x9f09('0x41')](_0x5bc7ff[_0x9f09('0x40')],{'$or':_[_0x9f09('0x42')](_0x3365c6,function(_0x48e6d0){if(_0x48e6d0['type']!==_0x9f09('0x43')){var _0x217be2={};_0x217be2[_0x48e6d0[_0x9f09('0x2b')]]={'$like':'%'+_0x292a46[_0x9f09('0x35')]['filter']+'%'};return _0x217be2;}})});}_0x5bc7ff=_['merge']({},_0x5bc7ff,_0x292a46[_0x9f09('0x44')]);var _0xecdf02={'where':_0x5bc7ff[_0x9f09('0x40')]};return db[_0x9f09('0x2e')][_0x9f09('0x23')](_0xecdf02)['then'](function(_0x48f0d2){_0x55a038['count']=_0x48f0d2;if(_0x292a46[_0x9f09('0x35')]['includeAll']){_0x5bc7ff[_0x9f09('0x45')]=[{'all':!![]}];}return db['VoiceMailMessage']['findAll'](_0x5bc7ff);})[_0x9f09('0x27')](function(_0x16b1a0){_0x55a038[_0x9f09('0x46')]=_0x16b1a0;return _0x55a038;})[_0x9f09('0x27')](respondWithFilteredResult(_0x3ff4c6,_0x5bc7ff))['catch'](handleError(_0x3ff4c6,null));};exports[_0x9f09('0x47')]=function(_0x32d2b9,_0x2876bc){var _0x227993={'raw':!![],'where':{'id':_0x32d2b9[_0x9f09('0x48')]['id']}},_0x3ab46c={};_0x3ab46c[_0x9f09('0x33')]=_['keys'](db[_0x9f09('0x2e')][_0x9f09('0x2f')]);_0x3ab46c[_0x9f09('0x35')]=_[_0x9f09('0x34')](_0x32d2b9[_0x9f09('0x35')]);_0x3ab46c[_0x9f09('0x36')]=_[_0x9f09('0x38')](_0x3ab46c['model'],_0x3ab46c['query']);_0x227993['attributes']=_['intersection'](_0x3ab46c[_0x9f09('0x33')],qs[_0x9f09('0x39')](_0x32d2b9['query'][_0x9f09('0x39')]));_0x227993[_0x9f09('0x37')]=_0x227993[_0x9f09('0x37')][_0x9f09('0x3a')]?_0x227993[_0x9f09('0x37')]:_0x3ab46c[_0x9f09('0x33')];if(_0x32d2b9[_0x9f09('0x35')][_0x9f09('0x49')]){_0x227993[_0x9f09('0x45')]=[{'all':!![]}];}_0x227993=_[_0x9f09('0x41')]({},_0x227993,_0x32d2b9[_0x9f09('0x44')]);return db[_0x9f09('0x2e')][_0x9f09('0x4a')](_0x227993)[_0x9f09('0x27')](handleEntityNotFound(_0x2876bc,null))['then'](respondWithResult(_0x2876bc,null))[_0x9f09('0x4b')](handleError(_0x2876bc,null));};exports[_0x9f09('0x4c')]=function(_0x21a165,_0x34f564){return db[_0x9f09('0x2e')][_0x9f09('0x4c')](_0x21a165[_0x9f09('0x4d')],{})[_0x9f09('0x27')](respondWithResult(_0x34f564,0xc9))['catch'](handleError(_0x34f564,null));};exports[_0x9f09('0x4e')]=function(_0x3e8ab8,_0x555f54){if(_0x3e8ab8[_0x9f09('0x4d')]['id']){delete _0x3e8ab8[_0x9f09('0x4d')]['id'];}return db[_0x9f09('0x2e')]['find']({'where':{'id':_0x3e8ab8['params']['id']}})['then'](handleEntityNotFound(_0x555f54,null))[_0x9f09('0x27')](saveUpdates(_0x3e8ab8['body'],null))[_0x9f09('0x27')](respondWithResult(_0x555f54,null))[_0x9f09('0x4b')](handleError(_0x555f54,null));};exports[_0x9f09('0x28')]=function(_0x261361,_0x11e489){return db[_0x9f09('0x2e')]['find']({'where':{'id':_0x261361[_0x9f09('0x48')]['id']}})[_0x9f09('0x27')](handleEntityNotFound(_0x11e489,null))['then'](removeEntity(_0x11e489,null))[_0x9f09('0x4b')](handleError(_0x11e489,null));};exports[_0x9f09('0x4f')]=function(_0x50512f,_0x3a0acb,_0x213d66){return db[_0x9f09('0x2e')]['find']({'where':{'id':_0x50512f[_0x9f09('0x48')]['id']},'attributes':['id',_0x9f09('0x50'),_0x9f09('0x51')]})[_0x9f09('0x27')](handleEntityNotFound(_0x3a0acb,null))[_0x9f09('0x27')](function(_0x5ea174){if(_0x5ea174){if(!_0x5ea174[_0x9f09('0x50')]){throw new db['Sequelize'][(_0x9f09('0x52'))](_0x9f09('0x53'));}var _0x3a2f2c={'Content-Type':_0x9f09('0x54'),'Content-Disposition':_0x9f09('0x55')};if(_0x5ea174[_0x9f09('0x51')]){_0x3a2f2c[_0x9f09('0x56')]=_0x9f09('0x57')+_0x5ea174[_0x9f09('0x51')]+'.wav\x22';}_0x3a0acb['set'](_0x3a2f2c);return _0x3a0acb[_0x9f09('0x2c')](new Buffer(_0x5ea174['recording']));}})[_0x9f09('0x4b')](handleError(_0x3a0acb,null));};