Built motion from commit (unavailable).|2.3.4
[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 _0x5f2f=['keys','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','filter','where','map','key','options','includeAll','include','findAll','rows','catch','show','params','find','create','body','download','recording','Sequelize','ValidationError','VoiceMailMessage\x20not\x20found','attachment','msg_id','attachment;\x20filename=\x22','.wav\x22','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','papaparse','../../components/auth/service','../../config/license/hardware','../../components/parsers/qs','../../config/utils','../../config/environment','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','save','update','then','destroy','error','stack','name','send','index','VoiceMailMessage','rawAttributes'];(function(_0x259cd1,_0x3460a1){var _0x1b5f6f=function(_0x2c3431){while(--_0x2c3431){_0x259cd1['push'](_0x259cd1['shift']());}};_0x1b5f6f(++_0x3460a1);}(_0x5f2f,0x73));var _0xf5f2=function(_0x300d13,_0x412659){_0x300d13=_0x300d13-0x0;var _0x39541d=_0x5f2f[_0x300d13];return _0x39541d;};'use strict';var pdf=require(_0xf5f2('0x0'));var emlformat=require(_0xf5f2('0x1'));var rimraf=require(_0xf5f2('0x2'));var zipdir=require(_0xf5f2('0x3'));var jsonpatch=require(_0xf5f2('0x4'));var rp=require(_0xf5f2('0x5'));var moment=require(_0xf5f2('0x6'));var BPromise=require(_0xf5f2('0x7'));var Mustache=require('mustache');var util=require('util');var path=require(_0xf5f2('0x8'));var sox=require(_0xf5f2('0x9'));var csv=require(_0xf5f2('0xa'));var ejs=require(_0xf5f2('0xb'));var fs=require('fs');var _=require(_0xf5f2('0xc'));var squel=require(_0xf5f2('0xd'));var crypto=require('crypto');var jsforce=require(_0xf5f2('0xe'));var deskjs=require(_0xf5f2('0xf'));var toCsv=require(_0xf5f2('0xa'));var querystring=require('querystring');var Papa=require(_0xf5f2('0x10'));var authService=require(_0xf5f2('0x11'));var hardwareService=require(_0xf5f2('0x12'));var Redis=require('ioredis');var qs=require(_0xf5f2('0x13'));var logger=require('../../config/logger')('api');var utils=require(_0xf5f2('0x14'));var config=require(_0xf5f2('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x336f6b,_0x14b51f){_0x14b51f=_0x14b51f||0xcc;return function(_0x331482){if(_0x331482){return _0x336f6b[_0xf5f2('0x16')](_0x14b51f);}return _0x336f6b[_0xf5f2('0x17')](_0x14b51f)[_0xf5f2('0x18')]();};}function respondWithResult(_0x5c01b8,_0x5850f4){_0x5850f4=_0x5850f4||0xc8;return function(_0xea612c){if(_0xea612c){return _0x5c01b8[_0xf5f2('0x17')](_0x5850f4)[_0xf5f2('0x19')](_0xea612c);}};}function respondWithFilteredResult(_0x422b55,_0x4d97fc){return function(_0xafe430){if(_0xafe430){var _0x286197=_0xafe430[_0xf5f2('0x1a')],_0x17d656=_0x4d97fc[_0xf5f2('0x1b')],_0x1b6dd2=_0x4d97fc[_0xf5f2('0x1b')]+_0x4d97fc[_0xf5f2('0x1c')],_0x23e23a;if(_0x1b6dd2>=_0x286197){_0x1b6dd2=_0x286197;_0x23e23a=0xc8;}else{_0x23e23a=0xce;}_0x422b55[_0xf5f2('0x17')](_0x23e23a);return _0x422b55[_0xf5f2('0x1d')](_0xf5f2('0x1e'),_0x17d656+'-'+_0x1b6dd2+'/'+_0x286197)[_0xf5f2('0x19')](_0xafe430);}return null;};}function patchUpdates(_0x3ee69){return function(_0x3cf5ea){try{jsonpatch[_0xf5f2('0x1f')](_0x3cf5ea,_0x3ee69,!![]);}catch(_0x1bf655){return BPromise['reject'](_0x1bf655);}return _0x3cf5ea[_0xf5f2('0x20')]();};}function saveUpdates(_0x47101e,_0x49dac2){return function(_0x47acfc){if(_0x47acfc){return _0x47acfc[_0xf5f2('0x21')](_0x47101e)[_0xf5f2('0x22')](function(_0x4ae323){return _0x4ae323;});}return null;};}function removeEntity(_0x45b74f,_0x170042){return function(_0x39e44a){if(_0x39e44a){return _0x39e44a[_0xf5f2('0x23')]()[_0xf5f2('0x22')](function(){_0x45b74f['status'](0xcc)[_0xf5f2('0x18')]();});}};}function handleEntityNotFound(_0x4669a6,_0x4e8bda){return function(_0x2833fe){if(!_0x2833fe){_0x4669a6[_0xf5f2('0x16')](0x194);}return _0x2833fe;};}function handleError(_0x5bdf4a,_0x529f07){_0x529f07=_0x529f07||0x1f4;return function(_0x5f1124){logger[_0xf5f2('0x24')](_0x5f1124[_0xf5f2('0x25')]);if(_0x5f1124[_0xf5f2('0x26')]){delete _0x5f1124[_0xf5f2('0x26')];}_0x5bdf4a[_0xf5f2('0x17')](_0x529f07)[_0xf5f2('0x27')](_0x5f1124);};}exports[_0xf5f2('0x28')]=function(_0x294414,_0x4ab014){var _0xaa2602={},_0x102449={},_0x375ca8={'count':0x0,'rows':[]};var _0x31bfcb=db[_0xf5f2('0x29')][_0xf5f2('0x2a')];_0x102449['model']=_['differenceBy'](_[_0xf5f2('0x2b')](_0x31bfcb),[_0xf5f2('0x26')]);_0x102449[_0xf5f2('0x2c')]=_['keys'](_0x294414['query']);_0x102449[_0xf5f2('0x2d')]=_[_0xf5f2('0x2e')](_0x102449[_0xf5f2('0x2f')],_0x102449[_0xf5f2('0x2c')]);_0xaa2602[_0xf5f2('0x30')]=_['intersection'](_0x102449['model'],qs[_0xf5f2('0x31')](_0x294414['query'][_0xf5f2('0x31')]));_0xaa2602['attributes']=_0xaa2602[_0xf5f2('0x30')][_0xf5f2('0x32')]?_0xaa2602[_0xf5f2('0x30')]:_0x102449[_0xf5f2('0x2f')];if(!_0x294414[_0xf5f2('0x2c')][_0xf5f2('0x33')](_0xf5f2('0x34'))){_0xaa2602[_0xf5f2('0x1c')]=qs['limit'](_0x294414[_0xf5f2('0x2c')][_0xf5f2('0x1c')]);_0xaa2602[_0xf5f2('0x1b')]=qs[_0xf5f2('0x1b')](_0x294414[_0xf5f2('0x2c')][_0xf5f2('0x1b')]);}_0xaa2602[_0xf5f2('0x35')]=qs['sort'](_0x294414[_0xf5f2('0x2c')][_0xf5f2('0x36')]);_0xaa2602['where']=qs[_0xf5f2('0x2d')](_['pick'](_0x294414[_0xf5f2('0x2c')],_0x102449[_0xf5f2('0x2d')]));if(_0x294414[_0xf5f2('0x2c')][_0xf5f2('0x37')]){_0xaa2602['where']=_['merge'](_0xaa2602[_0xf5f2('0x38')],{'$or':_[_0xf5f2('0x39')](_0x31bfcb,function(_0x20eb74){if(_0x20eb74['type'][_0xf5f2('0x3a')]!=='VIRTUAL'){var _0x9da533={};_0x9da533[_0x20eb74['field']]={'$like':'%'+_0x294414[_0xf5f2('0x2c')][_0xf5f2('0x37')]+'%'};return _0x9da533;}})});}_0xaa2602=_['merge']({},_0xaa2602,_0x294414[_0xf5f2('0x3b')]);var _0x46eb22={'where':_0xaa2602[_0xf5f2('0x38')]};return db[_0xf5f2('0x29')]['count'](_0x46eb22)['then'](function(_0x3d328f){_0x375ca8[_0xf5f2('0x1a')]=_0x3d328f;if(_0x294414[_0xf5f2('0x2c')][_0xf5f2('0x3c')]){_0xaa2602[_0xf5f2('0x3d')]=[{'all':!![]}];}return db[_0xf5f2('0x29')][_0xf5f2('0x3e')](_0xaa2602);})['then'](function(_0x110fe5){_0x375ca8[_0xf5f2('0x3f')]=_0x110fe5;return _0x375ca8;})['then'](respondWithFilteredResult(_0x4ab014,_0xaa2602))[_0xf5f2('0x40')](handleError(_0x4ab014,null));};exports[_0xf5f2('0x41')]=function(_0x71b0e7,_0x85b6d0){var _0xd10701={'raw':!![],'where':{'id':_0x71b0e7[_0xf5f2('0x42')]['id']}},_0x3b6372={};_0x3b6372[_0xf5f2('0x2f')]=_['keys'](db[_0xf5f2('0x29')][_0xf5f2('0x2a')]);_0x3b6372[_0xf5f2('0x2c')]=_['keys'](_0x71b0e7['query']);_0x3b6372['filters']=_[_0xf5f2('0x2e')](_0x3b6372[_0xf5f2('0x2f')],_0x3b6372['query']);_0xd10701[_0xf5f2('0x30')]=_[_0xf5f2('0x2e')](_0x3b6372[_0xf5f2('0x2f')],qs[_0xf5f2('0x31')](_0x71b0e7[_0xf5f2('0x2c')][_0xf5f2('0x31')]));_0xd10701[_0xf5f2('0x30')]=_0xd10701[_0xf5f2('0x30')][_0xf5f2('0x32')]?_0xd10701[_0xf5f2('0x30')]:_0x3b6372[_0xf5f2('0x2f')];if(_0x71b0e7[_0xf5f2('0x2c')][_0xf5f2('0x3c')]){_0xd10701[_0xf5f2('0x3d')]=[{'all':!![]}];}_0xd10701=_['merge']({},_0xd10701,_0x71b0e7[_0xf5f2('0x3b')]);return db['VoiceMailMessage'][_0xf5f2('0x43')](_0xd10701)[_0xf5f2('0x22')](handleEntityNotFound(_0x85b6d0,null))[_0xf5f2('0x22')](respondWithResult(_0x85b6d0,null))[_0xf5f2('0x40')](handleError(_0x85b6d0,null));};exports[_0xf5f2('0x44')]=function(_0x3721c4,_0x55a633){return db[_0xf5f2('0x29')][_0xf5f2('0x44')](_0x3721c4[_0xf5f2('0x45')],{})[_0xf5f2('0x22')](respondWithResult(_0x55a633,0xc9))[_0xf5f2('0x40')](handleError(_0x55a633,null));};exports[_0xf5f2('0x21')]=function(_0xf638ff,_0x297f07){if(_0xf638ff['body']['id']){delete _0xf638ff[_0xf5f2('0x45')]['id'];}return db[_0xf5f2('0x29')][_0xf5f2('0x43')]({'where':{'id':_0xf638ff['params']['id']}})[_0xf5f2('0x22')](handleEntityNotFound(_0x297f07,null))[_0xf5f2('0x22')](saveUpdates(_0xf638ff[_0xf5f2('0x45')],null))['then'](respondWithResult(_0x297f07,null))['catch'](handleError(_0x297f07,null));};exports[_0xf5f2('0x23')]=function(_0x27c472,_0x5db519){return db[_0xf5f2('0x29')]['find']({'where':{'id':_0x27c472[_0xf5f2('0x42')]['id']}})['then'](handleEntityNotFound(_0x5db519,null))[_0xf5f2('0x22')](removeEntity(_0x5db519,null))['catch'](handleError(_0x5db519,null));};exports[_0xf5f2('0x46')]=function(_0xb8ea3a,_0xbb658c,_0x11a083){return db['VoiceMailMessage'][_0xf5f2('0x43')]({'where':{'id':_0xb8ea3a[_0xf5f2('0x42')]['id']},'attributes':['id','recording','msg_id']})[_0xf5f2('0x22')](handleEntityNotFound(_0xbb658c,null))[_0xf5f2('0x22')](function(_0x57782c){if(_0x57782c){if(!_0x57782c[_0xf5f2('0x47')]){throw new db[(_0xf5f2('0x48'))][(_0xf5f2('0x49'))](_0xf5f2('0x4a'));}var _0x5d0db0={'Content-Type':'audio/wav','Content-Disposition':_0xf5f2('0x4b')};if(_0x57782c[_0xf5f2('0x4c')]){_0x5d0db0['Content-Disposition']=_0xf5f2('0x4d')+_0x57782c[_0xf5f2('0x4c')]+_0xf5f2('0x4e');}_0xbb658c[_0xf5f2('0x1d')](_0x5d0db0);return _0xbb658c[_0xf5f2('0x27')](new Buffer(_0x57782c[_0xf5f2('0x47')]));}})[_0xf5f2('0x40')](handleError(_0xbb658c,null));};