732af3c11350638b027430a4e6f072077e2760ac
[motion-next.git] / server / api / analyticFieldReport / analyticFieldReport.controller.js
1 const a17_0xf1f2=['filter','model','../../components/parsers/qs','fieldName','count','query','rawAttributes','send','body','VIRTUAL','status','key','intersection','catch','set','order','update','keys','length','limit','destroy','sequelize','options','addFields','bulkCreate','type','sort','../../mysqldb','filters','then','../../config/logger','attributes','sendStatus','like','stack','pick','Content-Range','findOne','json','include','includeAll','api','end','bulkDestroy','params','merge','offset','fields','name','CustomReportId','AnalyticFieldReport','where','map'];(function(_0x38338c,_0xf1f291){const _0x2fc356=function(_0x3dbe53){while(--_0x3dbe53){_0x38338c['push'](_0x38338c['shift']());}};_0x2fc356(++_0xf1f291);}(a17_0xf1f2,0x133));const a17_0x2fc3=function(_0x38338c,_0xf1f291){_0x38338c=_0x38338c-0x0;let _0x2fc356=a17_0xf1f2[_0x38338c];return _0x2fc356;};const _0x28e34f=a17_0x2fc3;'use strict';const _=require('lodash'),qs=require(_0x28e34f('0xd')),logger=require(_0x28e34f('0x29'))(_0x28e34f('0x34')),db=require(_0x28e34f('0x26'))['db'],{Op}=require(_0x28e34f('0x20'));function respondWithResult(_0x3dbe53,_0x4cad24){return _0x4cad24=_0x4cad24||0xc8,function(_0x2fa77f){const _0x250097=a17_0x2fc3;if(_0x2fa77f)return _0x3dbe53[_0x250097('0x15')](_0x4cad24)[_0x250097('0x31')](_0x2fa77f);};}function respondWithFilteredResult(_0x7ad8f4,_0x29e624){return function(_0x1d4799){const _0x1673d6=a17_0x2fc3;if(_0x1d4799){const _0x47f955=_0x1d4799['count'],_0x2f99bd=_0x29e624[_0x1673d6('0x4')];let _0x19e4a9=_0x29e624['offset']+_0x29e624[_0x1673d6('0x1e')],_0x167c69;return _0x19e4a9>=_0x47f955?(_0x19e4a9=_0x47f955,_0x167c69=0xc8):_0x167c69=0xce,_0x7ad8f4['status'](_0x167c69),_0x7ad8f4[_0x1673d6('0x19')](_0x1673d6('0x2f'),_0x2f99bd+'-'+_0x19e4a9+'/'+_0x47f955)[_0x1673d6('0x31')](_0x1d4799);}return null;};}function saveUpdates(_0x4f6f84){return function(_0x47c143){const _0x363a3e=a17_0x2fc3;if(_0x47c143)return _0x47c143['update'](_0x4f6f84)[_0x363a3e('0x28')](function(_0x4335d2){return _0x4335d2;});return null;};}function removeEntity(_0x51e7f0){return function(_0x11030d){const _0x4f3220=a17_0x2fc3;if(_0x11030d)return _0x11030d[_0x4f3220('0x1f')]()[_0x4f3220('0x28')](function(){const _0x3de6d6=_0x4f3220;_0x51e7f0[_0x3de6d6('0x15')](0xcc)[_0x3de6d6('0x0')]();});};}function handleEntityNotFound(_0x2f12a3){return function(_0x202add){const _0x452d47=a17_0x2fc3;return!_0x202add&&_0x2f12a3[_0x452d47('0x2b')](0x194),_0x202add;};}function handleError(_0x2238d8,_0x5b7be1){return _0x5b7be1=_0x5b7be1||0x1f4,function(_0x4913e5){const _0x42dafd=a17_0x2fc3;logger['error'](_0x4913e5[_0x42dafd('0x2d')]),_0x4913e5[_0x42dafd('0x6')]&&delete _0x4913e5['name'],_0x2238d8[_0x42dafd('0x15')](_0x5b7be1)[_0x42dafd('0x12')](_0x4913e5);};}exports['index']=function(_0x7a2933,_0x37ccb4){const _0x5389a0=_0x28e34f;let _0x40bca0={};const _0xd46748={},_0x3078fa={'count':0x0,'rows':[]},_0x53260b=_[_0x5389a0('0xa')](db[_0x5389a0('0x8')]['rawAttributes'],function(_0x5b2fa7){const _0x12c3f0=_0x5389a0;return{'name':_0x5b2fa7[_0x12c3f0('0xe')],'type':_0x5b2fa7['type'][_0x12c3f0('0x16')]};});_0xd46748['model']=_[_0x5389a0('0xa')](_0x53260b,_0x5389a0('0x6')),_0xd46748[_0x5389a0('0x10')]=_[_0x5389a0('0x1c')](_0x7a2933[_0x5389a0('0x10')]),_0xd46748[_0x5389a0('0x27')]=_[_0x5389a0('0x17')](_0xd46748[_0x5389a0('0xc')],_0xd46748['query']),_0x40bca0[_0x5389a0('0x2a')]=_[_0x5389a0('0x17')](_0xd46748[_0x5389a0('0xc')],qs[_0x5389a0('0x5')](_0x7a2933[_0x5389a0('0x10')][_0x5389a0('0x5')])),_0x40bca0[_0x5389a0('0x2a')]=_0x40bca0[_0x5389a0('0x2a')][_0x5389a0('0x1d')]?_0x40bca0['attributes']:_0xd46748[_0x5389a0('0xc')];typeof _0x7a2933['query']['nolimit']==='undefined'&&(_0x40bca0['limit']=qs['limit'](_0x7a2933[_0x5389a0('0x10')][_0x5389a0('0x1e')]),_0x40bca0[_0x5389a0('0x4')]=qs['offset'](_0x7a2933[_0x5389a0('0x10')][_0x5389a0('0x4')]));_0x40bca0[_0x5389a0('0x1a')]=qs[_0x5389a0('0x25')](_0x7a2933[_0x5389a0('0x10')][_0x5389a0('0x25')]),_0x40bca0[_0x5389a0('0x9')]=qs[_0x5389a0('0x27')](_[_0x5389a0('0x2e')](_0x7a2933[_0x5389a0('0x10')],_0xd46748['filters']),_0x53260b);_0x7a2933['query'][_0x5389a0('0xb')]&&(_0x40bca0[_0x5389a0('0x9')]=_[_0x5389a0('0x3')](_0x40bca0[_0x5389a0('0x9')],{[Op['or']]:_[_0x5389a0('0xa')](_0x53260b,function(_0x5ccec4){const _0x3e3db0=_0x5389a0;if(_0x5ccec4[_0x3e3db0('0x24')]!==_0x3e3db0('0x14')){const _0x4e7453={};return _0x4e7453[_0x5ccec4['name']]={[Op[_0x3e3db0('0x2c')]]:'%'+_0x7a2933['query'][_0x3e3db0('0xb')]+'%'},_0x4e7453;}})}));_0x40bca0=_[_0x5389a0('0x3')]({},_0x40bca0,_0x7a2933['options']);const _0x4b9844={'where':_0x40bca0[_0x5389a0('0x9')]};return db['AnalyticFieldReport'][_0x5389a0('0xf')](_0x4b9844)['then'](function(_0x585959){const _0x2d0bce=_0x5389a0;return _0x3078fa[_0x2d0bce('0xf')]=_0x585959,_0x7a2933[_0x2d0bce('0x10')][_0x2d0bce('0x33')]&&(_0x40bca0['include']=[{'all':!![]}]),db[_0x2d0bce('0x8')]['findAll'](_0x40bca0);})[_0x5389a0('0x28')](function(_0x28284f){return _0x3078fa['rows']=_0x28284f,_0x3078fa;})[_0x5389a0('0x28')](respondWithFilteredResult(_0x37ccb4,_0x40bca0))[_0x5389a0('0x18')](handleError(_0x37ccb4,null));},exports['show']=function(_0x2f6460,_0x2f0ef3){const _0x5418df=_0x28e34f;let _0x53e097={'raw':![],'where':{'id':_0x2f6460[_0x5418df('0x2')]['id']}};const _0x5f3074={};return _0x5f3074[_0x5418df('0xc')]=_[_0x5418df('0x1c')](db['AnalyticFieldReport'][_0x5418df('0x11')]),_0x5f3074[_0x5418df('0x10')]=_[_0x5418df('0x1c')](_0x2f6460[_0x5418df('0x10')]),_0x5f3074[_0x5418df('0x27')]=_[_0x5418df('0x17')](_0x5f3074[_0x5418df('0xc')],_0x5f3074[_0x5418df('0x10')]),_0x53e097[_0x5418df('0x2a')]=_['intersection'](_0x5f3074[_0x5418df('0xc')],qs[_0x5418df('0x5')](_0x2f6460[_0x5418df('0x10')][_0x5418df('0x5')])),_0x53e097[_0x5418df('0x2a')]=_0x53e097[_0x5418df('0x2a')]['length']?_0x53e097[_0x5418df('0x2a')]:_0x5f3074[_0x5418df('0xc')],_0x2f6460['query'][_0x5418df('0x33')]&&(_0x53e097[_0x5418df('0x32')]=[{'all':!![]}]),_0x53e097=_['merge']({},_0x53e097,_0x2f6460[_0x5418df('0x21')]),db['AnalyticFieldReport']['findOne'](_0x53e097)['then'](handleEntityNotFound(_0x2f0ef3,null))[_0x5418df('0x28')](respondWithResult(_0x2f0ef3,null))[_0x5418df('0x18')](handleError(_0x2f0ef3,null));},exports['create']=function(_0x1e7bae,_0x33e8e1){const _0x3a255=_0x28e34f;return db['AnalyticFieldReport']['create'](_0x1e7bae[_0x3a255('0x13')],{})[_0x3a255('0x28')](respondWithResult(_0x33e8e1,0xc9))['catch'](handleError(_0x33e8e1,null));},exports['bulkCreate']=function(_0x223335,_0x4a0650){const _0x580d83=_0x28e34f;return db[_0x580d83('0x8')][_0x580d83('0x23')](_0x223335[_0x580d83('0x13')],{'raw':![],'individualHooks':!![]})['then'](respondWithResult(_0x4a0650,0xc9))['catch'](handleError(_0x4a0650,null));},exports[_0x28e34f('0x1b')]=function(_0x51cfe5,_0x32853b){const _0x172d51=_0x28e34f;return _0x51cfe5[_0x172d51('0x13')]['id']&&delete _0x51cfe5[_0x172d51('0x13')]['id'],db[_0x172d51('0x8')]['findOne']({'where':{'id':_0x51cfe5['params']['id']}})['then'](handleEntityNotFound(_0x32853b,null))[_0x172d51('0x28')](saveUpdates(_0x51cfe5[_0x172d51('0x13')],null))[_0x172d51('0x28')](respondWithResult(_0x32853b,null))[_0x172d51('0x18')](handleError(_0x32853b,null));},exports[_0x28e34f('0x1f')]=function(_0x2dd914,_0x48c262){const _0x2c0057=_0x28e34f;return db[_0x2c0057('0x8')]['findOne']({'where':{'id':_0x2dd914[_0x2c0057('0x2')]['id']}})['then'](handleEntityNotFound(_0x48c262,null))[_0x2c0057('0x28')](removeEntity(_0x48c262,null))[_0x2c0057('0x18')](handleError(_0x48c262,null));},exports[_0x28e34f('0x1')]=function(_0x1ae22e,_0x36fcbc){const _0x55b5ba=_0x28e34f;return db[_0x55b5ba('0x8')]['destroy']({'where':{'id':_0x1ae22e['query']['ids']||[]},'raw':![],'individualHooks':!![]})[_0x55b5ba('0x28')](respondWithResult(_0x36fcbc,0xcc))[_0x55b5ba('0x18')](handleError(_0x36fcbc,null));},exports[_0x28e34f('0x22')]=function(_0x3a97c6,_0x118083){const _0x12f446=_0x28e34f;return db['AnalyticCustomReport'][_0x12f446('0x30')]({'where':{'id':_0x3a97c6[_0x12f446('0x2')]['id']}})[_0x12f446('0x28')](handleEntityNotFound(_0x118083,null))[_0x12f446('0x28')](function(_0x2815a8){const _0x282a3b=_0x12f446;if(_0x2815a8)return db[_0x282a3b('0x20')]['transaction'](function(_0x2a72b1){const _0x54eebc=_0x282a3b;return db[_0x54eebc('0x8')][_0x54eebc('0x1f')]({'where':{'CustomReportId':_0x3a97c6[_0x54eebc('0x2')]['id']},'transaction':_0x2a72b1})[_0x54eebc('0x28')](function(){const _0x245d98=_0x54eebc,_0xa10a38=_[_0x245d98('0xa')](_0x3a97c6[_0x245d98('0x13')],function(_0xc822ca){const _0x573bfd=_0x245d98;return delete _0xc822ca['id'],_0xc822ca[_0x573bfd('0x7')]=_0x3a97c6[_0x573bfd('0x2')]['id'],_0xc822ca;});return db[_0x245d98('0x8')]['bulkCreate'](_0xa10a38,{'transaction':_0x2a72b1});});})[_0x282a3b('0x28')](function(){const _0x112479=_0x282a3b;return db[_0x112479('0x8')]['findAll']({'where':{'CustomReportId':_0x3a97c6[_0x112479('0x2')]['id']}});});})[_0x12f446('0x28')](respondWithResult(_0x118083,null))['catch'](handleError(_0x118083,null));};