57f181ca9fa24fa58bb3c6480e60d49257fb0d42
[motion-next.git] / server / api / analyticMetric / analyticMetric.controller.js
1 const a21_0x172b=['merge','get','filter','query','filters','body','where','catch','lodash','findAll','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','length','rawAttributes','name','nolimit','status','show','type','create','userProfileId','options','keys','intersection','attributes','map','destroy','includeAll','error','user','count','../../config/logger','include','sendStatus','AnalyticMetric','fields','order','Content-Range','findOne','then','pick','end','UserProfileSection','role','offset','send','params','undefined','sequelize','VIRTUAL','json','../../mysqldb','limit','UserProfileResource','Unable\x20to\x20retrieve\x20the\x20current\x20user','rows','sort','stack','api','../../components/parsers/qs','key','model','autoAssociation','index','fieldName'];(function(_0x257958,_0x172b43){const _0x10bb65=function(_0x53cbd6){while(--_0x53cbd6){_0x257958['push'](_0x257958['shift']());}};_0x10bb65(++_0x172b43);}(a21_0x172b,0x18a));const a21_0x10bb=function(_0x257958,_0x172b43){_0x257958=_0x257958-0x0;let _0x10bb65=a21_0x172b[_0x257958];return _0x10bb65;};const _0x4e10d1=a21_0x10bb;'use strict';const _=require(_0x4e10d1('0x3e')),qs=require(_0x4e10d1('0x30')),logger=require(_0x4e10d1('0x14'))(_0x4e10d1('0x2f')),db=require(_0x4e10d1('0x28'))['db'],{Op}=require(_0x4e10d1('0x25'));function respondWithResult(_0x53cbd6,_0x2b2393){return _0x2b2393=_0x2b2393||0xc8,function(_0x2c7855){const _0x39ad53=a21_0x10bb;if(_0x2c7855)return _0x53cbd6['status'](_0x2b2393)[_0x39ad53('0x27')](_0x2c7855);};}function respondWithFilteredResult(_0x2c47fe,_0x52f00a){return function(_0x542ef3){const _0x1de507=a21_0x10bb;if(_0x542ef3){const _0x5d28b1=_0x542ef3[_0x1de507('0x13')],_0x1c925b=_0x52f00a[_0x1de507('0x21')];let _0x31d8b5=_0x52f00a[_0x1de507('0x21')]+_0x52f00a[_0x1de507('0x29')],_0x56f05e;return _0x31d8b5>=_0x5d28b1?(_0x31d8b5=_0x5d28b1,_0x56f05e=0xc8):_0x56f05e=0xce,_0x2c47fe[_0x1de507('0x5')](_0x56f05e),_0x2c47fe['set'](_0x1de507('0x1a'),_0x1c925b+'-'+_0x31d8b5+'/'+_0x5d28b1)[_0x1de507('0x27')](_0x542ef3);}return null;};}function saveUpdates(_0x4d8c69){return function(_0x5272b7){const _0x2750aa=a21_0x10bb;if(_0x5272b7)return _0x5272b7['update'](_0x4d8c69)[_0x2750aa('0x1c')](function(_0x5aa697){return _0x5aa697;});return null;};}function removeEntity(_0x2e547d){return function(_0x131a4e){const _0x1cbd41=a21_0x10bb;if(_0x131a4e)return _0x131a4e[_0x1cbd41('0xf')]()['then'](function(){const _0x3857ba=_0x1cbd41,_0x4f2a01=_0x131a4e['get']({'plain':!![]}),_0x1451b0='Metrics';return db[_0x3857ba('0x2a')][_0x3857ba('0xf')]({'where':{'type':_0x1451b0,'resourceId':_0x4f2a01['id']}})[_0x3857ba('0x1c')](function(){return _0x131a4e;});})[_0x1cbd41('0x1c')](function(){const _0x4ac94a=_0x1cbd41;_0x2e547d['status'](0xcc)[_0x4ac94a('0x1e')]();});};}function handleEntityNotFound(_0x11c586){return function(_0x5035f6){const _0x35cf59=a21_0x10bb;return!_0x5035f6&&_0x11c586[_0x35cf59('0x16')](0x194),_0x5035f6;};}function handleError(_0x44e665,_0x165bf1){return _0x165bf1=_0x165bf1||0x1f4,function(_0xfe5665){const _0x21f330=a21_0x10bb;logger[_0x21f330('0x11')](_0xfe5665[_0x21f330('0x2e')]),_0xfe5665['name']&&delete _0xfe5665[_0x21f330('0x3')],_0x44e665[_0x21f330('0x5')](_0x165bf1)[_0x21f330('0x22')](_0xfe5665);};}exports[_0x4e10d1('0x34')]=function(_0x37523e,_0xfed739){const _0x59a325=_0x4e10d1;let _0x2693dc={};const _0x581569={},_0x3c5f87={'count':0x0,'rows':[]},_0x51dc76=_['map'](db['AnalyticMetric'][_0x59a325('0x2')],function(_0x477186){const _0x4ad058=_0x59a325;return{'name':_0x477186[_0x4ad058('0x35')],'type':_0x477186[_0x4ad058('0x7')][_0x4ad058('0x31')]};});_0x581569[_0x59a325('0x32')]=_[_0x59a325('0xe')](_0x51dc76,_0x59a325('0x3')),_0x581569[_0x59a325('0x39')]=_[_0x59a325('0xb')](_0x37523e[_0x59a325('0x39')]),_0x581569[_0x59a325('0x3a')]=_[_0x59a325('0xc')](_0x581569[_0x59a325('0x32')],_0x581569[_0x59a325('0x39')]),_0x2693dc['attributes']=_[_0x59a325('0xc')](_0x581569[_0x59a325('0x32')],qs[_0x59a325('0x18')](_0x37523e[_0x59a325('0x39')][_0x59a325('0x18')])),_0x2693dc['attributes']=_0x2693dc[_0x59a325('0xd')][_0x59a325('0x1')]?_0x2693dc[_0x59a325('0xd')]:_0x581569['model'];typeof _0x37523e['query'][_0x59a325('0x4')]===_0x59a325('0x24')&&(_0x2693dc['limit']=qs[_0x59a325('0x29')](_0x37523e[_0x59a325('0x39')][_0x59a325('0x29')]),_0x2693dc[_0x59a325('0x21')]=qs[_0x59a325('0x21')](_0x37523e[_0x59a325('0x39')][_0x59a325('0x21')]));_0x2693dc[_0x59a325('0x19')]=qs[_0x59a325('0x2d')](_0x37523e['query'][_0x59a325('0x2d')]),_0x2693dc[_0x59a325('0x3c')]=qs[_0x59a325('0x3a')](_[_0x59a325('0x1d')](_0x37523e[_0x59a325('0x39')],_0x581569['filters']),_0x51dc76);_0x37523e[_0x59a325('0x39')]['filter']&&(_0x2693dc[_0x59a325('0x3c')]=_[_0x59a325('0x36')](_0x2693dc[_0x59a325('0x3c')],{[Op['or']]:_[_0x59a325('0xe')](_0x51dc76,function(_0xd45558){const _0x3358e2=_0x59a325;if(_0xd45558[_0x3358e2('0x7')]!==_0x3358e2('0x26')){const _0x1774f1={};return _0x1774f1[_0xd45558[_0x3358e2('0x3')]]={[Op['like']]:'%'+_0x37523e[_0x3358e2('0x39')][_0x3358e2('0x38')]+'%'},_0x1774f1;}})}));_0x2693dc=_[_0x59a325('0x36')]({},_0x2693dc,_0x37523e[_0x59a325('0xa')]);const _0x10e76e={'where':_0x2693dc[_0x59a325('0x3c')]};return db[_0x59a325('0x17')]['count'](_0x10e76e)[_0x59a325('0x1c')](function(_0x1ace09){const _0x21d8b4=_0x59a325;return _0x3c5f87[_0x21d8b4('0x13')]=_0x1ace09,_0x37523e[_0x21d8b4('0x39')][_0x21d8b4('0x10')]&&(_0x2693dc[_0x21d8b4('0x15')]=[{'all':!![]}]),db[_0x21d8b4('0x17')][_0x21d8b4('0x3f')](_0x2693dc);})[_0x59a325('0x1c')](function(_0x234e59){const _0x30b330=_0x59a325;return _0x3c5f87[_0x30b330('0x2c')]=_0x234e59,_0x3c5f87;})[_0x59a325('0x1c')](respondWithFilteredResult(_0xfed739,_0x2693dc))[_0x59a325('0x3d')](handleError(_0xfed739,null));},exports[_0x4e10d1('0x6')]=function(_0x13c60f,_0x55af37){const _0x3e3bb2=_0x4e10d1;let _0x2a603a={'raw':!![],'where':{'id':_0x13c60f[_0x3e3bb2('0x23')]['id']}};const _0x562086={};return _0x562086[_0x3e3bb2('0x32')]=_[_0x3e3bb2('0xb')](db[_0x3e3bb2('0x17')][_0x3e3bb2('0x2')]),_0x562086[_0x3e3bb2('0x39')]=_[_0x3e3bb2('0xb')](_0x13c60f['query']),_0x562086[_0x3e3bb2('0x3a')]=_[_0x3e3bb2('0xc')](_0x562086[_0x3e3bb2('0x32')],_0x562086[_0x3e3bb2('0x39')]),_0x2a603a[_0x3e3bb2('0xd')]=_[_0x3e3bb2('0xc')](_0x562086['model'],qs['fields'](_0x13c60f[_0x3e3bb2('0x39')]['fields'])),_0x2a603a[_0x3e3bb2('0xd')]=_0x2a603a['attributes']['length']?_0x2a603a[_0x3e3bb2('0xd')]:_0x562086[_0x3e3bb2('0x32')],_0x13c60f[_0x3e3bb2('0x39')][_0x3e3bb2('0x10')]&&(_0x2a603a[_0x3e3bb2('0x15')]=[{'all':!![]}]),_0x2a603a=_[_0x3e3bb2('0x36')]({},_0x2a603a,_0x13c60f['options']),db[_0x3e3bb2('0x17')]['findOne'](_0x2a603a)[_0x3e3bb2('0x1c')](handleEntityNotFound(_0x55af37,null))['then'](respondWithResult(_0x55af37,null))[_0x3e3bb2('0x3d')](handleError(_0x55af37,null));},exports[_0x4e10d1('0x8')]=function(_0x3882dc,_0x12cbca){const _0x2bb9c0=_0x4e10d1;return db[_0x2bb9c0('0x17')]['create'](_0x3882dc['body'],{})[_0x2bb9c0('0x1c')](function(_0x173381){const _0x2ce5b1=_0x2bb9c0,_0x29ac9c=_0x3882dc[_0x2ce5b1('0x12')][_0x2ce5b1('0x37')]({'plain':!![]});if(!_0x29ac9c)throw new Error(_0x2ce5b1('0x2b'));if(_0x29ac9c[_0x2ce5b1('0x20')]===_0x2ce5b1('0x12')){const _0x451406=_0x173381[_0x2ce5b1('0x37')]({'plain':!![]}),_0x59c6cf='Metrics';return db[_0x2ce5b1('0x1f')]['findOne']({'where':{'name':_0x59c6cf,'userProfileId':_0x29ac9c[_0x2ce5b1('0x9')]},'raw':!![]})[_0x2ce5b1('0x1c')](function(_0x2b3822){const _0x10ddd1=_0x2ce5b1;return _0x2b3822&&_0x2b3822[_0x10ddd1('0x33')]===0x0?db['UserProfileResource'][_0x10ddd1('0x8')]({'name':_0x451406[_0x10ddd1('0x3')],'resourceId':_0x451406['id'],'type':_0x2b3822['name'],'sectionId':_0x2b3822['id']},{})[_0x10ddd1('0x1c')](function(){return _0x173381;}):_0x173381;})[_0x2ce5b1('0x3d')](function(_0x68eb72){const _0x43ae27=_0x2ce5b1;logger['error'](_0x43ae27('0x0'),_0x68eb72);throw _0x68eb72;});}return _0x173381;})[_0x2bb9c0('0x1c')](respondWithResult(_0x12cbca,0xc9))[_0x2bb9c0('0x3d')](handleError(_0x12cbca,null));},exports['update']=function(_0x1f52f6,_0x5bd951){const _0x2a225a=_0x4e10d1;return _0x1f52f6[_0x2a225a('0x3b')]['id']&&delete _0x1f52f6[_0x2a225a('0x3b')]['id'],db[_0x2a225a('0x17')][_0x2a225a('0x1b')]({'where':{'id':_0x1f52f6[_0x2a225a('0x23')]['id']}})[_0x2a225a('0x1c')](handleEntityNotFound(_0x5bd951,null))[_0x2a225a('0x1c')](saveUpdates(_0x1f52f6[_0x2a225a('0x3b')],null))[_0x2a225a('0x1c')](respondWithResult(_0x5bd951,null))[_0x2a225a('0x3d')](handleError(_0x5bd951,null));},exports[_0x4e10d1('0xf')]=function(_0x4bf8b9,_0x66643d){const _0x16635f=_0x4e10d1;return db['AnalyticMetric']['findOne']({'where':{'id':_0x4bf8b9['params']['id']}})['then'](handleEntityNotFound(_0x66643d,null))[_0x16635f('0x1c')](removeEntity(_0x66643d,null))[_0x16635f('0x3d')](handleError(_0x66643d,null));};