This commit is contained in:
xfarrow
2024-10-24 09:56:24 +02:00
parent b9545a1f80
commit 50a5f4f2c6
7 changed files with 112 additions and 54 deletions

View File

@ -12,8 +12,16 @@
*/
const knex = require('../utils/knex_config');
/**
* Inserts a new JobApplication.
*
* @param {*} personId The ID of the Person applying for the job
* @param {*} jobOfferId The ID of the job
* @returns The inserted JobApplication object if successful, throws an
* exception otherwise
*/
async function insert(personId, jobOfferId) {
return await knex('Applicant')
return await knex('JobApplication')
.insert({
person_id: personId,
job_offer_id: jobOfferId
@ -22,7 +30,7 @@ async function insert(personId, jobOfferId) {
}
async function userAlreadyApplicated(personId, jobOfferId){
const person = await knex('Applicant')
const person = await knex('JobApplication')
.where('person_id', personId)
.where('job_offer_id', jobOfferId)
.select('*')
@ -33,7 +41,23 @@ async function userAlreadyApplicated(personId, jobOfferId){
return false;
}
/**
* Retrieves all the applications of the specified Person, includinf data from
* JobOffer and Organization
* @param {*} personId
* @returns All the applications of the specified Person, throws an exception
* otherwise
*/
async function getApplications(personId){
return await knex('JobApplication')
.where('person_id', personId)
.join('JobOffer', 'JobOffer.id', 'JobApplication.job_offer_id')
.join('Organization', 'Organization.id', 'JobOffer.organization_id')
.select('JobApplication.id', 'JobOffer.title', 'JobOffer.description', 'Organization.name', 'Organization.location');
}
module.exports = {
insert,
userAlreadyApplicated
userAlreadyApplicated,
getApplications
}

View File

@ -131,5 +131,6 @@ async function filter(title, description, requirements, salary, salaryOperator,
module.exports = {
insert,
remove,
findByOrganizationId
findByOrganizationId,
findById
}