From 0d1195f913d0f081a0fca033ed2c0d1fb2513cf8 Mon Sep 17 00:00:00 2001 From: xfarrow <49845537+xfarrow@users.noreply.github.com> Date: Wed, 30 Oct 2024 15:32:32 +0100 Subject: [PATCH] JobApplication completed --- .../src/routes/job_application_routes.js | 33 +++++++++++++++---- .../validators/job_application_validator.js | 18 +++++++++- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/backend/apis/nodejs/src/routes/job_application_routes.js b/backend/apis/nodejs/src/routes/job_application_routes.js index 8a2519d..c494417 100644 --- a/backend/apis/nodejs/src/routes/job_application_routes.js +++ b/backend/apis/nodejs/src/routes/job_application_routes.js @@ -165,6 +165,13 @@ async function getApplicationsByJobOffer(req, res) { */ async function getApplicationsByOrganization(req, res) { try { + const errors = jobApplicationValidator.validationResult(req); + if (!errors.isEmpty()) { + return res.status(400).json({ + errors: errors.array() + }); + } + const isAdmin = await OrganizationAdmin.isAdmin(req.jwt.person_id, req.params.idOrganization); if (!isAdmin) { return res.status(401).json({ @@ -188,6 +195,13 @@ async function getApplicationsByOrganization(req, res) { */ async function remove(req, res) { try { + const errors = jobApplicationValidator.validationResult(req); + if (!errors.isEmpty()) { + return res.status(400).json({ + errors: errors.array() + }); + } + const jobApplication = await Application.find(req.params.idApplication); if (jobApplication == null) { return res.status(404).send(); @@ -215,6 +229,13 @@ async function remove(req, res) { */ async function setStatus(req, res) { try { + const errors = jobApplicationValidator.validationResult(req); + if (!errors.isEmpty()) { + return res.status(400).json({ + errors: errors.array() + }); + } + const canPersonSetStatus = await Application.isPersonJobApplicationAdministrator(req.params.idApplication, req.jwt.person_id); if (!canPersonSetStatus) { return res.status(401).json({ @@ -233,12 +254,12 @@ async function setStatus(req, res) { const routes = express.Router(); routes.post('/joboffers/:idJobOffer/applications', jwtUtils.extractToken, jobApplicationValidator.insertValidator, insert); -routes.get('/joboffers/:idJobOffer/applications/:idApplication', jwtUtils.extractToken, find); -routes.get('/joboffers/applications/mine', jwtUtils.extractToken, myApplications); -routes.get('/joboffers/:idJobOffer/applications', jwtUtils.extractToken, getApplicationsByJobOffer); -routes.get('/:idOrganization/joboffers/applications', jwtUtils.extractToken, getApplicationsByOrganization); -routes.delete('/joboffers/applications/:idApplication', jwtUtils.extractToken, remove); -routes.patch('/joboffers/applications/:idApplication', jwtUtils.extractToken, setStatus); +routes.get('/joboffers/:idJobOffer/applications/:idApplication', jwtUtils.extractToken, jobApplicationValidator.findValidator, find); +routes.get('/joboffers/applications/mine', jwtUtils.extractToken, jobApplicationValidator.myApplicationsValidator, myApplications); +routes.get('/joboffers/:idJobOffer/applications', jwtUtils.extractToken, jobApplicationValidator.getApplicationsByJobOfferValidator, getApplicationsByJobOffer); +routes.get('/:idOrganization/joboffers/applications', jwtUtils.extractToken, jobApplicationValidator.getApplicationsByOrganizationValidator, getApplicationsByOrganization); +routes.delete('/joboffers/applications/:idApplication', jwtUtils.extractToken, jobApplicationValidator.removeValidator, remove); +routes.patch('/joboffers/applications/:idApplication', jwtUtils.extractToken, jobApplicationValidator.setStatusValidator, setStatus); module.exports = { routes diff --git a/backend/apis/nodejs/src/utils/validators/job_application_validator.js b/backend/apis/nodejs/src/utils/validators/job_application_validator.js index 38276bf..e587781 100644 --- a/backend/apis/nodejs/src/utils/validators/job_application_validator.js +++ b/backend/apis/nodejs/src/utils/validators/job_application_validator.js @@ -33,7 +33,20 @@ const myApplicationsValidator = [ ]; const getApplicationsByJobOfferValidator = [ - check('idJobOffer').optional().trim().escape().isInt() + check('idJobOffer').trim().escape().isInt() +]; + +const getApplicationsByOrganizationValidator = [ + check('idOrganization').trim().escape().isInt() +]; + +const removeValidator = [ + check('idApplication').trim().escape().isInt() +]; + +const setStatusValidator = [ + check('idApplication').trim().escape().isInt(), + check('status').trim().escape().isIn(['ACCEPTED', 'REJECTED']).withMessage('Invalid status. Status must be ACCEPTED or REJECTED') ]; module.exports = { @@ -41,5 +54,8 @@ module.exports = { findValidator, myApplicationsValidator, getApplicationsByJobOfferValidator, + getApplicationsByOrganizationValidator, + removeValidator, + setStatusValidator, validationResult } \ No newline at end of file