mirror of https://github.com/xfarrow/blink
update organization
This commit is contained in:
parent
6def308ee1
commit
5ef0317833
|
@ -45,11 +45,13 @@ async function getOrganizationById (id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert an Organization and its relative Administrator
|
* Insert an Organization and its relative Administrator.
|
||||||
* @param {*} organization
|
* @param {*} organization
|
||||||
|
*
|
||||||
|
* @returns The inserted Organization
|
||||||
*/
|
*/
|
||||||
async function insertOrganization (organization, organizationAdministratorId) {
|
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
|
// We have to insert either both in Organization and in OrganizationAdministrator
|
||||||
// or in neither
|
// or in neither
|
||||||
const organizationResult = await trx('Organization')
|
const organizationResult = await trx('Organization')
|
||||||
|
@ -61,6 +63,8 @@ async function insertOrganization (organization, organizationAdministratorId) {
|
||||||
id_person: organizationAdministratorId,
|
id_person: organizationAdministratorId,
|
||||||
id_organization: organizationResult[0].id
|
id_organization: organizationResult[0].id
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return organizationResult[0];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,8 @@ async function createOrganization (req, res) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const organization = organizationModel.createOrganization(req.body.name, req.body.location, req.body.description, req.body.is_hiring);
|
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);
|
const insertedOrganization = await organizationModel.insertOrganization(organization, req.jwt.person_id);
|
||||||
return res.status(200).json(organization);
|
return res.status(200).json(insertedOrganization);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error in function ${createOrganization.name}: ${error}`);
|
console.error(`Error in function ${createOrganization.name}: ${error}`);
|
||||||
res.status(500).json({ error: 'Internal server error' });
|
res.status(500).json({ error: 'Internal server error' });
|
||||||
|
|
Loading…
Reference in New Issue