Built motion from commit (unavailable).|2.5.11
[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 _0x6acb=['ejs','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','count','offset','set','Content-Range','reject','update','then','error','stack','name','send','map','VoiceMailMessage','rawAttributes','fieldName','key','model','differenceBy','keys','query','filters','intersection','attributes','fields','length','nolimit','limit','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','findAll','rows','catch','params','include','find','create','body','destroy','download','recording','msg_id','Sequelize','audio/wav','attachment;\x20filename=\x22','.wav\x22','rimraf','zip-dir','fast-json-patch','request-promise','mustache','path','to-csv'];(function(_0x4496c1,_0x103294){var _0xa2da11=function(_0x22d096){while(--_0x22d096){_0x4496c1['push'](_0x4496c1['shift']());}};_0xa2da11(++_0x103294);}(_0x6acb,0xe0));var _0xb6ac=function(_0x41382c,_0xc3ffd1){_0x41382c=_0x41382c-0x0;var _0x4da35b=_0x6acb[_0x41382c];return _0x4da35b;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0xb6ac('0x0'));var zipdir=require(_0xb6ac('0x1'));var jsonpatch=require(_0xb6ac('0x2'));var rp=require(_0xb6ac('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xb6ac('0x4'));var util=require('util');var path=require(_0xb6ac('0x5'));var sox=require('sox');var csv=require(_0xb6ac('0x6'));var ejs=require(_0xb6ac('0x7'));var fs=require('fs');var _=require('lodash');var squel=require(_0xb6ac('0x8'));var crypto=require('crypto');var jsforce=require(_0xb6ac('0x9'));var deskjs=require(_0xb6ac('0xa'));var toCsv=require(_0xb6ac('0x6'));var querystring=require(_0xb6ac('0xb'));var Papa=require(_0xb6ac('0xc'));var Redis=require(_0xb6ac('0xd'));var authService=require(_0xb6ac('0xe'));var qs=require(_0xb6ac('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xb6ac('0x10'));var logger=require(_0xb6ac('0x11'))(_0xb6ac('0x12'));var utils=require(_0xb6ac('0x13'));var config=require(_0xb6ac('0x14'));var licenseUtil=require('../../config/license/util');var db=require(_0xb6ac('0x15'))['db'];function respondWithStatusCode(_0x355da9,_0x80082d){_0x80082d=_0x80082d||0xcc;return function(_0x607a7a){if(_0x607a7a){return _0x355da9[_0xb6ac('0x16')](_0x80082d);}return _0x355da9[_0xb6ac('0x17')](_0x80082d)[_0xb6ac('0x18')]();};}function respondWithResult(_0x52fae3,_0x94b7a9){_0x94b7a9=_0x94b7a9||0xc8;return function(_0x295d22){if(_0x295d22){return _0x52fae3[_0xb6ac('0x17')](_0x94b7a9)[_0xb6ac('0x19')](_0x295d22);}};}function respondWithFilteredResult(_0x5cd32b,_0x3deebf){return function(_0x5255f8){if(_0x5255f8){var _0x52879c=_0x5255f8[_0xb6ac('0x1a')],_0x2b19fc=_0x3deebf[_0xb6ac('0x1b')],_0x5b0631=_0x3deebf[_0xb6ac('0x1b')]+_0x3deebf['limit'],_0x5d1df3;if(_0x5b0631>=_0x52879c){_0x5b0631=_0x52879c;_0x5d1df3=0xc8;}else{_0x5d1df3=0xce;}_0x5cd32b[_0xb6ac('0x17')](_0x5d1df3);return _0x5cd32b[_0xb6ac('0x1c')](_0xb6ac('0x1d'),_0x2b19fc+'-'+_0x5b0631+'/'+_0x52879c)[_0xb6ac('0x19')](_0x5255f8);}return null;};}function patchUpdates(_0x3941c7){return function(_0x202db0){try{jsonpatch['apply'](_0x202db0,_0x3941c7,!![]);}catch(_0x376fcb){return BPromise[_0xb6ac('0x1e')](_0x376fcb);}return _0x202db0['save']();};}function saveUpdates(_0x484b22,_0x414714){return function(_0x4b3124){if(_0x4b3124){return _0x4b3124[_0xb6ac('0x1f')](_0x484b22)['then'](function(_0x5e2bc5){return _0x5e2bc5;});}return null;};}function removeEntity(_0x5eca1e,_0x56195b){return function(_0x31aafc){if(_0x31aafc){return _0x31aafc['destroy']()[_0xb6ac('0x20')](function(){_0x5eca1e[_0xb6ac('0x17')](0xcc)['end']();});}};}function handleEntityNotFound(_0x10458d,_0x5761f4){return function(_0x9fe3b8){if(!_0x9fe3b8){_0x10458d[_0xb6ac('0x16')](0x194);}return _0x9fe3b8;};}function handleError(_0x53fa7d,_0x229931){_0x229931=_0x229931||0x1f4;return function(_0x2ee9cb){logger[_0xb6ac('0x21')](_0x2ee9cb[_0xb6ac('0x22')]);if(_0x2ee9cb[_0xb6ac('0x23')]){delete _0x2ee9cb[_0xb6ac('0x23')];}_0x53fa7d[_0xb6ac('0x17')](_0x229931)[_0xb6ac('0x24')](_0x2ee9cb);};}exports['index']=function(_0x28dc9a,_0x2e7adc){var _0x462c70={},_0x3285bd={},_0x38730d={'count':0x0,'rows':[]};var _0x2c8ada=_[_0xb6ac('0x25')](db[_0xb6ac('0x26')][_0xb6ac('0x27')],function(_0x5f1da3){return{'name':_0x5f1da3[_0xb6ac('0x28')],'type':_0x5f1da3['type'][_0xb6ac('0x29')]};});_0x3285bd[_0xb6ac('0x2a')]=_[_0xb6ac('0x2b')](_[_0xb6ac('0x25')](_0x2c8ada,_0xb6ac('0x23')),[_0xb6ac('0x23')]);_0x3285bd['query']=_[_0xb6ac('0x2c')](_0x28dc9a[_0xb6ac('0x2d')]);_0x3285bd[_0xb6ac('0x2e')]=_[_0xb6ac('0x2f')](_0x3285bd[_0xb6ac('0x2a')],_0x3285bd[_0xb6ac('0x2d')]);_0x462c70[_0xb6ac('0x30')]=_[_0xb6ac('0x2f')](_0x3285bd[_0xb6ac('0x2a')],qs[_0xb6ac('0x31')](_0x28dc9a[_0xb6ac('0x2d')]['fields']));_0x462c70[_0xb6ac('0x30')]=_0x462c70[_0xb6ac('0x30')][_0xb6ac('0x32')]?_0x462c70[_0xb6ac('0x30')]:_0x3285bd['model'];if(!_0x28dc9a[_0xb6ac('0x2d')]['hasOwnProperty'](_0xb6ac('0x33'))){_0x462c70[_0xb6ac('0x34')]=qs[_0xb6ac('0x34')](_0x28dc9a[_0xb6ac('0x2d')]['limit']);_0x462c70['offset']=qs['offset'](_0x28dc9a[_0xb6ac('0x2d')]['offset']);}_0x462c70['order']=qs[_0xb6ac('0x35')](_0x28dc9a[_0xb6ac('0x2d')][_0xb6ac('0x35')]);_0x462c70[_0xb6ac('0x36')]=qs[_0xb6ac('0x2e')](_[_0xb6ac('0x37')](_0x28dc9a[_0xb6ac('0x2d')],_0x3285bd[_0xb6ac('0x2e')]),_0x2c8ada);if(_0x28dc9a[_0xb6ac('0x2d')][_0xb6ac('0x38')]){_0x462c70['where']=_[_0xb6ac('0x39')](_0x462c70['where'],{'$or':_['map'](_0x2c8ada,function(_0x17c977){if(_0x17c977['type']!==_0xb6ac('0x3a')){var _0x2e5e37={};_0x2e5e37[_0x17c977['name']]={'$like':'%'+_0x28dc9a[_0xb6ac('0x2d')][_0xb6ac('0x38')]+'%'};return _0x2e5e37;}})});}_0x462c70=_[_0xb6ac('0x39')]({},_0x462c70,_0x28dc9a[_0xb6ac('0x3b')]);var _0x2a0f1f={'where':_0x462c70[_0xb6ac('0x36')]};return db[_0xb6ac('0x26')]['count'](_0x2a0f1f)[_0xb6ac('0x20')](function(_0x50a113){_0x38730d[_0xb6ac('0x1a')]=_0x50a113;if(_0x28dc9a['query'][_0xb6ac('0x3c')]){_0x462c70['include']=[{'all':!![]}];}return db['VoiceMailMessage'][_0xb6ac('0x3d')](_0x462c70);})[_0xb6ac('0x20')](function(_0x3345ba){_0x38730d[_0xb6ac('0x3e')]=_0x3345ba;return _0x38730d;})[_0xb6ac('0x20')](respondWithFilteredResult(_0x2e7adc,_0x462c70))[_0xb6ac('0x3f')](handleError(_0x2e7adc,null));};exports['show']=function(_0x471521,_0x3dfd41){var _0x28084f={'raw':!![],'where':{'id':_0x471521[_0xb6ac('0x40')]['id']}},_0x3c1fd3={};_0x3c1fd3[_0xb6ac('0x2a')]=_['keys'](db[_0xb6ac('0x26')]['rawAttributes']);_0x3c1fd3[_0xb6ac('0x2d')]=_[_0xb6ac('0x2c')](_0x471521[_0xb6ac('0x2d')]);_0x3c1fd3['filters']=_[_0xb6ac('0x2f')](_0x3c1fd3[_0xb6ac('0x2a')],_0x3c1fd3[_0xb6ac('0x2d')]);_0x28084f['attributes']=_[_0xb6ac('0x2f')](_0x3c1fd3[_0xb6ac('0x2a')],qs[_0xb6ac('0x31')](_0x471521['query'][_0xb6ac('0x31')]));_0x28084f[_0xb6ac('0x30')]=_0x28084f['attributes'][_0xb6ac('0x32')]?_0x28084f[_0xb6ac('0x30')]:_0x3c1fd3[_0xb6ac('0x2a')];if(_0x471521['query'][_0xb6ac('0x3c')]){_0x28084f[_0xb6ac('0x41')]=[{'all':!![]}];}_0x28084f=_[_0xb6ac('0x39')]({},_0x28084f,_0x471521['options']);return db[_0xb6ac('0x26')][_0xb6ac('0x42')](_0x28084f)['then'](handleEntityNotFound(_0x3dfd41,null))['then'](respondWithResult(_0x3dfd41,null))[_0xb6ac('0x3f')](handleError(_0x3dfd41,null));};exports['create']=function(_0x2bf54e,_0x4df7bf){return db[_0xb6ac('0x26')][_0xb6ac('0x43')](_0x2bf54e['body'],{})[_0xb6ac('0x20')](respondWithResult(_0x4df7bf,0xc9))[_0xb6ac('0x3f')](handleError(_0x4df7bf,null));};exports[_0xb6ac('0x1f')]=function(_0x2328ff,_0x127b3e){if(_0x2328ff[_0xb6ac('0x44')]['id']){delete _0x2328ff[_0xb6ac('0x44')]['id'];}return db[_0xb6ac('0x26')][_0xb6ac('0x42')]({'where':{'id':_0x2328ff[_0xb6ac('0x40')]['id']}})[_0xb6ac('0x20')](handleEntityNotFound(_0x127b3e,null))['then'](saveUpdates(_0x2328ff['body'],null))[_0xb6ac('0x20')](respondWithResult(_0x127b3e,null))[_0xb6ac('0x3f')](handleError(_0x127b3e,null));};exports[_0xb6ac('0x45')]=function(_0x37e47b,_0x4ee024){return db[_0xb6ac('0x26')]['find']({'where':{'id':_0x37e47b[_0xb6ac('0x40')]['id']}})['then'](handleEntityNotFound(_0x4ee024,null))[_0xb6ac('0x20')](removeEntity(_0x4ee024,null))[_0xb6ac('0x3f')](handleError(_0x4ee024,null));};exports[_0xb6ac('0x46')]=function(_0x3e0d28,_0x14c4af,_0x47d7ac){return db[_0xb6ac('0x26')]['find']({'where':{'id':_0x3e0d28[_0xb6ac('0x40')]['id']},'attributes':['id',_0xb6ac('0x47'),_0xb6ac('0x48')]})[_0xb6ac('0x20')](handleEntityNotFound(_0x14c4af,null))[_0xb6ac('0x20')](function(_0x58c992){if(_0x58c992){if(!_0x58c992[_0xb6ac('0x47')]){throw new db[(_0xb6ac('0x49'))]['ValidationError']('VoiceMailMessage\x20not\x20found');}var _0x4b32c5={'Content-Type':_0xb6ac('0x4a'),'Content-Disposition':'attachment'};if(_0x58c992['msg_id']){_0x4b32c5['Content-Disposition']=_0xb6ac('0x4b')+_0x58c992[_0xb6ac('0x48')]+_0xb6ac('0x4c');}_0x14c4af['set'](_0x4b32c5);return _0x14c4af[_0xb6ac('0x24')](new Buffer(_0x58c992[_0xb6ac('0x47')]));}})[_0xb6ac('0x3f')](handleError(_0x14c4af,null));};