07f6ffefa9a0724b427d43a54449543106313161
[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 _0xf260=['crypto','jsforce','desk.js','querystring','ioredis','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','Content-Range','apply','reject','update','then','destroy','end','stack','name','index','map','rawAttributes','fieldName','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','merge','type','VIRTUAL','filter','options','includeAll','include','findAll','catch','show','keys','VoiceMailMessage','find','create','body','params','recording','Sequelize','ValidationError','VoiceMailMessage\x20not\x20found','audio/wav','attachment','msg_id','Content-Disposition','attachment;\x20filename=\x22','set','send','eml-format','fast-json-patch','request-promise','bluebird','mustache','path','sox','to-csv','ejs','fs-extra'];(function(_0x2e63e8,_0xed68f5){var _0x3fe904=function(_0x10e876){while(--_0x10e876){_0x2e63e8['push'](_0x2e63e8['shift']());}};_0x3fe904(++_0xed68f5);}(_0xf260,0xe6));var _0x0f26=function(_0x580d0e,_0x1e5f43){_0x580d0e=_0x580d0e-0x0;var _0xb51111=_0xf260[_0x580d0e];return _0xb51111;};'use strict';var emlformat=require(_0x0f26('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x0f26('0x1'));var rp=require(_0x0f26('0x2'));var moment=require('moment');var BPromise=require(_0x0f26('0x3'));var Mustache=require(_0x0f26('0x4'));var util=require('util');var path=require(_0x0f26('0x5'));var sox=require(_0x0f26('0x6'));var csv=require(_0x0f26('0x7'));var ejs=require(_0x0f26('0x8'));var fs=require('fs');var fs_extra=require(_0x0f26('0x9'));var _=require('lodash');var squel=require('squel');var crypto=require(_0x0f26('0xa'));var jsforce=require(_0x0f26('0xb'));var deskjs=require(_0x0f26('0xc'));var toCsv=require(_0x0f26('0x7'));var querystring=require(_0x0f26('0xd'));var Papa=require('papaparse');var Redis=require(_0x0f26('0xe'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x0f26('0xf'));var logger=require(_0x0f26('0x10'))(_0x0f26('0x11'));var utils=require(_0x0f26('0x12'));var config=require('../../config/environment');var licenseUtil=require(_0x0f26('0x13'));var db=require(_0x0f26('0x14'))['db'];function respondWithStatusCode(_0x49444b,_0x110e49){_0x110e49=_0x110e49||0xcc;return function(_0x5257e7){if(_0x5257e7){return _0x49444b[_0x0f26('0x15')](_0x110e49);}return _0x49444b[_0x0f26('0x16')](_0x110e49)['end']();};}function respondWithResult(_0x53290e,_0x2ca234){_0x2ca234=_0x2ca234||0xc8;return function(_0x177152){if(_0x177152){return _0x53290e[_0x0f26('0x16')](_0x2ca234)[_0x0f26('0x17')](_0x177152);}};}function respondWithFilteredResult(_0x168c40,_0x43f084){return function(_0xa1cad4){if(_0xa1cad4){var _0x4bd4bb=typeof _0x43f084[_0x0f26('0x18')]===_0x0f26('0x19')&&typeof _0x43f084[_0x0f26('0x1a')]==='undefined';var _0x4fbfd5=_0xa1cad4[_0x0f26('0x1b')];var _0xdc8080=_0x4bd4bb?0x0:_0x43f084[_0x0f26('0x18')];var _0xe5e5cc=_0x4bd4bb?_0xa1cad4[_0x0f26('0x1b')]:_0x43f084['offset']+_0x43f084[_0x0f26('0x1a')];var _0x56bf3b;if(_0xe5e5cc>=_0x4fbfd5){_0xe5e5cc=_0x4fbfd5;_0x56bf3b=0xc8;}else{_0x56bf3b=0xce;}_0x168c40['status'](_0x56bf3b);return _0x168c40['set'](_0x0f26('0x1c'),_0xdc8080+'-'+_0xe5e5cc+'/'+_0x4fbfd5)[_0x0f26('0x17')](_0xa1cad4);}return null;};}function patchUpdates(_0x2b2270){return function(_0x1f1631){try{jsonpatch[_0x0f26('0x1d')](_0x1f1631,_0x2b2270,!![]);}catch(_0x331497){return BPromise[_0x0f26('0x1e')](_0x331497);}return _0x1f1631['save']();};}function saveUpdates(_0x4ae128,_0x13ea3f){return function(_0x3962ab){if(_0x3962ab){return _0x3962ab[_0x0f26('0x1f')](_0x4ae128)[_0x0f26('0x20')](function(_0x4967f7){return _0x4967f7;});}return null;};}function removeEntity(_0x4ff55d,_0x2c7b57){return function(_0x305829){if(_0x305829){return _0x305829[_0x0f26('0x21')]()[_0x0f26('0x20')](function(){_0x4ff55d[_0x0f26('0x16')](0xcc)[_0x0f26('0x22')]();});}};}function handleEntityNotFound(_0x28b5ba,_0x1d4ecc){return function(_0x2db1ed){if(!_0x2db1ed){_0x28b5ba[_0x0f26('0x15')](0x194);}return _0x2db1ed;};}function handleError(_0x32b241,_0x2646b1){_0x2646b1=_0x2646b1||0x1f4;return function(_0x53ae62){logger['error'](_0x53ae62[_0x0f26('0x23')]);if(_0x53ae62[_0x0f26('0x24')]){delete _0x53ae62['name'];}_0x32b241[_0x0f26('0x16')](_0x2646b1)['send'](_0x53ae62);};}exports[_0x0f26('0x25')]=function(_0x2b4e6c,_0x59208e){var _0x4af8de={},_0x34450b={},_0x372e15={'count':0x0,'rows':[]};var _0x35b703=_[_0x0f26('0x26')](db['VoiceMailMessage'][_0x0f26('0x27')],function(_0x2749a4){return{'name':_0x2749a4[_0x0f26('0x28')],'type':_0x2749a4['type']['key']};});_0x34450b[_0x0f26('0x29')]=_['differenceBy'](_[_0x0f26('0x26')](_0x35b703,_0x0f26('0x24')),[_0x0f26('0x24')]);_0x34450b[_0x0f26('0x2a')]=_['keys'](_0x2b4e6c['query']);_0x34450b[_0x0f26('0x2b')]=_[_0x0f26('0x2c')](_0x34450b[_0x0f26('0x29')],_0x34450b[_0x0f26('0x2a')]);_0x4af8de[_0x0f26('0x2d')]=_[_0x0f26('0x2c')](_0x34450b[_0x0f26('0x29')],qs['fields'](_0x2b4e6c['query'][_0x0f26('0x2e')]));_0x4af8de[_0x0f26('0x2d')]=_0x4af8de[_0x0f26('0x2d')][_0x0f26('0x2f')]?_0x4af8de[_0x0f26('0x2d')]:_0x34450b['model'];if(!_0x2b4e6c['query'][_0x0f26('0x30')](_0x0f26('0x31'))){_0x4af8de[_0x0f26('0x1a')]=qs[_0x0f26('0x1a')](_0x2b4e6c[_0x0f26('0x2a')][_0x0f26('0x1a')]);_0x4af8de[_0x0f26('0x18')]=qs['offset'](_0x2b4e6c[_0x0f26('0x2a')][_0x0f26('0x18')]);}_0x4af8de[_0x0f26('0x32')]=qs[_0x0f26('0x33')](_0x2b4e6c[_0x0f26('0x2a')][_0x0f26('0x33')]);_0x4af8de[_0x0f26('0x34')]=qs[_0x0f26('0x2b')](_['pick'](_0x2b4e6c[_0x0f26('0x2a')],_0x34450b[_0x0f26('0x2b')]),_0x35b703);if(_0x2b4e6c[_0x0f26('0x2a')]['filter']){_0x4af8de[_0x0f26('0x34')]=_[_0x0f26('0x35')](_0x4af8de[_0x0f26('0x34')],{'$or':_[_0x0f26('0x26')](_0x35b703,function(_0x1c77af){if(_0x1c77af[_0x0f26('0x36')]!==_0x0f26('0x37')){var _0x58cdad={};_0x58cdad[_0x1c77af['name']]={'$like':'%'+_0x2b4e6c['query'][_0x0f26('0x38')]+'%'};return _0x58cdad;}})});}_0x4af8de=_['merge']({},_0x4af8de,_0x2b4e6c[_0x0f26('0x39')]);var _0x1f61cd={'where':_0x4af8de['where']};return db['VoiceMailMessage'][_0x0f26('0x1b')](_0x1f61cd)['then'](function(_0x5a0b26){_0x372e15[_0x0f26('0x1b')]=_0x5a0b26;if(_0x2b4e6c[_0x0f26('0x2a')][_0x0f26('0x3a')]){_0x4af8de[_0x0f26('0x3b')]=[{'all':!![]}];}return db['VoiceMailMessage'][_0x0f26('0x3c')](_0x4af8de);})[_0x0f26('0x20')](function(_0x1c470f){_0x372e15['rows']=_0x1c470f;return _0x372e15;})[_0x0f26('0x20')](respondWithFilteredResult(_0x59208e,_0x4af8de))[_0x0f26('0x3d')](handleError(_0x59208e,null));};exports[_0x0f26('0x3e')]=function(_0x1c4b6f,_0x53469c){var _0x70ffbd={'raw':!![],'where':{'id':_0x1c4b6f['params']['id']}},_0xe17e76={};_0xe17e76[_0x0f26('0x29')]=_[_0x0f26('0x3f')](db[_0x0f26('0x40')]['rawAttributes']);_0xe17e76[_0x0f26('0x2a')]=_[_0x0f26('0x3f')](_0x1c4b6f[_0x0f26('0x2a')]);_0xe17e76[_0x0f26('0x2b')]=_[_0x0f26('0x2c')](_0xe17e76[_0x0f26('0x29')],_0xe17e76[_0x0f26('0x2a')]);_0x70ffbd['attributes']=_[_0x0f26('0x2c')](_0xe17e76['model'],qs['fields'](_0x1c4b6f[_0x0f26('0x2a')][_0x0f26('0x2e')]));_0x70ffbd[_0x0f26('0x2d')]=_0x70ffbd[_0x0f26('0x2d')]['length']?_0x70ffbd[_0x0f26('0x2d')]:_0xe17e76['model'];if(_0x1c4b6f[_0x0f26('0x2a')][_0x0f26('0x3a')]){_0x70ffbd[_0x0f26('0x3b')]=[{'all':!![]}];}_0x70ffbd=_[_0x0f26('0x35')]({},_0x70ffbd,_0x1c4b6f[_0x0f26('0x39')]);return db[_0x0f26('0x40')][_0x0f26('0x41')](_0x70ffbd)[_0x0f26('0x20')](handleEntityNotFound(_0x53469c,null))[_0x0f26('0x20')](respondWithResult(_0x53469c,null))[_0x0f26('0x3d')](handleError(_0x53469c,null));};exports[_0x0f26('0x42')]=function(_0x1b3666,_0x5e91ec){return db[_0x0f26('0x40')][_0x0f26('0x42')](_0x1b3666[_0x0f26('0x43')],{})[_0x0f26('0x20')](respondWithResult(_0x5e91ec,0xc9))[_0x0f26('0x3d')](handleError(_0x5e91ec,null));};exports[_0x0f26('0x1f')]=function(_0x734ac1,_0x2962cf){if(_0x734ac1[_0x0f26('0x43')]['id']){delete _0x734ac1[_0x0f26('0x43')]['id'];}return db[_0x0f26('0x40')][_0x0f26('0x41')]({'where':{'id':_0x734ac1['params']['id']}})[_0x0f26('0x20')](handleEntityNotFound(_0x2962cf,null))['then'](saveUpdates(_0x734ac1[_0x0f26('0x43')],null))[_0x0f26('0x20')](respondWithResult(_0x2962cf,null))[_0x0f26('0x3d')](handleError(_0x2962cf,null));};exports[_0x0f26('0x21')]=function(_0x5ba5e4,_0x3cc88d){return db[_0x0f26('0x40')][_0x0f26('0x41')]({'where':{'id':_0x5ba5e4[_0x0f26('0x44')]['id']}})[_0x0f26('0x20')](handleEntityNotFound(_0x3cc88d,null))[_0x0f26('0x20')](removeEntity(_0x3cc88d,null))['catch'](handleError(_0x3cc88d,null));};exports['download']=function(_0x4bfaf6,_0x3083c4,_0x259639){return db[_0x0f26('0x40')][_0x0f26('0x41')]({'where':{'id':_0x4bfaf6['params']['id']},'attributes':['id',_0x0f26('0x45'),'msg_id']})[_0x0f26('0x20')](handleEntityNotFound(_0x3083c4,null))['then'](function(_0x5effb7){if(_0x5effb7){if(!_0x5effb7[_0x0f26('0x45')]){throw new db[(_0x0f26('0x46'))][(_0x0f26('0x47'))](_0x0f26('0x48'));}var _0xd80cf8={'Content-Type':_0x0f26('0x49'),'Content-Disposition':_0x0f26('0x4a')};if(_0x5effb7[_0x0f26('0x4b')]){_0xd80cf8[_0x0f26('0x4c')]=_0x0f26('0x4d')+_0x5effb7[_0x0f26('0x4b')]+'.wav\x22';}_0x3083c4[_0x0f26('0x4e')](_0xd80cf8);return _0x3083c4[_0x0f26('0x4f')](new Buffer(_0x5effb7[_0x0f26('0x45')]));}})[_0x0f26('0x3d')](handleError(_0x3083c4,null));};