21e9bc5222bc581a0bd3a5585ba4f1880c829a56
[motion-next.git] / server / api / analyticExtractedReport / analyticExtractedReport.controller.js
1 const a13_0x45ca=['pick','destroy','findAll','exists','stack','show','length','params','nolimit','include','rawAttributes','UserProfileSection','fields','model','filters','keys','../../mysqldb','join','includeAll','userProfileId','basename','update','api','json','merge','UserProfileResource','then','create','output','savename','type','path','util','rows','end','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','AnalyticExtractedReport','sort','role','user','attributes','VIRTUAL','limit','get','map','Report\x20not\x20found\x20or\x20empty','undefined','Content-Range','catch','like','where','offset','intersection','toLowerCase','options','query','body','name','../../config/environment','error','fieldName','status','ExtractedReports','root','autoAssociation','download','../../components/parsers/qs','sendStatus','sequelize','findOne','%s.%s','files/reports'];(function(_0x3839b0,_0x45ca1a){const _0x25ab96=function(_0x4f56e8){while(--_0x4f56e8){_0x3839b0['push'](_0x3839b0['shift']());}};_0x25ab96(++_0x45ca1a);}(a13_0x45ca,0x1f3));const a13_0x25ab=function(_0x3839b0,_0x45ca1a){_0x3839b0=_0x3839b0-0x0;let _0x25ab96=a13_0x45ca[_0x3839b0];return _0x25ab96;};const _0x531bf1=a13_0x25ab;'use strict';const util=require(_0x531bf1('0x25')),path=require(_0x531bf1('0x24')),fs=require('fs'),_=require('lodash'),qs=require(_0x531bf1('0x47')),logger=require('../../config/logger')(_0x531bf1('0x1b')),config=require(_0x531bf1('0x3f')),db=require(_0x531bf1('0x15'))['db'],{Op,ValidationError}=require(_0x531bf1('0x1'));function respondWithResult(_0x4f56e8,_0x2ef658){return _0x2ef658=_0x2ef658||0xc8,function(_0x4d906c){const _0x5e71b0=a13_0x25ab;if(_0x4d906c)return _0x4f56e8[_0x5e71b0('0x42')](_0x2ef658)['json'](_0x4d906c);};}function respondWithFilteredResult(_0x41335d,_0xf7a0ab){return function(_0x5b4cd3){const _0x2fab84=a13_0x25ab;if(_0x5b4cd3){const _0x72e3a8=_0x5b4cd3['count'],_0x5da2de=_0xf7a0ab[_0x2fab84('0x38')];let _0x46ceb2=_0xf7a0ab['offset']+_0xf7a0ab[_0x2fab84('0x2f')],_0x32ef41;return _0x46ceb2>=_0x72e3a8?(_0x46ceb2=_0x72e3a8,_0x32ef41=0xc8):_0x32ef41=0xce,_0x41335d[_0x2fab84('0x42')](_0x32ef41),_0x41335d['set'](_0x2fab84('0x34'),_0x5da2de+'-'+_0x46ceb2+'/'+_0x72e3a8)[_0x2fab84('0x1c')](_0x5b4cd3);}return null;};}function saveUpdates(_0x3680d9){return function(_0x63ce3){const _0x2d72a9=a13_0x25ab;if(_0x63ce3)return _0x63ce3[_0x2d72a9('0x1a')](_0x3680d9)['then'](function(_0x1de535){return _0x1de535;});return null;};}function removeEntity(_0x507c82){return function(_0x464a01){const _0x15cea0=a13_0x25ab;if(_0x464a01)return _0x464a01[_0x15cea0('0x6')]()[_0x15cea0('0x1f')](function(){const _0x4ed335=_0x15cea0,_0x3fcb58=_0x464a01[_0x4ed335('0x30')]({'plain':!![]}),_0x2555fd=_0x4ed335('0x43');return db[_0x4ed335('0x1e')][_0x4ed335('0x6')]({'where':{'type':_0x2555fd,'resourceId':_0x3fcb58['id']}})[_0x4ed335('0x1f')](function(){return _0x464a01;});})[_0x15cea0('0x1f')](function(){const _0x45cb39=_0x15cea0;_0x507c82[_0x45cb39('0x42')](0xcc)[_0x45cb39('0x27')]();});};}function handleEntityNotFound(_0x35d3be){return function(_0x2b042e){const _0x29d818=a13_0x25ab;return!_0x2b042e&&_0x35d3be[_0x29d818('0x0')](0x194),_0x2b042e;};}function handleError(_0x4e06e1,_0x2629e5){return _0x2629e5=_0x2629e5||0x1f4,function(_0x4cd721){const _0x17f23a=a13_0x25ab;logger[_0x17f23a('0x40')](_0x4cd721[_0x17f23a('0x9')]),_0x4cd721[_0x17f23a('0x3e')]&&delete _0x4cd721['name'],_0x4e06e1[_0x17f23a('0x42')](_0x2629e5)['send'](_0x4cd721);};}exports['index']=function(_0x43c9f4,_0x323f5f){const _0x2d8205=_0x531bf1;let _0x52f433={};const _0x33f8b5={},_0x27d090={'count':0x0,'rows':[]},_0x3b656d=_[_0x2d8205('0x31')](db['AnalyticExtractedReport'][_0x2d8205('0xf')],function(_0x39df3c){const _0x291bbb=_0x2d8205;return{'name':_0x39df3c[_0x291bbb('0x41')],'type':_0x39df3c[_0x291bbb('0x23')]['key']};});_0x33f8b5['model']=_[_0x2d8205('0x31')](_0x3b656d,_0x2d8205('0x3e')),_0x33f8b5[_0x2d8205('0x3c')]=_[_0x2d8205('0x14')](_0x43c9f4[_0x2d8205('0x3c')]),_0x33f8b5[_0x2d8205('0x13')]=_['intersection'](_0x33f8b5[_0x2d8205('0x12')],_0x33f8b5['query']),_0x52f433['attributes']=_['intersection'](_0x33f8b5['model'],qs[_0x2d8205('0x11')](_0x43c9f4[_0x2d8205('0x3c')]['fields'])),_0x52f433[_0x2d8205('0x2d')]=_0x52f433[_0x2d8205('0x2d')][_0x2d8205('0xb')]?_0x52f433[_0x2d8205('0x2d')]:_0x33f8b5['model'];typeof _0x43c9f4['query'][_0x2d8205('0xd')]===_0x2d8205('0x33')&&(_0x52f433[_0x2d8205('0x2f')]=qs[_0x2d8205('0x2f')](_0x43c9f4['query'][_0x2d8205('0x2f')]),_0x52f433[_0x2d8205('0x38')]=qs[_0x2d8205('0x38')](_0x43c9f4[_0x2d8205('0x3c')][_0x2d8205('0x38')]));_0x52f433['order']=qs['sort'](_0x43c9f4[_0x2d8205('0x3c')][_0x2d8205('0x2a')]),_0x52f433[_0x2d8205('0x37')]=qs[_0x2d8205('0x13')](_[_0x2d8205('0x5')](_0x43c9f4[_0x2d8205('0x3c')],_0x33f8b5['filters']),_0x3b656d);_0x43c9f4[_0x2d8205('0x3c')]['filter']&&(_0x52f433['where']=_['merge'](_0x52f433['where'],{[Op['or']]:_[_0x2d8205('0x31')](_0x3b656d,function(_0x3ec642){const _0x1c9b14=_0x2d8205;if(_0x3ec642[_0x1c9b14('0x23')]!==_0x1c9b14('0x2e')){const _0x3d22c4={};return _0x3d22c4[_0x3ec642['name']]={[Op[_0x1c9b14('0x36')]]:'%'+_0x43c9f4[_0x1c9b14('0x3c')]['filter']+'%'},_0x3d22c4;}})}));_0x52f433=_[_0x2d8205('0x1d')]({},_0x52f433,_0x43c9f4[_0x2d8205('0x3b')]);const _0x10c41b={'where':_0x52f433[_0x2d8205('0x37')]};return db[_0x2d8205('0x29')]['count'](_0x10c41b)[_0x2d8205('0x1f')](function(_0xe41442){const _0x2c3ed9=_0x2d8205;return _0x27d090['count']=_0xe41442,_0x43c9f4[_0x2c3ed9('0x3c')][_0x2c3ed9('0x17')]&&(_0x52f433[_0x2c3ed9('0xe')]=[{'all':!![]}]),db[_0x2c3ed9('0x29')][_0x2c3ed9('0x7')](_0x52f433);})['then'](function(_0xff1664){const _0x599fa6=_0x2d8205;return _0x27d090[_0x599fa6('0x26')]=_0xff1664,_0x27d090;})[_0x2d8205('0x1f')](respondWithFilteredResult(_0x323f5f,_0x52f433))[_0x2d8205('0x35')](handleError(_0x323f5f,null));},exports[_0x531bf1('0xa')]=function(_0x57f947,_0x362921){const _0x21b6cc=_0x531bf1;let _0x4db9={'raw':!![],'where':{'id':_0x57f947[_0x21b6cc('0xc')]['id']}};const _0x3c6bd4={};return _0x3c6bd4['model']=_[_0x21b6cc('0x14')](db[_0x21b6cc('0x29')][_0x21b6cc('0xf')]),_0x3c6bd4[_0x21b6cc('0x3c')]=_[_0x21b6cc('0x14')](_0x57f947[_0x21b6cc('0x3c')]),_0x3c6bd4[_0x21b6cc('0x13')]=_[_0x21b6cc('0x39')](_0x3c6bd4[_0x21b6cc('0x12')],_0x3c6bd4[_0x21b6cc('0x3c')]),_0x4db9[_0x21b6cc('0x2d')]=_[_0x21b6cc('0x39')](_0x3c6bd4[_0x21b6cc('0x12')],qs[_0x21b6cc('0x11')](_0x57f947['query'][_0x21b6cc('0x11')])),_0x4db9[_0x21b6cc('0x2d')]=_0x4db9[_0x21b6cc('0x2d')][_0x21b6cc('0xb')]?_0x4db9[_0x21b6cc('0x2d')]:_0x3c6bd4[_0x21b6cc('0x12')],_0x57f947['query']['includeAll']&&(_0x4db9[_0x21b6cc('0xe')]=[{'all':!![]}]),_0x4db9=_['merge']({},_0x4db9,_0x57f947[_0x21b6cc('0x3b')]),db[_0x21b6cc('0x29')]['findOne'](_0x4db9)[_0x21b6cc('0x1f')](handleEntityNotFound(_0x362921,null))[_0x21b6cc('0x1f')](respondWithResult(_0x362921,null))['catch'](handleError(_0x362921,null));},exports[_0x531bf1('0x20')]=function(_0xd9c35f,_0x571624){const _0x49a825=_0x531bf1;return db[_0x49a825('0x29')][_0x49a825('0x20')](_0xd9c35f[_0x49a825('0x3d')],{})[_0x49a825('0x1f')](function(_0xd030e5){const _0x194a90=_0x49a825,_0x33fa40=_0xd9c35f['user'][_0x194a90('0x30')]({'plain':!![]});if(!_0x33fa40)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x33fa40[_0x194a90('0x2b')]===_0x194a90('0x2c')){const _0x28138c=_0xd030e5['get']({'plain':!![]}),_0x63cc5=_0x194a90('0x43');return db[_0x194a90('0x10')][_0x194a90('0x2')]({'where':{'name':_0x63cc5,'userProfileId':_0x33fa40[_0x194a90('0x18')]},'raw':!![]})[_0x194a90('0x1f')](function(_0x51f45b){const _0x546687=_0x194a90;return _0x51f45b&&_0x51f45b[_0x546687('0x45')]===0x0?db['UserProfileResource'][_0x546687('0x20')]({'name':_0x28138c[_0x546687('0x3e')],'resourceId':_0x28138c['id'],'type':_0x51f45b[_0x546687('0x3e')],'sectionId':_0x51f45b['id']},{})[_0x546687('0x1f')](function(){return _0xd030e5;}):_0xd030e5;})['catch'](function(_0x2482c3){const _0x45d871=_0x194a90;logger[_0x45d871('0x40')](_0x45d871('0x28'),_0x2482c3);throw _0x2482c3;});}return _0xd030e5;})[_0x49a825('0x1f')](respondWithResult(_0x571624,0xc9))[_0x49a825('0x35')](handleError(_0x571624,null));},exports['update']=function(_0x198427,_0x457a60){const _0x4e9298=_0x531bf1;return _0x198427[_0x4e9298('0x3d')]['id']&&delete _0x198427[_0x4e9298('0x3d')]['id'],db[_0x4e9298('0x29')][_0x4e9298('0x2')]({'where':{'id':_0x198427[_0x4e9298('0xc')]['id']}})['then'](handleEntityNotFound(_0x457a60,null))[_0x4e9298('0x1f')](saveUpdates(_0x198427[_0x4e9298('0x3d')],null))[_0x4e9298('0x1f')](respondWithResult(_0x457a60,null))[_0x4e9298('0x35')](handleError(_0x457a60,null));},exports[_0x531bf1('0x6')]=function(_0xa9f1d9,_0x4fe7fa){const _0x4ff144=_0x531bf1;return db[_0x4ff144('0x29')]['findOne']({'where':{'id':_0xa9f1d9[_0x4ff144('0xc')]['id']}})[_0x4ff144('0x1f')](handleEntityNotFound(_0x4fe7fa,null))[_0x4ff144('0x1f')](removeEntity(_0x4fe7fa,null))[_0x4ff144('0x35')](handleError(_0x4fe7fa,null));},exports[_0x531bf1('0x46')]=function(_0x1d723f,_0x58207a){const _0xa12a1e=_0x531bf1;return db[_0xa12a1e('0x29')][_0xa12a1e('0x2')]({'where':{'id':_0x1d723f[_0xa12a1e('0xc')]['id']},'attributes':[_0xa12a1e('0x3e'),'basename',_0xa12a1e('0x22'),_0xa12a1e('0x21')],'raw':!![]})[_0xa12a1e('0x1f')](handleEntityNotFound(_0x58207a,null))[_0xa12a1e('0x1f')](function(_0x428fad){const _0x44ec2e=_0xa12a1e;if(_0x428fad){if(!fs['existsSync'](path['join'](config[_0x44ec2e('0x44')],_0x44ec2e('0x4'),_0x428fad[_0x44ec2e('0x22')])))throw new ValidationError(_0x44ec2e('0x32'));if(_0x1d723f[_0x44ec2e('0x3c')][_0x44ec2e('0x8')])return _0x58207a['sendStatus'](0xc8);return _0x58207a['download'](path[_0x44ec2e('0x16')](config[_0x44ec2e('0x44')],_0x44ec2e('0x4'),_0x428fad[_0x44ec2e('0x22')]),util['format'](_0x44ec2e('0x3'),_0x428fad[_0x44ec2e('0x19')]||_0x428fad['name'],_0x428fad[_0x44ec2e('0x21')][_0x44ec2e('0x3a')]()));}})[_0xa12a1e('0x35')](handleError(_0x58207a,null));};