249e4160b348141aa479ffe84b6f2b02c80956a0
[motion-next.git] / server / api / squareOdbc / squareOdbc.controller.js
1 const a593_0x465c=['sort','lodash','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','catch','odbc','json','offset','rows','order','get','keys','includeAll','options','intersection','nolimit','count','status','UserProfileResource','ODBC','update','where','send','pick','include','stack','error','like','limit','set','params','create','then','dsn','fields','merge','filters','query','show','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','openSync','filter','SquareOdbc','attributes','Content-Range','api','type','closeSync','../../config/logger','../../mysqldb','end','../../components/parsers/qs','user','findAll','length','destroy','map','test','name','role','UserProfileSection','model','undefined','findOne'];(function(_0x687286,_0x465cd4){const _0x193a1a=function(_0x3c3b42){while(--_0x3c3b42){_0x687286['push'](_0x687286['shift']());}};_0x193a1a(++_0x465cd4);}(a593_0x465c,0x15a));const a593_0x193a=function(_0x687286,_0x465cd4){_0x687286=_0x687286-0x0;let _0x193a1a=a593_0x465c[_0x687286];return _0x193a1a;};const _0x4f70e8=a593_0x193a;'use strict';const _=require(_0x4f70e8('0x27')),qs=require(_0x4f70e8('0x19')),logger=require(_0x4f70e8('0x16'))(_0x4f70e8('0x13')),db=require(_0x4f70e8('0x17'))['db'],{Op}=require('sequelize');function respondWithResult(_0x3c3b42,_0x176d5a){return _0x176d5a=_0x176d5a||0xc8,function(_0x12b6ef){const _0x44b6ea=a593_0x193a;if(_0x12b6ef)return _0x3c3b42[_0x44b6ea('0x36')](_0x176d5a)['json'](_0x12b6ef);};}function respondWithFilteredResult(_0x87a083,_0x385169){return function(_0x479b9b){const _0xd918e6=a593_0x193a;if(_0x479b9b){const _0x1c4020=_0x479b9b[_0xd918e6('0x35')],_0x457a01=_0x385169['offset'];let _0x52c602=_0x385169[_0xd918e6('0x2c')]+_0x385169['limit'],_0x49ae06;return _0x52c602>=_0x1c4020?(_0x52c602=_0x1c4020,_0x49ae06=0xc8):_0x49ae06=0xce,_0x87a083['status'](_0x49ae06),_0x87a083[_0xd918e6('0x2')](_0xd918e6('0x12'),_0x457a01+'-'+_0x52c602+'/'+_0x1c4020)[_0xd918e6('0x2b')](_0x479b9b);}return null;};}function saveUpdates(_0x11e5d7){return function(_0x3d4461){const _0x53a8c1=a593_0x193a;if(_0x3d4461)return _0x3d4461[_0x53a8c1('0x39')](_0x11e5d7)['then'](function(_0x1a48a6){return _0x1a48a6;});return null;};}function removeEntity(_0x166314){return function(_0x1e7ce7){const _0x48d63b=a593_0x193a;if(_0x1e7ce7)return _0x1e7ce7[_0x48d63b('0x1d')]()[_0x48d63b('0x5')](function(){const _0x29898d=_0x48d63b,_0x4c124c=_0x1e7ce7[_0x29898d('0x2f')]({'plain':!![]}),_0xa8f299=_0x29898d('0x38');return db[_0x29898d('0x37')][_0x29898d('0x1d')]({'where':{'type':_0xa8f299,'resourceId':_0x4c124c['id']}})[_0x29898d('0x5')](function(){return _0x1e7ce7;});})['then'](function(){const _0x494f41=_0x48d63b;_0x166314[_0x494f41('0x36')](0xcc)[_0x494f41('0x18')]();});};}function handleEntityNotFound(_0x3214b6){return function(_0x1ce084){return!_0x1ce084&&_0x3214b6['sendStatus'](0x194),_0x1ce084;};}function handleError(_0x27ef37,_0xe862b9){return _0xe862b9=_0xe862b9||0x1f4,function(_0x2b99ba){const _0x555805=a593_0x193a;logger[_0x555805('0x3f')](_0x2b99ba[_0x555805('0x3e')]),_0x2b99ba['name']&&delete _0x2b99ba[_0x555805('0x20')],_0x27ef37[_0x555805('0x36')](_0xe862b9)[_0x555805('0x3b')](_0x2b99ba);};}exports['index']=function(_0x559069,_0x28534f){const _0x41aee5=_0x4f70e8;let _0x3e8189={};const _0x4c13bc={},_0x398d3d={'count':0x0,'rows':[]},_0x3f69ce=_[_0x41aee5('0x1e')](db[_0x41aee5('0x10')]['rawAttributes'],function(_0x59c079){return{'name':_0x59c079['fieldName'],'type':_0x59c079['type']['key']};});_0x4c13bc[_0x41aee5('0x23')]=_[_0x41aee5('0x1e')](_0x3f69ce,_0x41aee5('0x20')),_0x4c13bc[_0x41aee5('0xa')]=_[_0x41aee5('0x30')](_0x559069[_0x41aee5('0xa')]),_0x4c13bc[_0x41aee5('0x9')]=_[_0x41aee5('0x33')](_0x4c13bc[_0x41aee5('0x23')],_0x4c13bc[_0x41aee5('0xa')]),_0x3e8189[_0x41aee5('0x11')]=_['intersection'](_0x4c13bc['model'],qs[_0x41aee5('0x7')](_0x559069[_0x41aee5('0xa')][_0x41aee5('0x7')])),_0x3e8189[_0x41aee5('0x11')]=_0x3e8189[_0x41aee5('0x11')]['length']?_0x3e8189[_0x41aee5('0x11')]:_0x4c13bc[_0x41aee5('0x23')];typeof _0x559069[_0x41aee5('0xa')][_0x41aee5('0x34')]===_0x41aee5('0x24')&&(_0x3e8189[_0x41aee5('0x1')]=qs[_0x41aee5('0x1')](_0x559069[_0x41aee5('0xa')]['limit']),_0x3e8189[_0x41aee5('0x2c')]=qs['offset'](_0x559069['query'][_0x41aee5('0x2c')]));_0x3e8189[_0x41aee5('0x2e')]=qs[_0x41aee5('0x26')](_0x559069['query']['sort']),_0x3e8189['where']=qs[_0x41aee5('0x9')](_[_0x41aee5('0x3c')](_0x559069['query'],_0x4c13bc[_0x41aee5('0x9')]),_0x3f69ce);_0x559069[_0x41aee5('0xa')][_0x41aee5('0xf')]&&(_0x3e8189[_0x41aee5('0x3a')]=_[_0x41aee5('0x8')](_0x3e8189['where'],{[Op['or']]:_[_0x41aee5('0x1e')](_0x3f69ce,function(_0x3bc552){const _0x5cd749=_0x41aee5;if(_0x3bc552[_0x5cd749('0x14')]!=='VIRTUAL'){const _0x460e95={};return _0x460e95[_0x3bc552[_0x5cd749('0x20')]]={[Op[_0x5cd749('0x0')]]:'%'+_0x559069[_0x5cd749('0xa')]['filter']+'%'},_0x460e95;}})}));_0x3e8189=_['merge']({},_0x3e8189,_0x559069[_0x41aee5('0x32')]);const _0x55a610={'where':_0x3e8189[_0x41aee5('0x3a')]};return db[_0x41aee5('0x10')][_0x41aee5('0x35')](_0x55a610)[_0x41aee5('0x5')](function(_0x2862af){const _0x46bb95=_0x41aee5;return _0x398d3d[_0x46bb95('0x35')]=_0x2862af,_0x559069[_0x46bb95('0xa')][_0x46bb95('0x31')]&&(_0x3e8189[_0x46bb95('0x3d')]=[{'all':!![]}]),db[_0x46bb95('0x10')][_0x46bb95('0x1b')](_0x3e8189);})[_0x41aee5('0x5')](function(_0x16f04a){const _0x108750=_0x41aee5;return _0x398d3d[_0x108750('0x2d')]=_0x16f04a,_0x398d3d;})[_0x41aee5('0x5')](respondWithFilteredResult(_0x28534f,_0x3e8189))['catch'](handleError(_0x28534f,null));},exports[_0x4f70e8('0xb')]=function(_0x322810,_0x465f09){const _0x2ab58e=_0x4f70e8;let _0x4e8f4a={'raw':!![],'where':{'id':_0x322810[_0x2ab58e('0x3')]['id']}};const _0x5cf8cc={};return _0x5cf8cc[_0x2ab58e('0x23')]=_['keys'](db[_0x2ab58e('0x10')]['rawAttributes']),_0x5cf8cc[_0x2ab58e('0xa')]=_[_0x2ab58e('0x30')](_0x322810['query']),_0x5cf8cc[_0x2ab58e('0x9')]=_['intersection'](_0x5cf8cc['model'],_0x5cf8cc[_0x2ab58e('0xa')]),_0x4e8f4a[_0x2ab58e('0x11')]=_['intersection'](_0x5cf8cc[_0x2ab58e('0x23')],qs[_0x2ab58e('0x7')](_0x322810[_0x2ab58e('0xa')][_0x2ab58e('0x7')])),_0x4e8f4a[_0x2ab58e('0x11')]=_0x4e8f4a['attributes'][_0x2ab58e('0x1c')]?_0x4e8f4a[_0x2ab58e('0x11')]:_0x5cf8cc[_0x2ab58e('0x23')],_0x322810[_0x2ab58e('0xa')]['includeAll']&&(_0x4e8f4a[_0x2ab58e('0x3d')]=[{'all':!![]}]),_0x4e8f4a=_['merge']({},_0x4e8f4a,_0x322810[_0x2ab58e('0x32')]),db[_0x2ab58e('0x10')][_0x2ab58e('0x25')](_0x4e8f4a)[_0x2ab58e('0x5')](handleEntityNotFound(_0x465f09,null))[_0x2ab58e('0x5')](respondWithResult(_0x465f09,null))['catch'](handleError(_0x465f09,null));},exports['create']=function(_0x225bb6,_0x438d94){const _0x108680=_0x4f70e8;return db[_0x108680('0x10')][_0x108680('0x4')](_0x225bb6[_0x108680('0xc')],{})['then'](function(_0x5a9127){const _0x2f05b8=_0x108680,_0xe02355=_0x225bb6[_0x2f05b8('0x1a')][_0x2f05b8('0x2f')]({'plain':!![]});if(!_0xe02355)throw new Error(_0x2f05b8('0xd'));if(_0xe02355[_0x2f05b8('0x21')]==='user'){const _0x11bd7e=_0x5a9127[_0x2f05b8('0x2f')]({'plain':!![]}),_0x41c69f=_0x2f05b8('0x38');return db[_0x2f05b8('0x22')]['findOne']({'where':{'name':_0x41c69f,'userProfileId':_0xe02355['userProfileId']},'raw':!![]})[_0x2f05b8('0x5')](function(_0x542566){const _0x151a99=_0x2f05b8;return _0x542566&&_0x542566['autoAssociation']===0x0?db[_0x151a99('0x37')][_0x151a99('0x4')]({'name':_0x11bd7e[_0x151a99('0x20')],'resourceId':_0x11bd7e['id'],'type':_0x542566['name'],'sectionId':_0x542566['id']},{})[_0x151a99('0x5')](function(){return _0x5a9127;}):_0x5a9127;})[_0x2f05b8('0x29')](function(_0x2dacc5){const _0x226716=_0x2f05b8;logger[_0x226716('0x3f')](_0x226716('0x28'),_0x2dacc5);throw _0x2dacc5;});}return _0x5a9127;})[_0x108680('0x5')](respondWithResult(_0x438d94,0xc9))['catch'](handleError(_0x438d94,null));},exports['update']=function(_0x37e503,_0x5d5f24){const _0x47d1c8=_0x4f70e8;return _0x37e503[_0x47d1c8('0xc')]['id']&&delete _0x37e503[_0x47d1c8('0xc')]['id'],db[_0x47d1c8('0x10')][_0x47d1c8('0x25')]({'where':{'id':_0x37e503['params']['id']}})[_0x47d1c8('0x5')](handleEntityNotFound(_0x5d5f24,null))['then'](saveUpdates(_0x37e503['body'],null))['then'](respondWithResult(_0x5d5f24,null))[_0x47d1c8('0x29')](handleError(_0x5d5f24,null));},exports[_0x4f70e8('0x1d')]=function(_0x474307,_0x4098f8){const _0x2029e1=_0x4f70e8;return db[_0x2029e1('0x10')][_0x2029e1('0x25')]({'where':{'id':_0x474307[_0x2029e1('0x3')]['id']}})['then'](handleEntityNotFound(_0x4098f8,null))[_0x2029e1('0x5')](removeEntity(_0x4098f8,null))[_0x2029e1('0x29')](handleError(_0x4098f8,null));},exports[_0x4f70e8('0x1f')]=function(_0x3fb052,_0x1acd45){const _0x315533=_0x4f70e8;return db[_0x315533('0x10')][_0x315533('0x25')]({'where':{'id':_0x3fb052[_0x315533('0x3')]['id']},'attributes':['id',_0x315533('0x6')]})['then'](handleEntityNotFound(_0x1acd45,null))[_0x315533('0x5')](function(_0x2a3e7f){const _0x2736f1=_0x315533;if(_0x2a3e7f){const _0xeee9be=require(_0x2736f1('0x2a'))();return _0xeee9be[_0x2736f1('0xe')](_0x2a3e7f['dsn']),_0xeee9be[_0x2736f1('0x15')](),_0x2a3e7f;}})[_0x315533('0x5')](respondWithResult(_0x1acd45,null))[_0x315533('0x29')](handleError(_0x1acd45,null));};