e77cbe2cb2a93088072f016ec2c20daa1499bec8
[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 _0x378f=['pick','filter','VIRTUAL','merge','includeAll','findAll','show','find','catch','create','body','params','download','recording','Sequelize','VoiceMailMessage\x20not\x20found','audio/wav','attachment','msg_id','Content-Disposition','attachment;\x20filename=\x22','.wav\x22','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','path','sox','fs-extra','lodash','crypto','jsforce','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','json','reject','save','update','then','destroy','stack','name','send','index','map','VoiceMailMessage','rawAttributes','type','model','differenceBy','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters'];(function(_0x58cbc5,_0x3de123){var _0x38a8d9=function(_0x3a92be){while(--_0x3a92be){_0x58cbc5['push'](_0x58cbc5['shift']());}};_0x38a8d9(++_0x3de123);}(_0x378f,0x68));var _0xf378=function(_0x19980b,_0xa4ee2f){_0x19980b=_0x19980b-0x0;var _0x1bd017=_0x378f[_0x19980b];return _0x1bd017;};'use strict';var emlformat=require(_0xf378('0x0'));var rimraf=require(_0xf378('0x1'));var zipdir=require(_0xf378('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf378('0x3'));var moment=require(_0xf378('0x4'));var BPromise=require(_0xf378('0x5'));var Mustache=require(_0xf378('0x6'));var util=require('util');var path=require(_0xf378('0x7'));var sox=require(_0xf378('0x8'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf378('0x9'));var _=require(_0xf378('0xa'));var squel=require('squel');var crypto=require(_0xf378('0xb'));var jsforce=require(_0xf378('0xc'));var deskjs=require(_0xf378('0xd'));var toCsv=require(_0xf378('0xe'));var querystring=require(_0xf378('0xf'));var Papa=require(_0xf378('0x10'));var Redis=require('ioredis');var authService=require(_0xf378('0x11'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf378('0x12'));var logger=require(_0xf378('0x13'))(_0xf378('0x14'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0xf378('0x15'));var db=require(_0xf378('0x16'))['db'];function respondWithStatusCode(_0x4722c8,_0xdcfcf0){_0xdcfcf0=_0xdcfcf0||0xcc;return function(_0x171f65){if(_0x171f65){return _0x4722c8[_0xf378('0x17')](_0xdcfcf0);}return _0x4722c8[_0xf378('0x18')](_0xdcfcf0)[_0xf378('0x19')]();};}function respondWithResult(_0x21bc9b,_0x2d5a83){_0x2d5a83=_0x2d5a83||0xc8;return function(_0x1b7ca2){if(_0x1b7ca2){return _0x21bc9b[_0xf378('0x18')](_0x2d5a83)['json'](_0x1b7ca2);}};}function respondWithFilteredResult(_0x2c73a6,_0x69b6ec){return function(_0x247319){if(_0x247319){var _0x2570cc=typeof _0x69b6ec[_0xf378('0x1a')]===_0xf378('0x1b')&&typeof _0x69b6ec[_0xf378('0x1c')]===_0xf378('0x1b');var _0x304ac0=_0x247319[_0xf378('0x1d')];var _0x1dc026=_0x2570cc?0x0:_0x69b6ec[_0xf378('0x1a')];var _0x5416d2=_0x2570cc?_0x247319[_0xf378('0x1d')]:_0x69b6ec['offset']+_0x69b6ec[_0xf378('0x1c')];var _0x2119ec;if(_0x5416d2>=_0x304ac0){_0x5416d2=_0x304ac0;_0x2119ec=0xc8;}else{_0x2119ec=0xce;}_0x2c73a6[_0xf378('0x18')](_0x2119ec);return _0x2c73a6[_0xf378('0x1e')](_0xf378('0x1f'),_0x1dc026+'-'+_0x5416d2+'/'+_0x304ac0)[_0xf378('0x20')](_0x247319);}return null;};}function patchUpdates(_0x10e22a){return function(_0x5b2f84){try{jsonpatch['apply'](_0x5b2f84,_0x10e22a,!![]);}catch(_0x1e1f56){return BPromise[_0xf378('0x21')](_0x1e1f56);}return _0x5b2f84[_0xf378('0x22')]();};}function saveUpdates(_0x5da3c4,_0x5d0e26){return function(_0x26bf89){if(_0x26bf89){return _0x26bf89[_0xf378('0x23')](_0x5da3c4)[_0xf378('0x24')](function(_0x313bf7){return _0x313bf7;});}return null;};}function removeEntity(_0xbbf17d,_0x2471f2){return function(_0x511ab8){if(_0x511ab8){return _0x511ab8[_0xf378('0x25')]()[_0xf378('0x24')](function(){_0xbbf17d[_0xf378('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x564083,_0x42e112){return function(_0x5b3ad8){if(!_0x5b3ad8){_0x564083['sendStatus'](0x194);}return _0x5b3ad8;};}function handleError(_0x2a2162,_0x955eb7){_0x955eb7=_0x955eb7||0x1f4;return function(_0x3a29b8){logger['error'](_0x3a29b8[_0xf378('0x26')]);if(_0x3a29b8[_0xf378('0x27')]){delete _0x3a29b8[_0xf378('0x27')];}_0x2a2162[_0xf378('0x18')](_0x955eb7)[_0xf378('0x28')](_0x3a29b8);};}exports[_0xf378('0x29')]=function(_0x28b6a6,_0x459678){var _0x3ce58d={},_0x40d6f3={},_0x2d807c={'count':0x0,'rows':[]};var _0x2aecc2=_[_0xf378('0x2a')](db[_0xf378('0x2b')][_0xf378('0x2c')],function(_0x4b4163){return{'name':_0x4b4163['fieldName'],'type':_0x4b4163[_0xf378('0x2d')]['key']};});_0x40d6f3[_0xf378('0x2e')]=_[_0xf378('0x2f')](_['map'](_0x2aecc2,_0xf378('0x27')),[_0xf378('0x27')]);_0x40d6f3[_0xf378('0x30')]=_[_0xf378('0x31')](_0x28b6a6['query']);_0x40d6f3['filters']=_[_0xf378('0x32')](_0x40d6f3[_0xf378('0x2e')],_0x40d6f3[_0xf378('0x30')]);_0x3ce58d[_0xf378('0x33')]=_['intersection'](_0x40d6f3[_0xf378('0x2e')],qs[_0xf378('0x34')](_0x28b6a6['query'][_0xf378('0x34')]));_0x3ce58d[_0xf378('0x33')]=_0x3ce58d['attributes'][_0xf378('0x35')]?_0x3ce58d[_0xf378('0x33')]:_0x40d6f3[_0xf378('0x2e')];if(!_0x28b6a6[_0xf378('0x30')][_0xf378('0x36')](_0xf378('0x37'))){_0x3ce58d['limit']=qs['limit'](_0x28b6a6['query'][_0xf378('0x1c')]);_0x3ce58d['offset']=qs[_0xf378('0x1a')](_0x28b6a6['query']['offset']);}_0x3ce58d[_0xf378('0x38')]=qs['sort'](_0x28b6a6[_0xf378('0x30')][_0xf378('0x39')]);_0x3ce58d[_0xf378('0x3a')]=qs[_0xf378('0x3b')](_[_0xf378('0x3c')](_0x28b6a6[_0xf378('0x30')],_0x40d6f3[_0xf378('0x3b')]),_0x2aecc2);if(_0x28b6a6[_0xf378('0x30')][_0xf378('0x3d')]){_0x3ce58d[_0xf378('0x3a')]=_['merge'](_0x3ce58d[_0xf378('0x3a')],{'$or':_[_0xf378('0x2a')](_0x2aecc2,function(_0x5f55c4){if(_0x5f55c4[_0xf378('0x2d')]!==_0xf378('0x3e')){var _0x229d58={};_0x229d58[_0x5f55c4['name']]={'$like':'%'+_0x28b6a6[_0xf378('0x30')][_0xf378('0x3d')]+'%'};return _0x229d58;}})});}_0x3ce58d=_[_0xf378('0x3f')]({},_0x3ce58d,_0x28b6a6['options']);var _0x33367a={'where':_0x3ce58d['where']};return db[_0xf378('0x2b')][_0xf378('0x1d')](_0x33367a)[_0xf378('0x24')](function(_0x3d3c9c){_0x2d807c[_0xf378('0x1d')]=_0x3d3c9c;if(_0x28b6a6[_0xf378('0x30')][_0xf378('0x40')]){_0x3ce58d['include']=[{'all':!![]}];}return db[_0xf378('0x2b')][_0xf378('0x41')](_0x3ce58d);})[_0xf378('0x24')](function(_0x34aad4){_0x2d807c['rows']=_0x34aad4;return _0x2d807c;})['then'](respondWithFilteredResult(_0x459678,_0x3ce58d))['catch'](handleError(_0x459678,null));};exports[_0xf378('0x42')]=function(_0x1ca7e2,_0x5c3365){var _0x588f2b={'raw':!![],'where':{'id':_0x1ca7e2['params']['id']}},_0x2a3813={};_0x2a3813[_0xf378('0x2e')]=_[_0xf378('0x31')](db[_0xf378('0x2b')][_0xf378('0x2c')]);_0x2a3813['query']=_[_0xf378('0x31')](_0x1ca7e2[_0xf378('0x30')]);_0x2a3813[_0xf378('0x3b')]=_[_0xf378('0x32')](_0x2a3813[_0xf378('0x2e')],_0x2a3813['query']);_0x588f2b[_0xf378('0x33')]=_[_0xf378('0x32')](_0x2a3813[_0xf378('0x2e')],qs[_0xf378('0x34')](_0x1ca7e2[_0xf378('0x30')]['fields']));_0x588f2b[_0xf378('0x33')]=_0x588f2b[_0xf378('0x33')][_0xf378('0x35')]?_0x588f2b[_0xf378('0x33')]:_0x2a3813[_0xf378('0x2e')];if(_0x1ca7e2[_0xf378('0x30')][_0xf378('0x40')]){_0x588f2b['include']=[{'all':!![]}];}_0x588f2b=_[_0xf378('0x3f')]({},_0x588f2b,_0x1ca7e2['options']);return db[_0xf378('0x2b')][_0xf378('0x43')](_0x588f2b)['then'](handleEntityNotFound(_0x5c3365,null))[_0xf378('0x24')](respondWithResult(_0x5c3365,null))[_0xf378('0x44')](handleError(_0x5c3365,null));};exports[_0xf378('0x45')]=function(_0x24f411,_0x1f7428){return db[_0xf378('0x2b')][_0xf378('0x45')](_0x24f411[_0xf378('0x46')],{})[_0xf378('0x24')](respondWithResult(_0x1f7428,0xc9))[_0xf378('0x44')](handleError(_0x1f7428,null));};exports[_0xf378('0x23')]=function(_0x3a5719,_0x5cb467){if(_0x3a5719['body']['id']){delete _0x3a5719[_0xf378('0x46')]['id'];}return db[_0xf378('0x2b')]['find']({'where':{'id':_0x3a5719['params']['id']}})[_0xf378('0x24')](handleEntityNotFound(_0x5cb467,null))[_0xf378('0x24')](saveUpdates(_0x3a5719[_0xf378('0x46')],null))[_0xf378('0x24')](respondWithResult(_0x5cb467,null))[_0xf378('0x44')](handleError(_0x5cb467,null));};exports[_0xf378('0x25')]=function(_0x3d8c2a,_0x3e739e){return db[_0xf378('0x2b')][_0xf378('0x43')]({'where':{'id':_0x3d8c2a[_0xf378('0x47')]['id']}})[_0xf378('0x24')](handleEntityNotFound(_0x3e739e,null))['then'](removeEntity(_0x3e739e,null))[_0xf378('0x44')](handleError(_0x3e739e,null));};exports[_0xf378('0x48')]=function(_0x12173,_0x1a489d,_0x1dc5c7){return db['VoiceMailMessage'][_0xf378('0x43')]({'where':{'id':_0x12173[_0xf378('0x47')]['id']},'attributes':['id',_0xf378('0x49'),'msg_id']})[_0xf378('0x24')](handleEntityNotFound(_0x1a489d,null))[_0xf378('0x24')](function(_0x39e4fc){if(_0x39e4fc){if(!_0x39e4fc[_0xf378('0x49')]){throw new db[(_0xf378('0x4a'))]['ValidationError'](_0xf378('0x4b'));}var _0x4e68f4={'Content-Type':_0xf378('0x4c'),'Content-Disposition':_0xf378('0x4d')};if(_0x39e4fc[_0xf378('0x4e')]){_0x4e68f4[_0xf378('0x4f')]=_0xf378('0x50')+_0x39e4fc[_0xf378('0x4e')]+_0xf378('0x51');}_0x1a489d[_0xf378('0x1e')](_0x4e68f4);return _0x1a489d['send'](new Buffer(_0x39e4fc[_0xf378('0x49')]));}})[_0xf378('0x44')](handleError(_0x1a489d,null));};