56822e509f7dcd6ae46261c543f930a65a46e176
[motion-next.git] / server / api / variable / variable.controller.js
1 const a697_0x42eb=['type','attributes','limit','where','pick','autoAssociation','role','length','options','../../components/parsers/qs','send','params','rows','get','filter','json','update','error','findOne','nolimit','status','UserProfileResource','body','keys','then','order','UserProfileSection','destroy','create','Variables','key','include','end','model','set','api','name','count','user','findAll','show','Content-Range','merge','offset','rawAttributes','like','filters','catch','stack','map','includeAll','fields','index','lodash','intersection','userProfileId','Variable','sort','query'];(function(_0x180aaf,_0x42ebfd){const _0x2fcc17=function(_0x53e9f7){while(--_0x53e9f7){_0x180aaf['push'](_0x180aaf['shift']());}};_0x2fcc17(++_0x42ebfd);}(a697_0x42eb,0xb9));const a697_0x2fcc=function(_0x180aaf,_0x42ebfd){_0x180aaf=_0x180aaf-0x0;let _0x2fcc17=a697_0x42eb[_0x180aaf];return _0x2fcc17;};const _0x1721e6=a697_0x2fcc;'use strict';const _=require(_0x1721e6('0x2d')),qs=require(_0x1721e6('0x1')),logger=require('../../config/logger')(_0x1721e6('0x1b')),db=require('../../mysqldb')['db'],{Op}=require('sequelize');function respondWithResult(_0x53e9f7,_0x28b24e){return _0x28b24e=_0x28b24e||0xc8,function(_0xa3a5f){const _0x56be63=a697_0x2fcc;if(_0xa3a5f)return _0x53e9f7[_0x56be63('0xc')](_0x28b24e)[_0x56be63('0x7')](_0xa3a5f);};}function respondWithFilteredResult(_0x2253f6,_0x38931c){return function(_0x57a4ab){const _0x45ddb9=a697_0x2fcc;if(_0x57a4ab){const _0x4293c9=_0x57a4ab[_0x45ddb9('0x1d')],_0x433480=_0x38931c[_0x45ddb9('0x23')];let _0x59ee2f=_0x38931c['offset']+_0x38931c['limit'],_0x30e6f2;return _0x59ee2f>=_0x4293c9?(_0x59ee2f=_0x4293c9,_0x30e6f2=0xc8):_0x30e6f2=0xce,_0x2253f6[_0x45ddb9('0xc')](_0x30e6f2),_0x2253f6[_0x45ddb9('0x1a')](_0x45ddb9('0x21'),_0x433480+'-'+_0x59ee2f+'/'+_0x4293c9)['json'](_0x57a4ab);}return null;};}function saveUpdates(_0x260e61){return function(_0x169b5c){const _0x1241fa=a697_0x2fcc;if(_0x169b5c)return _0x169b5c[_0x1241fa('0x8')](_0x260e61)[_0x1241fa('0x10')](function(_0x4e45f9){return _0x4e45f9;});return null;};}function removeEntity(_0x2ce566){return function(_0x3e2e90){const _0x5c3746=a697_0x2fcc;if(_0x3e2e90)return _0x3e2e90[_0x5c3746('0x13')]()[_0x5c3746('0x10')](function(){const _0x473883=_0x5c3746,_0x57b8a2=_0x3e2e90[_0x473883('0x5')]({'plain':!![]}),_0x386631=_0x473883('0x15');return db[_0x473883('0xd')]['destroy']({'where':{'type':_0x386631,'resourceId':_0x57b8a2['id']}})[_0x473883('0x10')](function(){return _0x3e2e90;});})[_0x5c3746('0x10')](function(){const _0x8834c=_0x5c3746;_0x2ce566[_0x8834c('0xc')](0xcc)[_0x8834c('0x18')]();});};}function handleEntityNotFound(_0x49b8da){return function(_0x842d42){return!_0x842d42&&_0x49b8da['sendStatus'](0x194),_0x842d42;};}function handleError(_0x5b777b,_0x29c935){return _0x29c935=_0x29c935||0x1f4,function(_0x38277f){const _0x196cd2=a697_0x2fcc;logger[_0x196cd2('0x9')](_0x38277f[_0x196cd2('0x28')]),_0x38277f[_0x196cd2('0x1c')]&&delete _0x38277f[_0x196cd2('0x1c')],_0x5b777b[_0x196cd2('0xc')](_0x29c935)[_0x196cd2('0x2')](_0x38277f);};}exports[_0x1721e6('0x2c')]=function(_0x5cc82d,_0xa5e2ab){const _0x22f213=_0x1721e6;let _0x1834ad={};const _0x40d510={},_0x495145={'count':0x0,'rows':[]},_0x49cbbb=_[_0x22f213('0x29')](db['Variable']['rawAttributes'],function(_0x1f3c4a){const _0x53590d=_0x22f213;return{'name':_0x1f3c4a['fieldName'],'type':_0x1f3c4a[_0x53590d('0x33')][_0x53590d('0x16')]};});_0x40d510[_0x22f213('0x19')]=_[_0x22f213('0x29')](_0x49cbbb,_0x22f213('0x1c')),_0x40d510['query']=_['keys'](_0x5cc82d[_0x22f213('0x32')]),_0x40d510['filters']=_['intersection'](_0x40d510[_0x22f213('0x19')],_0x40d510[_0x22f213('0x32')]),_0x1834ad[_0x22f213('0x34')]=_[_0x22f213('0x2e')](_0x40d510[_0x22f213('0x19')],qs[_0x22f213('0x2b')](_0x5cc82d[_0x22f213('0x32')][_0x22f213('0x2b')])),_0x1834ad[_0x22f213('0x34')]=_0x1834ad[_0x22f213('0x34')][_0x22f213('0x3a')]?_0x1834ad[_0x22f213('0x34')]:_0x40d510['model'];typeof _0x5cc82d['query'][_0x22f213('0xb')]==='undefined'&&(_0x1834ad['limit']=qs[_0x22f213('0x35')](_0x5cc82d['query']['limit']),_0x1834ad[_0x22f213('0x23')]=qs['offset'](_0x5cc82d[_0x22f213('0x32')][_0x22f213('0x23')]));_0x1834ad[_0x22f213('0x11')]=qs['sort'](_0x5cc82d[_0x22f213('0x32')][_0x22f213('0x31')]),_0x1834ad[_0x22f213('0x36')]=qs[_0x22f213('0x26')](_[_0x22f213('0x37')](_0x5cc82d[_0x22f213('0x32')],_0x40d510['filters']),_0x49cbbb);_0x5cc82d[_0x22f213('0x32')][_0x22f213('0x6')]&&(_0x1834ad[_0x22f213('0x36')]=_[_0x22f213('0x22')](_0x1834ad[_0x22f213('0x36')],{[Op['or']]:_[_0x22f213('0x29')](_0x49cbbb,function(_0x40e857){const _0x323bf8=_0x22f213;if(_0x40e857[_0x323bf8('0x33')]!=='VIRTUAL'){const _0x4c17d8={};return _0x4c17d8[_0x40e857[_0x323bf8('0x1c')]]={[Op[_0x323bf8('0x25')]]:'%'+_0x5cc82d[_0x323bf8('0x32')][_0x323bf8('0x6')]+'%'},_0x4c17d8;}})}));_0x1834ad=_['merge']({},_0x1834ad,_0x5cc82d[_0x22f213('0x0')]);const _0x145fe8={'where':_0x1834ad[_0x22f213('0x36')]};return db[_0x22f213('0x30')][_0x22f213('0x1d')](_0x145fe8)[_0x22f213('0x10')](function(_0x362955){const _0x24bfd1=_0x22f213;return _0x495145[_0x24bfd1('0x1d')]=_0x362955,_0x5cc82d['query'][_0x24bfd1('0x2a')]&&(_0x1834ad['include']=[{'all':!![]}]),db[_0x24bfd1('0x30')][_0x24bfd1('0x1f')](_0x1834ad);})['then'](function(_0x59d9cc){const _0x11724e=_0x22f213;return _0x495145[_0x11724e('0x4')]=_0x59d9cc,_0x495145;})[_0x22f213('0x10')](respondWithFilteredResult(_0xa5e2ab,_0x1834ad))[_0x22f213('0x27')](handleError(_0xa5e2ab,null));},exports[_0x1721e6('0x20')]=function(_0x46539d,_0x19af05){const _0x55eb8f=_0x1721e6;let _0x4cf602={'raw':!![],'where':{'id':_0x46539d[_0x55eb8f('0x3')]['id']}};const _0x2257c4={};return _0x2257c4[_0x55eb8f('0x19')]=_[_0x55eb8f('0xf')](db[_0x55eb8f('0x30')][_0x55eb8f('0x24')]),_0x2257c4[_0x55eb8f('0x32')]=_['keys'](_0x46539d[_0x55eb8f('0x32')]),_0x2257c4['filters']=_[_0x55eb8f('0x2e')](_0x2257c4[_0x55eb8f('0x19')],_0x2257c4['query']),_0x4cf602[_0x55eb8f('0x34')]=_[_0x55eb8f('0x2e')](_0x2257c4['model'],qs[_0x55eb8f('0x2b')](_0x46539d[_0x55eb8f('0x32')][_0x55eb8f('0x2b')])),_0x4cf602[_0x55eb8f('0x34')]=_0x4cf602['attributes'][_0x55eb8f('0x3a')]?_0x4cf602[_0x55eb8f('0x34')]:_0x2257c4[_0x55eb8f('0x19')],_0x46539d[_0x55eb8f('0x32')]['includeAll']&&(_0x4cf602[_0x55eb8f('0x17')]=[{'all':!![]}]),_0x4cf602=_[_0x55eb8f('0x22')]({},_0x4cf602,_0x46539d[_0x55eb8f('0x0')]),db['Variable'][_0x55eb8f('0xa')](_0x4cf602)[_0x55eb8f('0x10')](handleEntityNotFound(_0x19af05,null))[_0x55eb8f('0x10')](respondWithResult(_0x19af05,null))['catch'](handleError(_0x19af05,null));},exports['create']=function(_0x4879ad,_0x309433){const _0x5370ac=_0x1721e6;return db[_0x5370ac('0x30')][_0x5370ac('0x14')](_0x4879ad['body'],{})[_0x5370ac('0x10')](function(_0x38d221){const _0x4c375b=_0x5370ac,_0x2d2506=_0x4879ad[_0x4c375b('0x1e')][_0x4c375b('0x5')]({'plain':!![]});if(!_0x2d2506)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x2d2506[_0x4c375b('0x39')]===_0x4c375b('0x1e')){const _0x51da1d=_0x38d221['get']({'plain':!![]}),_0x21b941=_0x4c375b('0x15');return db[_0x4c375b('0x12')][_0x4c375b('0xa')]({'where':{'name':_0x21b941,'userProfileId':_0x2d2506[_0x4c375b('0x2f')]},'raw':!![]})['then'](function(_0x185242){const _0x3de657=_0x4c375b;return _0x185242&&_0x185242[_0x3de657('0x38')]===0x0?db[_0x3de657('0xd')][_0x3de657('0x14')]({'name':_0x51da1d[_0x3de657('0x1c')],'resourceId':_0x51da1d['id'],'type':_0x185242[_0x3de657('0x1c')],'sectionId':_0x185242['id']},{})[_0x3de657('0x10')](function(){return _0x38d221;}):_0x38d221;})[_0x4c375b('0x27')](function(_0x3fbd36){const _0x329312=_0x4c375b;logger[_0x329312('0x9')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x3fbd36);throw _0x3fbd36;});}return _0x38d221;})['then'](respondWithResult(_0x309433,0xc9))[_0x5370ac('0x27')](handleError(_0x309433,null));},exports[_0x1721e6('0x8')]=function(_0x2941b9,_0x5091e8){const _0x75ba32=_0x1721e6;return _0x2941b9[_0x75ba32('0xe')]['id']&&delete _0x2941b9['body']['id'],db[_0x75ba32('0x30')]['findOne']({'where':{'id':_0x2941b9[_0x75ba32('0x3')]['id']}})[_0x75ba32('0x10')](handleEntityNotFound(_0x5091e8,null))[_0x75ba32('0x10')](saveUpdates(_0x2941b9['body'],null))[_0x75ba32('0x10')](respondWithResult(_0x5091e8,null))[_0x75ba32('0x27')](handleError(_0x5091e8,null));},exports[_0x1721e6('0x13')]=function(_0xc95a09,_0x2a4be6){const _0x366472=_0x1721e6;return db[_0x366472('0x30')][_0x366472('0xa')]({'where':{'id':_0xc95a09[_0x366472('0x3')]['id']}})[_0x366472('0x10')](handleEntityNotFound(_0x2a4be6,null))['then'](removeEntity(_0x2a4be6,null))[_0x366472('0x27')](handleError(_0x2a4be6,null));};