mirror of https://github.com/xfarrow/blink
fix route handling
This commit is contained in:
parent
bb4749f874
commit
d76a0d056a
|
@ -54,14 +54,12 @@ app.use(rateLimit({
|
|||
===== BEGIN ROUTE HANDLING =====
|
||||
*/
|
||||
|
||||
// app.use('/api', personRoutes.publicRoutes);
|
||||
// app.use('/api', personRoutes.protectedRoutes);
|
||||
app.use('/api', jobOffersRoutes.publicRoutes);
|
||||
app.use('/api', jobOffersRoutes.protectedRoutes);
|
||||
app.use('/api', organizationRoutes.publicRoutes);
|
||||
app.use('/api', organizationRoutes.protectedRoutes);
|
||||
// app.use('/api', organizationPostRoutes.protectedRoutes);
|
||||
// app.use('/api', organizationAdminRoutes.protectedRoutes);
|
||||
app.use('/api/persons', personRoutes.publicRoutes);
|
||||
app.use('/api/persons', personRoutes.protectedRoutes);
|
||||
app.use('/api/organizations', organizationRoutes.routes);
|
||||
app.use('/api/organizations', jobOffersRoutes.routes);
|
||||
app.use('/api/organizations', organizationAdminRoutes.routes);
|
||||
app.use('/api/organizations', organizationPostRoutes.routes);
|
||||
|
||||
/*
|
||||
===== END ROUTE HANDLING =====
|
||||
|
|
|
@ -76,7 +76,6 @@ async function findByOrganizationId(organizationId){
|
|||
const result = await knex('JobOffer')
|
||||
.where({organization_id: organizationId})
|
||||
.select();
|
||||
console.log(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -98,15 +98,11 @@ async function findByOrganizationId(req, res) {
|
|||
}
|
||||
}
|
||||
|
||||
const publicRoutes = express.Router();
|
||||
publicRoutes.get('/organizations/:id/joboffers', findByOrganizationId);
|
||||
|
||||
const protectedRoutes = express.Router();
|
||||
protectedRoutes.use(jwtUtils.verifyToken);
|
||||
protectedRoutes.post('/organizations/:id/joboffers', insert);
|
||||
protectedRoutes.delete('/organizations/joboffers/:jobOfferId', remove);
|
||||
const routes = express.Router();
|
||||
routes.get('/:id/joboffers', findByOrganizationId);
|
||||
routes.post('/:id/joboffers', jwtUtils.verifyToken, insert);
|
||||
routes.delete('/joboffers/:jobOfferId', jwtUtils.verifyToken, remove);
|
||||
|
||||
module.exports = {
|
||||
publicRoutes,
|
||||
protectedRoutes
|
||||
routes
|
||||
}
|
|
@ -65,7 +65,7 @@ async function removeOrganizationAdmin(req, res) {
|
|||
});
|
||||
}
|
||||
const success = await organizationAdmin.remove(req.jwt.person_id, req.params.organizationId);
|
||||
if(success){
|
||||
if (success) {
|
||||
return res.status(204).send();
|
||||
}
|
||||
return res.status(404).send();
|
||||
|
@ -77,11 +77,10 @@ async function removeOrganizationAdmin(req, res) {
|
|||
}
|
||||
}
|
||||
|
||||
const protectedRoutes = express.Router();
|
||||
protectedRoutes.use(jwtUtils.verifyToken);
|
||||
protectedRoutes.post('/organizations/:organizationId/admins', organizationAdminValidator.addOrganizationAdminValidator, addOrganizationAdmin);
|
||||
protectedRoutes.delete('/organizations/:organizationId/admins/me', organizationAdminValidator.removeOrganizationAdminValidator, removeOrganizationAdmin);
|
||||
const routes = express.Router();
|
||||
routes.post('/:organizationId/admins', jwtUtils.verifyToken, organizationAdminValidator.addOrganizationAdminValidator, addOrganizationAdmin);
|
||||
routes.delete('/:organizationId/admins/me', jwtUtils.verifyToken, organizationAdminValidator.removeOrganizationAdminValidator, removeOrganizationAdmin);
|
||||
|
||||
module.exports = {
|
||||
protectedRoutes
|
||||
routes
|
||||
};
|
|
@ -94,14 +94,13 @@ async function deleteOrganizationPost(req, res) {
|
|||
}
|
||||
}
|
||||
|
||||
const protectedRoutes = express.Router();
|
||||
protectedRoutes.use(jwtUtils.verifyToken);
|
||||
protectedRoutes.post('/organizations/:idOrganization/posts', createOrganizationPost);
|
||||
protectedRoutes.delete('/organizations/posts/:id', deleteOrganizationPost);
|
||||
const routes = express.Router();
|
||||
routes.post('/:idOrganization/posts', jwtUtils.verifyToken, createOrganizationPost);
|
||||
routes.delete('/posts/:id', jwtUtils.verifyToken, deleteOrganizationPost);
|
||||
|
||||
// Exporting a function
|
||||
// means making a JavaScript function defined in one
|
||||
// module available for use in another module.
|
||||
module.exports = {
|
||||
protectedRoutes
|
||||
routes
|
||||
};
|
|
@ -163,16 +163,15 @@ async function getOrganization(req, res) {
|
|||
}
|
||||
}
|
||||
|
||||
const publicRoutes = express.Router();
|
||||
publicRoutes.get('/organizations/:id', organizationValidator.deleteOrGetOrganizationValidator, getOrganization);
|
||||
|
||||
const protectedRoutes = express.Router();
|
||||
protectedRoutes.use(jwtUtils.verifyToken);
|
||||
protectedRoutes.post('/organizations', organizationValidator.createOrganizationValidator, createOrganization);
|
||||
protectedRoutes.patch('/organizations/:id', organizationValidator.updateOrganizationValidator, updateOrganization);
|
||||
protectedRoutes.delete('/organizations/:id', organizationValidator.deleteOrGetOrganizationValidator, deleteOrganization);
|
||||
// Here we can not use the jwtUtils.verifyToken as the Router's middleware directly, as the latter
|
||||
// will be mounted under /organizations, but there are other resources under /organizations
|
||||
// that do not require the authorization, e.g. job offers
|
||||
const routes = express.Router();
|
||||
routes.get('/:id', organizationValidator.deleteOrGetOrganizationValidator, getOrganization);
|
||||
routes.post('/', jwtUtils.verifyToken, organizationValidator.createOrganizationValidator, createOrganization);
|
||||
routes.patch('/:id', jwtUtils.verifyToken, organizationValidator.updateOrganizationValidator, updateOrganization);
|
||||
routes.delete('/:id', jwtUtils.verifyToken, organizationValidator.deleteOrGetOrganizationValidator, deleteOrganization);
|
||||
|
||||
module.exports = {
|
||||
publicRoutes,
|
||||
protectedRoutes
|
||||
routes
|
||||
};
|
|
@ -80,7 +80,7 @@ async function registerPerson(req, res) {
|
|||
mailUtils.sendConfirmationLink(req.body.email, activationCode);
|
||||
}
|
||||
|
||||
res.set('Location', `/api/persons/${insertedPerson.id}/details`);
|
||||
res.set('Location', `/api/${insertedPerson.id}/details`);
|
||||
return res.status(201).json(insertedPerson);
|
||||
|
||||
} catch (error) {
|
||||
|
@ -323,16 +323,16 @@ async function confirmActivation(req, res) {
|
|||
}
|
||||
|
||||
const publicRoutes = express.Router(); // Routes not requiring token
|
||||
publicRoutes.post('/persons', personValidator.registerValidator, registerPerson);
|
||||
publicRoutes.post('/persons/me/token', personValidator.getTokenValidator, createToken);
|
||||
publicRoutes.get('/persons/:id/details', getPerson);
|
||||
publicRoutes.post('/persons/me/activation', personValidator.confirmActivationValidator, confirmActivation);
|
||||
publicRoutes.post('/', personValidator.registerValidator, registerPerson);
|
||||
publicRoutes.post('/me/token', personValidator.getTokenValidator, createToken);
|
||||
publicRoutes.get('/:id/details', getPerson);
|
||||
publicRoutes.post('/me/activation', personValidator.confirmActivationValidator, confirmActivation);
|
||||
|
||||
const protectedRoutes = express.Router(); // Routes requiring token
|
||||
protectedRoutes.use(jwtUtils.verifyToken);
|
||||
protectedRoutes.get('/persons/me', getMyself);
|
||||
protectedRoutes.patch('/persons/me', personValidator.updatePersonValidator, updatePerson);
|
||||
protectedRoutes.delete('/persons/me', deletePerson);
|
||||
protectedRoutes.get('/me', getMyself);
|
||||
protectedRoutes.patch('/me', personValidator.updatePersonValidator, updatePerson);
|
||||
protectedRoutes.delete('/me', deletePerson);
|
||||
|
||||
// Exporting a function
|
||||
// means making a JavaScript function defined in one
|
||||
|
|
Loading…
Reference in New Issue