Built motion from commit 44b1f254.|2.6.26
[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 _0x3f53=['where','merge','options','include','rows','catch','show','params','includeAll','create','body','find','download','recording','Sequelize','ValidationError','VoiceMailMessage\x20not\x20found','msg_id','Content-Disposition','attachment;\x20filename=\x22','.wav\x22','set','send','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','ejs','fs-extra','lodash','crypto','jsforce','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','Content-Range','apply','reject','update','then','destroy','error','name','index','VoiceMailMessage','rawAttributes','type','key','model','map','keys','query','filters','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort'];(function(_0xf3cb83,_0x57bf9e){var _0x44acc3=function(_0x52377c){while(--_0x52377c){_0xf3cb83['push'](_0xf3cb83['shift']());}};_0x44acc3(++_0x57bf9e);}(_0x3f53,0x68));var _0x33f5=function(_0x1fd56f,_0x1dcc57){_0x1fd56f=_0x1fd56f-0x0;var _0x30bdba=_0x3f53[_0x1fd56f];return _0x30bdba;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x33f5('0x0'));var zipdir=require(_0x33f5('0x1'));var jsonpatch=require(_0x33f5('0x2'));var rp=require(_0x33f5('0x3'));var moment=require(_0x33f5('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x33f5('0x5'));var util=require(_0x33f5('0x6'));var path=require(_0x33f5('0x7'));var sox=require(_0x33f5('0x8'));var csv=require('to-csv');var ejs=require(_0x33f5('0x9'));var fs=require('fs');var fs_extra=require(_0x33f5('0xa'));var _=require(_0x33f5('0xb'));var squel=require('squel');var crypto=require(_0x33f5('0xc'));var jsforce=require(_0x33f5('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x33f5('0xe'));var querystring=require('querystring');var Papa=require(_0x33f5('0xf'));var Redis=require(_0x33f5('0x10'));var authService=require(_0x33f5('0x11'));var qs=require(_0x33f5('0x12'));var as=require(_0x33f5('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x33f5('0x14'))(_0x33f5('0x15'));var utils=require('../../config/utils');var config=require(_0x33f5('0x16'));var licenseUtil=require(_0x33f5('0x17'));var db=require(_0x33f5('0x18'))['db'];function respondWithStatusCode(_0x5afedc,_0x4c13af){_0x4c13af=_0x4c13af||0xcc;return function(_0x5e8435){if(_0x5e8435){return _0x5afedc[_0x33f5('0x19')](_0x4c13af);}return _0x5afedc[_0x33f5('0x1a')](_0x4c13af)[_0x33f5('0x1b')]();};}function respondWithResult(_0x1d8c2b,_0xd44f4d){_0xd44f4d=_0xd44f4d||0xc8;return function(_0x550cd5){if(_0x550cd5){return _0x1d8c2b[_0x33f5('0x1a')](_0xd44f4d)[_0x33f5('0x1c')](_0x550cd5);}};}function respondWithFilteredResult(_0x4e568a,_0x258922){return function(_0x1141ca){if(_0x1141ca){var _0x130f3c=typeof _0x258922[_0x33f5('0x1d')]===_0x33f5('0x1e')&&typeof _0x258922[_0x33f5('0x1f')]===_0x33f5('0x1e');var _0x4148f1=_0x1141ca['count'];var _0x3317b1=_0x130f3c?0x0:_0x258922['offset'];var _0x19fb93=_0x130f3c?_0x1141ca[_0x33f5('0x20')]:_0x258922[_0x33f5('0x1d')]+_0x258922[_0x33f5('0x1f')];var _0x519364;if(_0x19fb93>=_0x4148f1){_0x19fb93=_0x4148f1;_0x519364=0xc8;}else{_0x519364=0xce;}_0x4e568a[_0x33f5('0x1a')](_0x519364);return _0x4e568a['set'](_0x33f5('0x21'),_0x3317b1+'-'+_0x19fb93+'/'+_0x4148f1)[_0x33f5('0x1c')](_0x1141ca);}return null;};}function patchUpdates(_0x53ff7a){return function(_0x66af27){try{jsonpatch[_0x33f5('0x22')](_0x66af27,_0x53ff7a,!![]);}catch(_0x208e2e){return BPromise[_0x33f5('0x23')](_0x208e2e);}return _0x66af27['save']();};}function saveUpdates(_0xca8a4,_0x2eb7c5){return function(_0x20dc60){if(_0x20dc60){return _0x20dc60[_0x33f5('0x24')](_0xca8a4)[_0x33f5('0x25')](function(_0x17d0bf){return _0x17d0bf;});}return null;};}function removeEntity(_0x5c452c,_0x5a7e8c){return function(_0x4dec9d){if(_0x4dec9d){return _0x4dec9d[_0x33f5('0x26')]()[_0x33f5('0x25')](function(){_0x5c452c[_0x33f5('0x1a')](0xcc)[_0x33f5('0x1b')]();});}};}function handleEntityNotFound(_0xf60780,_0x35272d){return function(_0x3cc8d9){if(!_0x3cc8d9){_0xf60780[_0x33f5('0x19')](0x194);}return _0x3cc8d9;};}function handleError(_0x1dc955,_0x15ece9){_0x15ece9=_0x15ece9||0x1f4;return function(_0x1c898c){logger[_0x33f5('0x27')](_0x1c898c['stack']);if(_0x1c898c[_0x33f5('0x28')]){delete _0x1c898c[_0x33f5('0x28')];}_0x1dc955[_0x33f5('0x1a')](_0x15ece9)['send'](_0x1c898c);};}exports[_0x33f5('0x29')]=function(_0x3f5b01,_0x32cf47){var _0x3e468d={},_0x497bf9={},_0x2a87db={'count':0x0,'rows':[]};var _0x4c6912=_['map'](db[_0x33f5('0x2a')][_0x33f5('0x2b')],function(_0x315fb2){return{'name':_0x315fb2['fieldName'],'type':_0x315fb2[_0x33f5('0x2c')][_0x33f5('0x2d')]};});_0x497bf9[_0x33f5('0x2e')]=_['differenceBy'](_[_0x33f5('0x2f')](_0x4c6912,'name'),[_0x33f5('0x28')]);_0x497bf9['query']=_[_0x33f5('0x30')](_0x3f5b01[_0x33f5('0x31')]);_0x497bf9[_0x33f5('0x32')]=_[_0x33f5('0x33')](_0x497bf9[_0x33f5('0x2e')],_0x497bf9['query']);_0x3e468d['attributes']=_['intersection'](_0x497bf9[_0x33f5('0x2e')],qs['fields'](_0x3f5b01['query'][_0x33f5('0x34')]));_0x3e468d[_0x33f5('0x35')]=_0x3e468d[_0x33f5('0x35')]['length']?_0x3e468d[_0x33f5('0x35')]:_0x497bf9[_0x33f5('0x2e')];if(!_0x3f5b01[_0x33f5('0x31')][_0x33f5('0x36')](_0x33f5('0x37'))){_0x3e468d[_0x33f5('0x1f')]=qs['limit'](_0x3f5b01[_0x33f5('0x31')][_0x33f5('0x1f')]);_0x3e468d[_0x33f5('0x1d')]=qs[_0x33f5('0x1d')](_0x3f5b01['query']['offset']);}_0x3e468d[_0x33f5('0x38')]=qs['sort'](_0x3f5b01[_0x33f5('0x31')][_0x33f5('0x39')]);_0x3e468d[_0x33f5('0x3a')]=qs[_0x33f5('0x32')](_['pick'](_0x3f5b01[_0x33f5('0x31')],_0x497bf9['filters']),_0x4c6912);if(_0x3f5b01[_0x33f5('0x31')]['filter']){_0x3e468d['where']=_[_0x33f5('0x3b')](_0x3e468d['where'],{'$or':_[_0x33f5('0x2f')](_0x4c6912,function(_0x25295b){if(_0x25295b[_0x33f5('0x2c')]!=='VIRTUAL'){var _0x278e14={};_0x278e14[_0x25295b[_0x33f5('0x28')]]={'$like':'%'+_0x3f5b01['query']['filter']+'%'};return _0x278e14;}})});}_0x3e468d=_[_0x33f5('0x3b')]({},_0x3e468d,_0x3f5b01[_0x33f5('0x3c')]);var _0x45f83e={'where':_0x3e468d[_0x33f5('0x3a')]};return db[_0x33f5('0x2a')][_0x33f5('0x20')](_0x45f83e)[_0x33f5('0x25')](function(_0x20a6a7){_0x2a87db[_0x33f5('0x20')]=_0x20a6a7;if(_0x3f5b01['query']['includeAll']){_0x3e468d[_0x33f5('0x3d')]=[{'all':!![]}];}return db[_0x33f5('0x2a')]['findAll'](_0x3e468d);})[_0x33f5('0x25')](function(_0x320f7d){_0x2a87db[_0x33f5('0x3e')]=_0x320f7d;return _0x2a87db;})[_0x33f5('0x25')](respondWithFilteredResult(_0x32cf47,_0x3e468d))[_0x33f5('0x3f')](handleError(_0x32cf47,null));};exports[_0x33f5('0x40')]=function(_0x187126,_0x37f988){var _0x19e786={'raw':!![],'where':{'id':_0x187126[_0x33f5('0x41')]['id']}},_0x1d3401={};_0x1d3401['model']=_['keys'](db[_0x33f5('0x2a')]['rawAttributes']);_0x1d3401[_0x33f5('0x31')]=_[_0x33f5('0x30')](_0x187126[_0x33f5('0x31')]);_0x1d3401['filters']=_[_0x33f5('0x33')](_0x1d3401[_0x33f5('0x2e')],_0x1d3401[_0x33f5('0x31')]);_0x19e786[_0x33f5('0x35')]=_[_0x33f5('0x33')](_0x1d3401[_0x33f5('0x2e')],qs[_0x33f5('0x34')](_0x187126['query'][_0x33f5('0x34')]));_0x19e786[_0x33f5('0x35')]=_0x19e786[_0x33f5('0x35')]['length']?_0x19e786[_0x33f5('0x35')]:_0x1d3401[_0x33f5('0x2e')];if(_0x187126[_0x33f5('0x31')][_0x33f5('0x42')]){_0x19e786[_0x33f5('0x3d')]=[{'all':!![]}];}_0x19e786=_[_0x33f5('0x3b')]({},_0x19e786,_0x187126[_0x33f5('0x3c')]);return db[_0x33f5('0x2a')]['find'](_0x19e786)[_0x33f5('0x25')](handleEntityNotFound(_0x37f988,null))['then'](respondWithResult(_0x37f988,null))[_0x33f5('0x3f')](handleError(_0x37f988,null));};exports[_0x33f5('0x43')]=function(_0x58ca1f,_0x15e3d6){return db[_0x33f5('0x2a')][_0x33f5('0x43')](_0x58ca1f[_0x33f5('0x44')],{})[_0x33f5('0x25')](respondWithResult(_0x15e3d6,0xc9))[_0x33f5('0x3f')](handleError(_0x15e3d6,null));};exports['update']=function(_0x474d0c,_0x330cf7){if(_0x474d0c[_0x33f5('0x44')]['id']){delete _0x474d0c[_0x33f5('0x44')]['id'];}return db['VoiceMailMessage'][_0x33f5('0x45')]({'where':{'id':_0x474d0c[_0x33f5('0x41')]['id']}})['then'](handleEntityNotFound(_0x330cf7,null))[_0x33f5('0x25')](saveUpdates(_0x474d0c[_0x33f5('0x44')],null))['then'](respondWithResult(_0x330cf7,null))[_0x33f5('0x3f')](handleError(_0x330cf7,null));};exports[_0x33f5('0x26')]=function(_0x1a2586,_0x4563f9){return db['VoiceMailMessage'][_0x33f5('0x45')]({'where':{'id':_0x1a2586['params']['id']}})[_0x33f5('0x25')](handleEntityNotFound(_0x4563f9,null))[_0x33f5('0x25')](removeEntity(_0x4563f9,null))[_0x33f5('0x3f')](handleError(_0x4563f9,null));};exports[_0x33f5('0x46')]=function(_0x48d4ac,_0x28e2e5,_0x1b3660){return db['VoiceMailMessage'][_0x33f5('0x45')]({'where':{'id':_0x48d4ac[_0x33f5('0x41')]['id']},'attributes':['id',_0x33f5('0x47'),'msg_id']})[_0x33f5('0x25')](handleEntityNotFound(_0x28e2e5,null))['then'](function(_0x397f75){if(_0x397f75){if(!_0x397f75['recording']){throw new db[(_0x33f5('0x48'))][(_0x33f5('0x49'))](_0x33f5('0x4a'));}var _0x138400={'Content-Type':'audio/wav','Content-Disposition':'attachment'};if(_0x397f75[_0x33f5('0x4b')]){_0x138400[_0x33f5('0x4c')]=_0x33f5('0x4d')+_0x397f75[_0x33f5('0x4b')]+_0x33f5('0x4e');}_0x28e2e5[_0x33f5('0x4f')](_0x138400);return _0x28e2e5[_0x33f5('0x50')](new Buffer(_0x397f75[_0x33f5('0x47')]));}})[_0x33f5('0x3f')](handleError(_0x28e2e5,null));};