a7278e7341496fcc03fdf90bd88d01dca66ae27f
[motion-next.git] / server / api / squareOdbc / squareOdbc.controller.js
1 const a593_0x118e=['where','include','body','limit','attributes','create','set','openSync','options','index','api','autoAssociation','UserProfileSection','catch','filters','Content-Range','map','filter','destroy','dsn','findOne','send','json','sort','role','query','intersection','../../mysqldb','model','keys','then','count','pick','ODBC','get','rawAttributes','key','../../components/parsers/qs','findAll','user','status','lodash','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileResource','closeSync','name','like','offset','end','includeAll','update','SquareOdbc','fields','type','sequelize','params','undefined','sendStatus','order','length','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s'];(function(_0x34969c,_0x118e49){const _0x5e06ff=function(_0x23066c){while(--_0x23066c){_0x34969c['push'](_0x34969c['shift']());}};_0x5e06ff(++_0x118e49);}(a593_0x118e,0x17a));const a593_0x5e06=function(_0x34969c,_0x118e49){_0x34969c=_0x34969c-0x0;let _0x5e06ff=a593_0x118e[_0x34969c];return _0x5e06ff;};const _0x34aa90=a593_0x5e06;'use strict';const _=require(_0x34aa90('0x1d')),qs=require(_0x34aa90('0x19')),logger=require('../../config/logger')(_0x34aa90('0x3b')),db=require(_0x34aa90('0xf'))['db'],{Op}=require(_0x34aa90('0x2a'));function respondWithResult(_0x23066c,_0x2a024e){return _0x2a024e=_0x2a024e||0xc8,function(_0x1bc599){const _0x1378b8=a593_0x5e06;if(_0x1bc599)return _0x23066c[_0x1378b8('0x1c')](_0x2a024e)[_0x1378b8('0xa')](_0x1bc599);};}function respondWithFilteredResult(_0xff4a15,_0x4c9204){return function(_0x37b73d){const _0xde7ddc=a593_0x5e06;if(_0x37b73d){const _0x2766b3=_0x37b73d[_0xde7ddc('0x13')],_0x509a16=_0x4c9204['offset'];let _0x2c4f5c=_0x4c9204[_0xde7ddc('0x23')]+_0x4c9204[_0xde7ddc('0x34')],_0x3a46e6;return _0x2c4f5c>=_0x2766b3?(_0x2c4f5c=_0x2766b3,_0x3a46e6=0xc8):_0x3a46e6=0xce,_0xff4a15[_0xde7ddc('0x1c')](_0x3a46e6),_0xff4a15[_0xde7ddc('0x37')](_0xde7ddc('0x3'),_0x509a16+'-'+_0x2c4f5c+'/'+_0x2766b3)[_0xde7ddc('0xa')](_0x37b73d);}return null;};}function saveUpdates(_0x5a7080){return function(_0x42a6b2){const _0x301b73=a593_0x5e06;if(_0x42a6b2)return _0x42a6b2[_0x301b73('0x26')](_0x5a7080)[_0x301b73('0x12')](function(_0x3eb125){return _0x3eb125;});return null;};}function removeEntity(_0x3bec09){return function(_0x33c800){const _0x6c1937=a593_0x5e06;if(_0x33c800)return _0x33c800['destroy']()[_0x6c1937('0x12')](function(){const _0x3e6ac3=_0x6c1937,_0x1fd04f=_0x33c800[_0x3e6ac3('0x16')]({'plain':!![]}),_0x13e9b1=_0x3e6ac3('0x15');return db['UserProfileResource'][_0x3e6ac3('0x6')]({'where':{'type':_0x13e9b1,'resourceId':_0x1fd04f['id']}})[_0x3e6ac3('0x12')](function(){return _0x33c800;});})[_0x6c1937('0x12')](function(){const _0x846df7=_0x6c1937;_0x3bec09[_0x846df7('0x1c')](0xcc)[_0x846df7('0x24')]();});};}function handleEntityNotFound(_0x385abd){return function(_0x39a198){const _0x266a15=a593_0x5e06;return!_0x39a198&&_0x385abd[_0x266a15('0x2d')](0x194),_0x39a198;};}function handleError(_0x58771b,_0x2b4043){return _0x2b4043=_0x2b4043||0x1f4,function(_0x345f94){const _0x28aae5=a593_0x5e06;logger['error'](_0x345f94['stack']),_0x345f94['name']&&delete _0x345f94[_0x28aae5('0x21')],_0x58771b[_0x28aae5('0x1c')](_0x2b4043)[_0x28aae5('0x9')](_0x345f94);};}exports[_0x34aa90('0x3a')]=function(_0x359c41,_0x278d41){const _0x36ec80=_0x34aa90;let _0x129502={};const _0x1549fe={},_0x3ac62f={'count':0x0,'rows':[]},_0x31cdbf=_['map'](db[_0x36ec80('0x27')][_0x36ec80('0x17')],function(_0x2cacea){const _0x780296=_0x36ec80;return{'name':_0x2cacea['fieldName'],'type':_0x2cacea['type'][_0x780296('0x18')]};});_0x1549fe['model']=_[_0x36ec80('0x4')](_0x31cdbf,'name'),_0x1549fe[_0x36ec80('0xd')]=_['keys'](_0x359c41['query']),_0x1549fe[_0x36ec80('0x2')]=_[_0x36ec80('0xe')](_0x1549fe['model'],_0x1549fe[_0x36ec80('0xd')]),_0x129502[_0x36ec80('0x35')]=_[_0x36ec80('0xe')](_0x1549fe['model'],qs['fields'](_0x359c41['query'][_0x36ec80('0x28')])),_0x129502[_0x36ec80('0x35')]=_0x129502[_0x36ec80('0x35')][_0x36ec80('0x2f')]?_0x129502[_0x36ec80('0x35')]:_0x1549fe[_0x36ec80('0x10')];typeof _0x359c41[_0x36ec80('0xd')]['nolimit']===_0x36ec80('0x2c')&&(_0x129502[_0x36ec80('0x34')]=qs[_0x36ec80('0x34')](_0x359c41['query']['limit']),_0x129502[_0x36ec80('0x23')]=qs[_0x36ec80('0x23')](_0x359c41[_0x36ec80('0xd')][_0x36ec80('0x23')]));_0x129502[_0x36ec80('0x2e')]=qs[_0x36ec80('0xb')](_0x359c41[_0x36ec80('0xd')][_0x36ec80('0xb')]),_0x129502[_0x36ec80('0x31')]=qs[_0x36ec80('0x2')](_[_0x36ec80('0x14')](_0x359c41[_0x36ec80('0xd')],_0x1549fe['filters']),_0x31cdbf);_0x359c41[_0x36ec80('0xd')][_0x36ec80('0x5')]&&(_0x129502[_0x36ec80('0x31')]=_['merge'](_0x129502[_0x36ec80('0x31')],{[Op['or']]:_[_0x36ec80('0x4')](_0x31cdbf,function(_0xf49a4c){const _0x599ef5=_0x36ec80;if(_0xf49a4c[_0x599ef5('0x29')]!=='VIRTUAL'){const _0x2e27eb={};return _0x2e27eb[_0xf49a4c['name']]={[Op[_0x599ef5('0x22')]]:'%'+_0x359c41[_0x599ef5('0xd')][_0x599ef5('0x5')]+'%'},_0x2e27eb;}})}));_0x129502=_['merge']({},_0x129502,_0x359c41[_0x36ec80('0x39')]);const _0x504ed6={'where':_0x129502[_0x36ec80('0x31')]};return db[_0x36ec80('0x27')][_0x36ec80('0x13')](_0x504ed6)['then'](function(_0x1c533e){const _0x236d0a=_0x36ec80;return _0x3ac62f['count']=_0x1c533e,_0x359c41[_0x236d0a('0xd')][_0x236d0a('0x25')]&&(_0x129502['include']=[{'all':!![]}]),db['SquareOdbc'][_0x236d0a('0x1a')](_0x129502);})['then'](function(_0x3543f8){return _0x3ac62f['rows']=_0x3543f8,_0x3ac62f;})[_0x36ec80('0x12')](respondWithFilteredResult(_0x278d41,_0x129502))[_0x36ec80('0x1')](handleError(_0x278d41,null));},exports['show']=function(_0x535705,_0x3529de){const _0x498649=_0x34aa90;let _0x1f83b5={'raw':!![],'where':{'id':_0x535705['params']['id']}};const _0x124dba={};return _0x124dba['model']=_[_0x498649('0x11')](db[_0x498649('0x27')][_0x498649('0x17')]),_0x124dba[_0x498649('0xd')]=_[_0x498649('0x11')](_0x535705[_0x498649('0xd')]),_0x124dba[_0x498649('0x2')]=_[_0x498649('0xe')](_0x124dba['model'],_0x124dba[_0x498649('0xd')]),_0x1f83b5[_0x498649('0x35')]=_['intersection'](_0x124dba[_0x498649('0x10')],qs[_0x498649('0x28')](_0x535705[_0x498649('0xd')][_0x498649('0x28')])),_0x1f83b5[_0x498649('0x35')]=_0x1f83b5['attributes'][_0x498649('0x2f')]?_0x1f83b5[_0x498649('0x35')]:_0x124dba[_0x498649('0x10')],_0x535705[_0x498649('0xd')][_0x498649('0x25')]&&(_0x1f83b5[_0x498649('0x32')]=[{'all':!![]}]),_0x1f83b5=_['merge']({},_0x1f83b5,_0x535705[_0x498649('0x39')]),db[_0x498649('0x27')][_0x498649('0x8')](_0x1f83b5)['then'](handleEntityNotFound(_0x3529de,null))[_0x498649('0x12')](respondWithResult(_0x3529de,null))[_0x498649('0x1')](handleError(_0x3529de,null));},exports[_0x34aa90('0x36')]=function(_0x29c814,_0x3d8300){const _0x13c2b4=_0x34aa90;return db[_0x13c2b4('0x27')][_0x13c2b4('0x36')](_0x29c814[_0x13c2b4('0x33')],{})[_0x13c2b4('0x12')](function(_0x13ef61){const _0x3ba95f=_0x13c2b4,_0x47b541=_0x29c814[_0x3ba95f('0x1b')][_0x3ba95f('0x16')]({'plain':!![]});if(!_0x47b541)throw new Error(_0x3ba95f('0x1e'));if(_0x47b541[_0x3ba95f('0xc')]==='user'){const _0x186648=_0x13ef61['get']({'plain':!![]}),_0x11652d=_0x3ba95f('0x15');return db[_0x3ba95f('0x0')][_0x3ba95f('0x8')]({'where':{'name':_0x11652d,'userProfileId':_0x47b541['userProfileId']},'raw':!![]})[_0x3ba95f('0x12')](function(_0x13403d){const _0x235df6=_0x3ba95f;return _0x13403d&&_0x13403d[_0x235df6('0x3c')]===0x0?db[_0x235df6('0x1f')][_0x235df6('0x36')]({'name':_0x186648[_0x235df6('0x21')],'resourceId':_0x186648['id'],'type':_0x13403d[_0x235df6('0x21')],'sectionId':_0x13403d['id']},{})[_0x235df6('0x12')](function(){return _0x13ef61;}):_0x13ef61;})[_0x3ba95f('0x1')](function(_0x30c99f){const _0x332927=_0x3ba95f;logger['error'](_0x332927('0x30'),_0x30c99f);throw _0x30c99f;});}return _0x13ef61;})[_0x13c2b4('0x12')](respondWithResult(_0x3d8300,0xc9))['catch'](handleError(_0x3d8300,null));},exports['update']=function(_0x5be231,_0x2aa281){const _0x55fbd7=_0x34aa90;return _0x5be231[_0x55fbd7('0x33')]['id']&&delete _0x5be231[_0x55fbd7('0x33')]['id'],db['SquareOdbc'][_0x55fbd7('0x8')]({'where':{'id':_0x5be231['params']['id']}})[_0x55fbd7('0x12')](handleEntityNotFound(_0x2aa281,null))[_0x55fbd7('0x12')](saveUpdates(_0x5be231[_0x55fbd7('0x33')],null))['then'](respondWithResult(_0x2aa281,null))[_0x55fbd7('0x1')](handleError(_0x2aa281,null));},exports[_0x34aa90('0x6')]=function(_0x14bd70,_0x4b593f){const _0x32df7b=_0x34aa90;return db['SquareOdbc']['findOne']({'where':{'id':_0x14bd70[_0x32df7b('0x2b')]['id']}})[_0x32df7b('0x12')](handleEntityNotFound(_0x4b593f,null))[_0x32df7b('0x12')](removeEntity(_0x4b593f,null))['catch'](handleError(_0x4b593f,null));},exports['test']=function(_0xe63413,_0x5019a3){const _0x1556e8=_0x34aa90;return db[_0x1556e8('0x27')][_0x1556e8('0x8')]({'where':{'id':_0xe63413[_0x1556e8('0x2b')]['id']},'attributes':['id',_0x1556e8('0x7')]})[_0x1556e8('0x12')](handleEntityNotFound(_0x5019a3,null))[_0x1556e8('0x12')](function(_0x118789){const _0x1847ef=_0x1556e8;if(_0x118789){const _0x15262a=require('odbc')();return _0x15262a[_0x1847ef('0x38')](_0x118789[_0x1847ef('0x7')]),_0x15262a[_0x1847ef('0x20')](),_0x118789;}})['then'](respondWithResult(_0x5019a3,null))[_0x1556e8('0x1')](handleError(_0x5019a3,null));};