experience update

This commit is contained in:
Alessandro Ferro
2025-04-18 15:24:40 +02:00
parent 597a9c1dae
commit ade6a05408
6 changed files with 34 additions and 968 deletions

View File

@ -17,8 +17,8 @@ function createExperience(title, description, organizationId, organizationName,
const experience = {
title,
description,
organization_id: organizationId,
organization_name: organizationName,
organization_id: organizationId, // Either OrganizationId or OrganizationName should be set, not both (TODO in validator)
organization_name: organizationName, // Either OrganizationId or OrganizationName should be set, not both (TODO in validator)
date,
person_id,
type
@ -26,17 +26,40 @@ function createExperience(title, description, organizationId, organizationName,
return experience;
}
async function insert(experience){
async function insert(experience) {
const insertedExperience = await knex('Experience')
.insert(experience)
.returning('*');
.insert(experience)
.returning('*');
return insertedExperience[0];
}
async function findById(experienceId) {
return await knex('Experience').where({
id: experienceId
}).select().first();
}
async function remove(experienceId) {
await knex('Experience')
.where({
id: experienceId
})
.del();
}
async function update(experience) {
await knex('Experience')
.where('id', experience.id)
.update(experience);
}
// Exporting a function
// means making a JavaScript function defined in one
// module available for use in another module.
module.exports = {
createExperience,
insert
insert,
findById,
remove,
update
};

View File

@ -120,9 +120,9 @@ async function authenticate(email, password) {
* @param {*} person The Person to update
* @param {*} person_id The database id of the Person to update
*/
async function update(person, person_id) {
async function update(person) {
await knex('Person')
.where('id', person_id)
.where('id', person.id)
.update(person);
}

View File

@ -278,7 +278,8 @@ async function updatePerson(req, res) {
});
}
await Person.update(updatePerson, req.jwt.person_id);
updatePerson.id = req.jwt.person_id;
await Person.update(updatePerson);
return res.status(204).send();
} catch (error) {
console.error(`Error in function ${updatePerson.name}: ${error}`);

View File

@ -55,7 +55,6 @@ function extractToken(req, res, next) {
error: 'No token provided'
});
}
}
module.exports = {