This commit is contained in:
xfarrow 2024-10-23 15:53:41 +02:00
parent ba4f1a5d8b
commit b9545a1f80
3 changed files with 88 additions and 0 deletions

View File

@ -26,6 +26,7 @@ const organizationAdminRoutes = require('./routes/organization_admin_routes.js')
const jobOffersRoutes = require('./routes/job_offer_routes.js'); const jobOffersRoutes = require('./routes/job_offer_routes.js');
const serverRoutes = require('./routes/server_routes.js'); const serverRoutes = require('./routes/server_routes.js');
const resetPasswordRoutes = require('./routes/reset_password_routes.js'); const resetPasswordRoutes = require('./routes/reset_password_routes.js');
const applicationRoutes = require('./routes/applicant_routes.js');
/* /*
===== END IMPORTING MODULES ===== ===== END IMPORTING MODULES =====
@ -55,6 +56,7 @@ app.use('/api/organizations', organizationRoutes.routes);
app.use('/api/organizations', jobOffersRoutes.routes); app.use('/api/organizations', jobOffersRoutes.routes);
app.use('/api/organizations', organizationAdminRoutes.routes); app.use('/api/organizations', organizationAdminRoutes.routes);
app.use('/api/resetpassword', resetPasswordRoutes.routes); app.use('/api/resetpassword', resetPasswordRoutes.routes);
app.use('/api/applications', applicationRoutes.routes);
/* /*
===== END ROUTE HANDLING ===== ===== END ROUTE HANDLING =====

View File

@ -0,0 +1,39 @@
/*
This code is part of Blink
licensed under GPLv3
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
const knex = require('../utils/knex_config');
async function insert(personId, jobOfferId) {
return await knex('Applicant')
.insert({
person_id: personId,
job_offer_id: jobOfferId
})
.returning("*");
}
async function userAlreadyApplicated(personId, jobOfferId){
const person = await knex('Applicant')
.where('person_id', personId)
.where('job_offer_id', jobOfferId)
.select('*')
.first();
if(person){
return true;
}
return false;
}
module.exports = {
insert,
userAlreadyApplicated
}

View File

@ -0,0 +1,47 @@
/*
This code is part of Blink
licensed under GPLv3
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
const Applicant = require('../models/applicant_model');
const express = require('express');
const jwtUtils = require('../utils/jwt_utils');
/**
* POST
* @param {*} req
* @param {*} res
* @returns
*/
async function insert(req, res) {
try {
if(await Applicant.userAlreadyApplicated(req.jwt.person_id, req.body.jobOfferId)){
return res.status(401).json({
error: 'User has already applied to this job'
});
}
const application = await Applicant.insert(req.jwt.person_id, req.body.jobOfferId);
res.set('Location', `/api/applications/${application.id}`);
return res.status(201).json(application);
} catch (error) {
console.error(`Error in function ${registerPerson.name}: ${error}`);
res.status(500).json({
error: 'Internal server error'
});
}
}
const routes = express.Router();
routes.post('/', jwtUtils.extractToken, insert);
module.exports = {
routes
};