This commit is contained in:
xfarrow 2024-03-13 12:16:20 +01:00
parent aa8e67120f
commit c164728a9b
2 changed files with 7 additions and 4 deletions

View File

@ -66,7 +66,7 @@ async function removeOrganizationAdmin(personId, organizationId) {
// TODO: Understand whether a lock on the table is really necessary
await transaction.raw('LOCK TABLE "OrganizationAdministrator" IN SHARE MODE');
await transaction('OrganizationAdministrator')
const deletedAdmins = await transaction('OrganizationAdministrator')
.where('id_person', personId)
.where('id_organization', organizationId)
.del();
@ -83,8 +83,8 @@ async function removeOrganizationAdmin(personId, organizationId) {
.where('id', organizationId)
.del();
}
await transaction.commit();
return deletedAdmins === 1;
}
module.exports = {

View File

@ -64,8 +64,11 @@ async function removeOrganizationAdmin(req, res) {
errors: errors.array()
});
}
await organizationAdminModel.removeOrganizationAdmin(req.jwt.person_id, req.params.organizationId);
return res.status(204).send();
const success = await organizationAdminModel.removeOrganizationAdmin(req.jwt.person_id, req.params.organizationId);
if(success){
return res.status(204).send();
}
return res.status(404).send();
} catch (error) {
console.error(`Error in function ${removeOrganizationAdmin.name}: ${error}`);
return res.status(500).json({