42754f80468b29f2fe77cece1808e6a338ddfd74
[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 _0x73f2=['VoiceMailMessage','rawAttributes','fieldName','type','key','differenceBy','query','intersection','model','fields','attributes','hasOwnProperty','nolimit','limit','order','sort','where','pick','filters','merge','includeAll','include','findAll','rows','show','params','keys','length','find','create','catch','body','download','msg_id','ValidationError','VoiceMailMessage\x20not\x20found','attachment','Content-Disposition','attachment;\x20filename=\x22','.wav\x22','set','recording','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','path','to-csv','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','count','offset','Content-Range','reject','update','then','destroy','stack','name','send','index','map'];(function(_0x408528,_0x577d54){var _0x1aa0a4=function(_0x3480d5){while(--_0x3480d5){_0x408528['push'](_0x408528['shift']());}};_0x1aa0a4(++_0x577d54);}(_0x73f2,0x11a));var _0x273f=function(_0x40fea9,_0x489156){_0x40fea9=_0x40fea9-0x0;var _0x5c1355=_0x73f2[_0x40fea9];return _0x5c1355;};'use strict';var pdf=require(_0x273f('0x0'));var emlformat=require(_0x273f('0x1'));var rimraf=require(_0x273f('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x273f('0x3'));var rp=require(_0x273f('0x4'));var moment=require(_0x273f('0x5'));var BPromise=require(_0x273f('0x6'));var Mustache=require(_0x273f('0x7'));var util=require('util');var path=require(_0x273f('0x8'));var sox=require('sox');var csv=require(_0x273f('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x273f('0xa'));var squel=require(_0x273f('0xb'));var crypto=require(_0x273f('0xc'));var jsforce=require(_0x273f('0xd'));var deskjs=require(_0x273f('0xe'));var toCsv=require(_0x273f('0x9'));var querystring=require(_0x273f('0xf'));var Papa=require(_0x273f('0x10'));var Redis=require(_0x273f('0x11'));var authService=require('../../components/auth/service');var qs=require(_0x273f('0x12'));var as=require(_0x273f('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0x273f('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0x273f('0x15'));var db=require(_0x273f('0x16'))['db'];function respondWithStatusCode(_0x2c95c1,_0x5a2f13){_0x5a2f13=_0x5a2f13||0xcc;return function(_0x18be0a){if(_0x18be0a){return _0x2c95c1[_0x273f('0x17')](_0x5a2f13);}return _0x2c95c1[_0x273f('0x18')](_0x5a2f13)[_0x273f('0x19')]();};}function respondWithResult(_0xc21801,_0x12e342){_0x12e342=_0x12e342||0xc8;return function(_0x1c1247){if(_0x1c1247){return _0xc21801[_0x273f('0x18')](_0x12e342)['json'](_0x1c1247);}};}function respondWithFilteredResult(_0x214746,_0x1c2801){return function(_0x19a502){if(_0x19a502){var _0x46031b=_0x19a502[_0x273f('0x1a')],_0x4afe55=_0x1c2801[_0x273f('0x1b')],_0x5a8e11=_0x1c2801[_0x273f('0x1b')]+_0x1c2801['limit'],_0x2ea1ac;if(_0x5a8e11>=_0x46031b){_0x5a8e11=_0x46031b;_0x2ea1ac=0xc8;}else{_0x2ea1ac=0xce;}_0x214746[_0x273f('0x18')](_0x2ea1ac);return _0x214746['set'](_0x273f('0x1c'),_0x4afe55+'-'+_0x5a8e11+'/'+_0x46031b)['json'](_0x19a502);}return null;};}function patchUpdates(_0x4f78ca){return function(_0x3d462c){try{jsonpatch['apply'](_0x3d462c,_0x4f78ca,!![]);}catch(_0x98937){return BPromise[_0x273f('0x1d')](_0x98937);}return _0x3d462c['save']();};}function saveUpdates(_0x1653e5,_0x19a682){return function(_0x4fda3f){if(_0x4fda3f){return _0x4fda3f[_0x273f('0x1e')](_0x1653e5)[_0x273f('0x1f')](function(_0x2f3f77){return _0x2f3f77;});}return null;};}function removeEntity(_0x3b5d90,_0xd169c6){return function(_0x1f8d1e){if(_0x1f8d1e){return _0x1f8d1e[_0x273f('0x20')]()[_0x273f('0x1f')](function(){_0x3b5d90['status'](0xcc)[_0x273f('0x19')]();});}};}function handleEntityNotFound(_0x28e491,_0x1c429c){return function(_0x38cca3){if(!_0x38cca3){_0x28e491['sendStatus'](0x194);}return _0x38cca3;};}function handleError(_0x392c0c,_0xad4a45){_0xad4a45=_0xad4a45||0x1f4;return function(_0xe01135){logger['error'](_0xe01135[_0x273f('0x21')]);if(_0xe01135[_0x273f('0x22')]){delete _0xe01135[_0x273f('0x22')];}_0x392c0c['status'](_0xad4a45)[_0x273f('0x23')](_0xe01135);};}exports[_0x273f('0x24')]=function(_0x4c365a,_0x5f1ba7){var _0xc5aa5b={},_0x393cf3={},_0x4f57e3={'count':0x0,'rows':[]};var _0x38e541=_[_0x273f('0x25')](db[_0x273f('0x26')][_0x273f('0x27')],function(_0x25b3dc){return{'name':_0x25b3dc[_0x273f('0x28')],'type':_0x25b3dc[_0x273f('0x29')][_0x273f('0x2a')]};});_0x393cf3['model']=_[_0x273f('0x2b')](_['map'](_0x38e541,_0x273f('0x22')),[_0x273f('0x22')]);_0x393cf3[_0x273f('0x2c')]=_['keys'](_0x4c365a['query']);_0x393cf3['filters']=_[_0x273f('0x2d')](_0x393cf3[_0x273f('0x2e')],_0x393cf3[_0x273f('0x2c')]);_0xc5aa5b['attributes']=_[_0x273f('0x2d')](_0x393cf3[_0x273f('0x2e')],qs[_0x273f('0x2f')](_0x4c365a[_0x273f('0x2c')][_0x273f('0x2f')]));_0xc5aa5b[_0x273f('0x30')]=_0xc5aa5b['attributes']['length']?_0xc5aa5b['attributes']:_0x393cf3['model'];if(!_0x4c365a[_0x273f('0x2c')][_0x273f('0x31')](_0x273f('0x32'))){_0xc5aa5b[_0x273f('0x33')]=qs[_0x273f('0x33')](_0x4c365a[_0x273f('0x2c')]['limit']);_0xc5aa5b[_0x273f('0x1b')]=qs[_0x273f('0x1b')](_0x4c365a[_0x273f('0x2c')]['offset']);}_0xc5aa5b[_0x273f('0x34')]=qs[_0x273f('0x35')](_0x4c365a[_0x273f('0x2c')][_0x273f('0x35')]);_0xc5aa5b[_0x273f('0x36')]=qs['filters'](_[_0x273f('0x37')](_0x4c365a[_0x273f('0x2c')],_0x393cf3[_0x273f('0x38')]),_0x38e541);if(_0x4c365a[_0x273f('0x2c')]['filter']){_0xc5aa5b[_0x273f('0x36')]=_[_0x273f('0x39')](_0xc5aa5b['where'],{'$or':_[_0x273f('0x25')](_0x38e541,function(_0x188bb1){if(_0x188bb1[_0x273f('0x29')]!=='VIRTUAL'){var _0x1d8d7e={};_0x1d8d7e[_0x188bb1[_0x273f('0x22')]]={'$like':'%'+_0x4c365a['query']['filter']+'%'};return _0x1d8d7e;}})});}_0xc5aa5b=_['merge']({},_0xc5aa5b,_0x4c365a['options']);var _0x55918e={'where':_0xc5aa5b[_0x273f('0x36')]};return db[_0x273f('0x26')][_0x273f('0x1a')](_0x55918e)[_0x273f('0x1f')](function(_0x51e28a){_0x4f57e3[_0x273f('0x1a')]=_0x51e28a;if(_0x4c365a[_0x273f('0x2c')][_0x273f('0x3a')]){_0xc5aa5b[_0x273f('0x3b')]=[{'all':!![]}];}return db[_0x273f('0x26')][_0x273f('0x3c')](_0xc5aa5b);})[_0x273f('0x1f')](function(_0x1b0a6a){_0x4f57e3[_0x273f('0x3d')]=_0x1b0a6a;return _0x4f57e3;})[_0x273f('0x1f')](respondWithFilteredResult(_0x5f1ba7,_0xc5aa5b))['catch'](handleError(_0x5f1ba7,null));};exports[_0x273f('0x3e')]=function(_0x2974c8,_0xd2b3f8){var _0x9d4210={'raw':!![],'where':{'id':_0x2974c8[_0x273f('0x3f')]['id']}},_0x101aa8={};_0x101aa8[_0x273f('0x2e')]=_['keys'](db[_0x273f('0x26')][_0x273f('0x27')]);_0x101aa8[_0x273f('0x2c')]=_[_0x273f('0x40')](_0x2974c8[_0x273f('0x2c')]);_0x101aa8[_0x273f('0x38')]=_['intersection'](_0x101aa8[_0x273f('0x2e')],_0x101aa8[_0x273f('0x2c')]);_0x9d4210['attributes']=_[_0x273f('0x2d')](_0x101aa8[_0x273f('0x2e')],qs['fields'](_0x2974c8[_0x273f('0x2c')][_0x273f('0x2f')]));_0x9d4210['attributes']=_0x9d4210[_0x273f('0x30')][_0x273f('0x41')]?_0x9d4210[_0x273f('0x30')]:_0x101aa8['model'];if(_0x2974c8['query'][_0x273f('0x3a')]){_0x9d4210['include']=[{'all':!![]}];}_0x9d4210=_[_0x273f('0x39')]({},_0x9d4210,_0x2974c8['options']);return db[_0x273f('0x26')][_0x273f('0x42')](_0x9d4210)['then'](handleEntityNotFound(_0xd2b3f8,null))['then'](respondWithResult(_0xd2b3f8,null))['catch'](handleError(_0xd2b3f8,null));};exports[_0x273f('0x43')]=function(_0x5adda1,_0x8dcf65){return db[_0x273f('0x26')]['create'](_0x5adda1['body'],{})['then'](respondWithResult(_0x8dcf65,0xc9))[_0x273f('0x44')](handleError(_0x8dcf65,null));};exports['update']=function(_0x51e27c,_0x35d371){if(_0x51e27c[_0x273f('0x45')]['id']){delete _0x51e27c[_0x273f('0x45')]['id'];}return db[_0x273f('0x26')][_0x273f('0x42')]({'where':{'id':_0x51e27c[_0x273f('0x3f')]['id']}})[_0x273f('0x1f')](handleEntityNotFound(_0x35d371,null))['then'](saveUpdates(_0x51e27c[_0x273f('0x45')],null))[_0x273f('0x1f')](respondWithResult(_0x35d371,null))[_0x273f('0x44')](handleError(_0x35d371,null));};exports[_0x273f('0x20')]=function(_0x8ec93,_0x29191f){return db['VoiceMailMessage'][_0x273f('0x42')]({'where':{'id':_0x8ec93[_0x273f('0x3f')]['id']}})[_0x273f('0x1f')](handleEntityNotFound(_0x29191f,null))[_0x273f('0x1f')](removeEntity(_0x29191f,null))[_0x273f('0x44')](handleError(_0x29191f,null));};exports[_0x273f('0x46')]=function(_0x2b18de,_0x58545c,_0x3ded19){return db['VoiceMailMessage']['find']({'where':{'id':_0x2b18de[_0x273f('0x3f')]['id']},'attributes':['id','recording',_0x273f('0x47')]})[_0x273f('0x1f')](handleEntityNotFound(_0x58545c,null))['then'](function(_0x2fdeb8){if(_0x2fdeb8){if(!_0x2fdeb8['recording']){throw new db['Sequelize'][(_0x273f('0x48'))](_0x273f('0x49'));}var _0x50176f={'Content-Type':'audio/wav','Content-Disposition':_0x273f('0x4a')};if(_0x2fdeb8[_0x273f('0x47')]){_0x50176f[_0x273f('0x4b')]=_0x273f('0x4c')+_0x2fdeb8[_0x273f('0x47')]+_0x273f('0x4d');}_0x58545c[_0x273f('0x4e')](_0x50176f);return _0x58545c[_0x273f('0x23')](new Buffer(_0x2fdeb8[_0x273f('0x4f')]));}})['catch'](handleError(_0x58545c,null));};