update organization

This commit is contained in:
xfarrow 2024-03-04 15:39:31 +01:00
parent 6def308ee1
commit 5ef0317833
2 changed files with 8 additions and 4 deletions

View File

@ -45,11 +45,13 @@ async function getOrganizationById (id) {
}
/**
* Insert an Organization and its relative Administrator
* Insert an Organization and its relative Administrator.
* @param {*} organization
*
* @returns The inserted Organization
*/
async function insertOrganization (organization, organizationAdministratorId) {
await knex.transaction(async (trx) => {
return await knex.transaction(async (trx) => {
// We have to insert either both in Organization and in OrganizationAdministrator
// or in neither
const organizationResult = await trx('Organization')
@ -61,6 +63,8 @@ async function insertOrganization (organization, organizationAdministratorId) {
id_person: organizationAdministratorId,
id_organization: organizationResult[0].id
});
return organizationResult[0];
});
}

View File

@ -30,8 +30,8 @@ async function createOrganization (req, res) {
try {
const organization = organizationModel.createOrganization(req.body.name, req.body.location, req.body.description, req.body.is_hiring);
await organizationModel.insertOrganization(organization, req.jwt.person_id);
return res.status(200).json(organization);
const insertedOrganization = await organizationModel.insertOrganization(organization, req.jwt.person_id);
return res.status(200).json(insertedOrganization);
} catch (error) {
console.error(`Error in function ${createOrganization.name}: ${error}`);
res.status(500).json({ error: 'Internal server error' });