mirror of https://github.com/xfarrow/blink
update
This commit is contained in:
parent
ba4f1a5d8b
commit
b9545a1f80
|
@ -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 =====
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -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
|
||||||
|
};
|
Loading…
Reference in New Issue