56fdc8184dc35973e3f99e5e5c9e170c0500e31e
[motion-next.git] / server / api / squareProject / squareProject.controller.js
1 const a598_0x32c8=['stack','findOne','includeAll','length','VIRTUAL','merge','../../config/logger','pick','nolimit','Unable\x20to\x20retrieve\x20the\x20current\x20user','keys','end','attributes','include','then','limit','User','userProfileId','filters','map','user','catch','get','set','query','emit','lodash','options','getUsers','intersection','status','rows','error','UserProfileResource','../../rediscache','SquareProject','fields','key','api','body','params','removeUsers','sort','json','type','model','offset','order','UserProfileSection','addUsers','index','filter','userSquareProject:remove','./squareProject.socket','autoAssociation','name','isArray','sendStatus','../../components/parsers/qs','like','undefined','send','register','create','SquareProjects','count','where','omit','role','Content-Range','update','ids'];(function(_0x576902,_0x32c82b){const _0x21d702=function(_0xd334d9){while(--_0xd334d9){_0x576902['push'](_0x576902['shift']());}};_0x21d702(++_0x32c82b);}(a598_0x32c8,0x14f));const a598_0x21d7=function(_0x576902,_0x32c82b){_0x576902=_0x576902-0x0;let _0x21d702=a598_0x32c8[_0x576902];return _0x21d702;};const _0x4193d2=a598_0x21d7;'use strict';const _=require(_0x4193d2('0x33')),qs=require(_0x4193d2('0xb')),logger=require(_0x4193d2('0x1f'))(_0x4193d2('0x3f')),{getSocket}=require(_0x4193d2('0x3b')),socket=getSocket(),db=require('../../mysqldb')['db'],{Op}=require('sequelize');require(_0x4193d2('0x6'))[_0x4193d2('0xf')](socket);function respondWithStatusCode(_0xd334d9,_0x52dd5a){return _0x52dd5a=_0x52dd5a||0xcc,function(_0x12180d){const _0x266bb5=a598_0x21d7;if(_0x12180d)return _0xd334d9[_0x266bb5('0xa')](_0x52dd5a);return _0xd334d9[_0x266bb5('0x37')](_0x52dd5a)[_0x266bb5('0x24')]();};}function respondWithResult(_0x4dace5,_0x3a6bd1){return _0x3a6bd1=_0x3a6bd1||0xc8,function(_0x442f20){const _0x4d6900=a598_0x21d7;if(_0x442f20)return _0x4dace5[_0x4d6900('0x37')](_0x3a6bd1)[_0x4d6900('0x44')](_0x442f20);};}function respondWithFilteredResult(_0x507d28,_0x2b5881){return function(_0x480653){const _0x5eafcf=a598_0x21d7;if(_0x480653){const _0x43ccbd=_0x480653['count'],_0x22d724=_0x2b5881[_0x5eafcf('0x47')];let _0x1bad9d=_0x2b5881['offset']+_0x2b5881[_0x5eafcf('0x28')],_0x4d358c;return _0x1bad9d>=_0x43ccbd?(_0x1bad9d=_0x43ccbd,_0x4d358c=0xc8):_0x4d358c=0xce,_0x507d28[_0x5eafcf('0x37')](_0x4d358c),_0x507d28[_0x5eafcf('0x30')](_0x5eafcf('0x16'),_0x22d724+'-'+_0x1bad9d+'/'+_0x43ccbd)[_0x5eafcf('0x44')](_0x480653);}return null;};}function saveUpdates(_0x1bcd83){return function(_0x61f8b9){if(_0x61f8b9)return _0x61f8b9['update'](_0x1bcd83)['then'](function(_0x50c52f){return _0x50c52f;});return null;};}function removeEntity(_0x5b34b0){return function(_0x3e1214){const _0x57596c=a598_0x21d7;if(_0x3e1214)return _0x3e1214['destroy']()[_0x57596c('0x27')](function(){const _0x1e8f50=_0x57596c,_0x1f2380=_0x3e1214[_0x1e8f50('0x2f')]({'plain':!![]}),_0x420b9e=_0x1e8f50('0x11');return db[_0x1e8f50('0x3a')]['destroy']({'where':{'type':_0x420b9e,'resourceId':_0x1f2380['id']}})[_0x1e8f50('0x27')](function(){return _0x3e1214;});})[_0x57596c('0x27')](function(){const _0x5b2490=_0x57596c;_0x5b34b0[_0x5b2490('0x37')](0xcc)[_0x5b2490('0x24')]();});};}function handleEntityNotFound(_0x3a361d){return function(_0x503959){return!_0x503959&&_0x3a361d['sendStatus'](0x194),_0x503959;};}function handleError(_0x3a659d,_0x4321f8){return _0x4321f8=_0x4321f8||0x1f4,function(_0x9073a8){const _0x221086=a598_0x21d7;logger[_0x221086('0x39')](_0x9073a8[_0x221086('0x19')]),_0x9073a8[_0x221086('0x8')]&&delete _0x9073a8[_0x221086('0x8')],_0x3a659d[_0x221086('0x37')](_0x4321f8)[_0x221086('0xe')](_0x9073a8);};}exports[_0x4193d2('0x3')]=function(_0x4783c3,_0x5256cd){const _0x4dde8b=_0x4193d2;let _0x311e0f={};const _0x414963={},_0x515466={'count':0x0,'rows':[]},_0x4b0177=_[_0x4dde8b('0x2c')](db[_0x4dde8b('0x3c')]['rawAttributes'],function(_0x212133){const _0x41a355=_0x4dde8b;return{'name':_0x212133['fieldName'],'type':_0x212133[_0x41a355('0x45')][_0x41a355('0x3e')]};});_0x414963[_0x4dde8b('0x46')]=_['map'](_0x4b0177,_0x4dde8b('0x8')),_0x414963[_0x4dde8b('0x31')]=_['keys'](_0x4783c3[_0x4dde8b('0x31')]),_0x414963['filters']=_['intersection'](_0x414963[_0x4dde8b('0x46')],_0x414963[_0x4dde8b('0x31')]),_0x311e0f[_0x4dde8b('0x25')]=_[_0x4dde8b('0x36')](_0x414963[_0x4dde8b('0x46')],qs[_0x4dde8b('0x3d')](_0x4783c3[_0x4dde8b('0x31')][_0x4dde8b('0x3d')])),_0x311e0f[_0x4dde8b('0x25')]=_0x311e0f[_0x4dde8b('0x25')][_0x4dde8b('0x1c')]?_0x311e0f[_0x4dde8b('0x25')]:_0x414963['model'];typeof _0x4783c3[_0x4dde8b('0x31')][_0x4dde8b('0x21')]===_0x4dde8b('0xd')&&(_0x311e0f['limit']=qs[_0x4dde8b('0x28')](_0x4783c3[_0x4dde8b('0x31')][_0x4dde8b('0x28')]),_0x311e0f[_0x4dde8b('0x47')]=qs['offset'](_0x4783c3[_0x4dde8b('0x31')][_0x4dde8b('0x47')]));_0x311e0f[_0x4dde8b('0x0')]=qs[_0x4dde8b('0x43')](_0x4783c3['query'][_0x4dde8b('0x43')]),_0x311e0f[_0x4dde8b('0x13')]=qs['filters'](_[_0x4dde8b('0x20')](_0x4783c3[_0x4dde8b('0x31')],_0x414963[_0x4dde8b('0x2b')]),_0x4b0177);_0x4783c3[_0x4dde8b('0x31')][_0x4dde8b('0x4')]&&(_0x311e0f[_0x4dde8b('0x13')]=_[_0x4dde8b('0x1e')](_0x311e0f[_0x4dde8b('0x13')],{[Op['or']]:_[_0x4dde8b('0x2c')](_0x4b0177,function(_0x37d8a4){const _0x220db9=_0x4dde8b;if(_0x37d8a4['type']!==_0x220db9('0x1d')){const _0x444d9a={};return _0x444d9a[_0x37d8a4[_0x220db9('0x8')]]={[Op[_0x220db9('0xc')]]:'%'+_0x4783c3[_0x220db9('0x31')]['filter']+'%'},_0x444d9a;}})}));_0x311e0f=_['merge']({},_0x311e0f,_0x4783c3[_0x4dde8b('0x34')]);const _0x3febfb={'where':_0x311e0f['where']};return db['SquareProject'][_0x4dde8b('0x12')](_0x3febfb)['then'](function(_0x1e8fe5){const _0xb7b21e=_0x4dde8b;return _0x515466['count']=_0x1e8fe5,_0x4783c3[_0xb7b21e('0x31')][_0xb7b21e('0x1b')]&&(_0x311e0f[_0xb7b21e('0x26')]=[{'all':!![]}]),db['SquareProject']['findAll'](_0x311e0f);})[_0x4dde8b('0x27')](function(_0x42f03b){const _0x318cd7=_0x4dde8b;return _0x515466[_0x318cd7('0x38')]=_0x42f03b,_0x515466;})[_0x4dde8b('0x27')](respondWithFilteredResult(_0x5256cd,_0x311e0f))['catch'](handleError(_0x5256cd,null));},exports['show']=function(_0x28dab3,_0x55b8a1){const _0x138c55=_0x4193d2;let _0x23a6fc={'raw':![],'where':{'id':_0x28dab3[_0x138c55('0x41')]['id']}};const _0x4709f7={};return _0x4709f7['model']=_[_0x138c55('0x23')](db['SquareProject']['rawAttributes']),_0x4709f7[_0x138c55('0x31')]=_[_0x138c55('0x23')](_0x28dab3[_0x138c55('0x31')]),_0x4709f7[_0x138c55('0x2b')]=_['intersection'](_0x4709f7['model'],_0x4709f7[_0x138c55('0x31')]),_0x23a6fc[_0x138c55('0x25')]=_[_0x138c55('0x36')](_0x4709f7[_0x138c55('0x46')],qs[_0x138c55('0x3d')](_0x28dab3[_0x138c55('0x31')][_0x138c55('0x3d')])),_0x23a6fc[_0x138c55('0x25')]=_0x23a6fc['attributes'][_0x138c55('0x1c')]?_0x23a6fc['attributes']:_0x4709f7['model'],_0x28dab3[_0x138c55('0x31')][_0x138c55('0x1b')]&&(_0x23a6fc[_0x138c55('0x26')]=[{'all':!![]}]),_0x23a6fc=_[_0x138c55('0x1e')]({},_0x23a6fc,_0x28dab3[_0x138c55('0x34')]),db['SquareProject'][_0x138c55('0x1a')](_0x23a6fc)[_0x138c55('0x27')](handleEntityNotFound(_0x55b8a1,null))[_0x138c55('0x27')](respondWithResult(_0x55b8a1,null))[_0x138c55('0x2e')](handleError(_0x55b8a1,null));},exports[_0x4193d2('0x10')]=function(_0x2ba71a,_0x534f11){const _0x3a325a=_0x4193d2;return db['SquareProject'][_0x3a325a('0x10')](_0x2ba71a[_0x3a325a('0x40')],{})[_0x3a325a('0x27')](function(_0x107b25){const _0x6fe8d9=_0x3a325a,_0x29e4ab=_0x2ba71a[_0x6fe8d9('0x2d')][_0x6fe8d9('0x2f')]({'plain':!![]});if(!_0x29e4ab)throw new Error(_0x6fe8d9('0x22'));if(_0x29e4ab[_0x6fe8d9('0x15')]===_0x6fe8d9('0x2d')){const _0x2bcf9e=_0x107b25[_0x6fe8d9('0x2f')]({'plain':!![]}),_0x596e28=_0x6fe8d9('0x11');return db[_0x6fe8d9('0x1')][_0x6fe8d9('0x1a')]({'where':{'name':_0x596e28,'userProfileId':_0x29e4ab[_0x6fe8d9('0x2a')]},'raw':!![]})[_0x6fe8d9('0x27')](function(_0x14701c){const _0x404fa4=_0x6fe8d9;return _0x14701c&&_0x14701c[_0x404fa4('0x7')]===0x0?db[_0x404fa4('0x3a')]['create']({'name':_0x2bcf9e[_0x404fa4('0x8')],'resourceId':_0x2bcf9e['id'],'type':_0x14701c['name'],'sectionId':_0x14701c['id']},{})[_0x404fa4('0x27')](function(){return _0x107b25;}):_0x107b25;})[_0x6fe8d9('0x2e')](function(_0xe7bb01){const _0x2a4d5d=_0x6fe8d9;logger[_0x2a4d5d('0x39')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0xe7bb01);throw _0xe7bb01;});}return _0x107b25;})['then'](respondWithResult(_0x534f11,0xc9))[_0x3a325a('0x2e')](handleError(_0x534f11,null));},exports[_0x4193d2('0x17')]=function(_0x4ad9db,_0x207da3){const _0x2b6296=_0x4193d2;return _0x4ad9db[_0x2b6296('0x40')]['id']&&delete _0x4ad9db['body']['id'],db[_0x2b6296('0x3c')]['findOne']({'where':{'id':_0x4ad9db[_0x2b6296('0x41')]['id']}})[_0x2b6296('0x27')](handleEntityNotFound(_0x207da3,null))[_0x2b6296('0x27')](saveUpdates(_0x4ad9db[_0x2b6296('0x40')],null))[_0x2b6296('0x27')](respondWithResult(_0x207da3,null))[_0x2b6296('0x2e')](handleError(_0x207da3,null));},exports['destroy']=function(_0x54d32d,_0xc6db4c){const _0x10d5ba=_0x4193d2;return db[_0x10d5ba('0x3c')][_0x10d5ba('0x1a')]({'where':{'id':_0x54d32d['params']['id']}})['then'](handleEntityNotFound(_0xc6db4c,null))['then'](removeEntity(_0xc6db4c,null))[_0x10d5ba('0x2e')](handleError(_0xc6db4c,null));},exports[_0x4193d2('0x2')]=function(_0x238a3d,_0x5f55aa){const _0x53bf0e=_0x4193d2;return db[_0x53bf0e('0x3c')][_0x53bf0e('0x1a')]({'where':{'id':_0x238a3d[_0x53bf0e('0x41')]['id']}})[_0x53bf0e('0x27')](function(_0xf26092){const _0xeec75d=_0x53bf0e;if(_0xf26092)return _0xf26092[_0xeec75d('0x2')](_0x238a3d[_0xeec75d('0x40')][_0xeec75d('0x18')],{'through':_[_0xeec75d('0x14')](_0x238a3d[_0xeec75d('0x40')],[_0xeec75d('0x18'),'id'])});})[_0x53bf0e('0x27')](respondWithResult(_0x5f55aa,null))[_0x53bf0e('0x2e')](handleError(_0x5f55aa,null));},exports[_0x4193d2('0x42')]=function(_0x611ceb,_0x2e304a){const _0x25d521=_0x4193d2;return db[_0x25d521('0x3c')][_0x25d521('0x1a')]({'where':{'id':_0x611ceb[_0x25d521('0x41')]['id']}})['then'](handleEntityNotFound(_0x2e304a,null))[_0x25d521('0x27')](function(_0x3f0c96){const _0x37f754=_0x25d521;if(_0x3f0c96)return _0x3f0c96[_0x37f754('0x42')](_0x611ceb['query'][_0x37f754('0x18')])['then'](function(){const _0x7d76bb=_0x37f754;if(_[_0x7d76bb('0x9')](_0x611ceb[_0x7d76bb('0x31')]['ids']))for(let _0xc7296b=0x0;_0xc7296b<_0x611ceb['query'][_0x7d76bb('0x18')][_0x7d76bb('0x1c')];_0xc7296b+=0x1){socket[_0x7d76bb('0x32')](_0x7d76bb('0x5'),{'UserId':Number(_0x611ceb[_0x7d76bb('0x31')][_0x7d76bb('0x18')][_0xc7296b]),'SquareProjectId':Number(_0x611ceb[_0x7d76bb('0x41')]['id'])});}else socket[_0x7d76bb('0x32')](_0x7d76bb('0x5'),{'UserId':Number(_0x611ceb[_0x7d76bb('0x31')][_0x7d76bb('0x18')]),'SquareProjectId':Number(_0x611ceb[_0x7d76bb('0x41')]['id'])});});})[_0x25d521('0x27')](respondWithStatusCode(_0x2e304a,null))[_0x25d521('0x2e')](handleError(_0x2e304a,null));},exports['getUsers']=function(_0x3d529b,_0x465dd2){const _0x2cd784=_0x4193d2;let _0xd7d860={};const _0x5f507d={};let _0x356717,_0x582b49;return db[_0x2cd784('0x3c')][_0x2cd784('0x1a')]({'where':{'id':_0x3d529b['params']['id']}})[_0x2cd784('0x27')](handleEntityNotFound(_0x465dd2,null))['then'](function(_0x72080a){const _0x3b21b7=_0x2cd784;if(_0x72080a)return _0x356717=_0x72080a,_0x5f507d[_0x3b21b7('0x46')]=_[_0x3b21b7('0x23')](db[_0x3b21b7('0x29')]['rawAttributes']),_0x5f507d[_0x3b21b7('0x31')]=_['keys'](_0x3d529b[_0x3b21b7('0x31')]),_0x5f507d[_0x3b21b7('0x2b')]=_['intersection'](_0x5f507d[_0x3b21b7('0x46')],_0x5f507d[_0x3b21b7('0x31')]),_0xd7d860['attributes']=_[_0x3b21b7('0x36')](_0x5f507d['model'],qs['fields'](_0x3d529b['query']['fields'])),_0xd7d860[_0x3b21b7('0x25')]=_0xd7d860[_0x3b21b7('0x25')][_0x3b21b7('0x1c')]?_0xd7d860[_0x3b21b7('0x25')]:_0x5f507d[_0x3b21b7('0x46')],_0xd7d860['order']=qs[_0x3b21b7('0x43')](_0x3d529b[_0x3b21b7('0x31')]['sort']),_0xd7d860[_0x3b21b7('0x13')]=qs['filters'](_[_0x3b21b7('0x20')](_0x3d529b['query'],_0x5f507d[_0x3b21b7('0x2b')])),_0x3d529b[_0x3b21b7('0x31')][_0x3b21b7('0x4')]&&(_0xd7d860[_0x3b21b7('0x13')]=_['merge'](_0xd7d860['where'],{[Op['or']]:_[_0x3b21b7('0x2c')](_0xd7d860[_0x3b21b7('0x25')],function(_0x449031){const _0x1068ae=_0x3b21b7,_0x3f1b9f={};return _0x3f1b9f[_0x449031]={[Op[_0x1068ae('0xc')]]:'%'+_0x3d529b['query'][_0x1068ae('0x4')]+'%'},_0x3f1b9f;})})),_0xd7d860=_[_0x3b21b7('0x1e')]({},_0xd7d860,_0x3d529b['options']),_0x356717[_0x3b21b7('0x35')](_0xd7d860);})['then'](function(_0x3e359d){const _0x5ee759=_0x2cd784;if(_0x3e359d)return _0x582b49=_0x3e359d[_0x5ee759('0x1c')],typeof _0x3d529b[_0x5ee759('0x31')]['nolimit']==='undefined'&&(_0xd7d860[_0x5ee759('0x28')]=qs[_0x5ee759('0x28')](_0x3d529b['query'][_0x5ee759('0x28')]),_0xd7d860[_0x5ee759('0x47')]=qs['offset'](_0x3d529b[_0x5ee759('0x31')][_0x5ee759('0x47')])),_0x356717[_0x5ee759('0x35')](_0xd7d860);})['then'](function(_0x488459){if(_0x488459)return _0x488459?{'count':_0x582b49,'rows':_0x488459}:null;})[_0x2cd784('0x27')](respondWithResult(_0x465dd2,null))[_0x2cd784('0x2e')](handleError(_0x465dd2,null));};