diff --git a/src/backend/app/db/models.py b/src/backend/app/db/models.py index a2292335d..bd6234617 100644 --- a/src/backend/app/db/models.py +++ b/src/backend/app/db/models.py @@ -516,7 +516,11 @@ async def delete(cls, db: Connection, org_id: int) -> bool: DELETE FROM projects WHERE organisation_id = %(org_id)s RETURNING organisation_id - ), deleted_org AS ( + ), deleted_org_managers AS ( + DELETE FROM organisation_managers + WHERE organisation_id = %(org_id)s + RETURNING organisation_id + ),deleted_org AS ( DELETE FROM organisations WHERE id = %(org_id)s RETURNING id diff --git a/src/backend/app/organisations/organisation_routes.py b/src/backend/app/organisations/organisation_routes.py index eba6d7edb..62c49eb4f 100644 --- a/src/backend/app/organisations/organisation_routes.py +++ b/src/backend/app/organisations/organisation_routes.py @@ -121,12 +121,13 @@ async def delete_org( org_user_dict: Annotated[AuthUser, Depends(org_admin)], ): """Delete an organisation.""" - org_deleted = await DbOrganisation.delete(db, org_user_dict.id) + org = org_user_dict.get("org") + org_deleted = await DbOrganisation.delete(db, org.id) if not org_deleted: - log.error(f"Failed deleting org ({org_user_dict.name}).") + log.error(f"Failed deleting org ({org.name}).") raise HTTPException( status_code=HTTPStatus.UNPROCESSABLE_ENTITY, - detail=f"Failed deleting org ({org_user_dict.name}).", + detail=f"Failed deleting org ({org.name}).", ) return Response(status_code=HTTPStatus.NO_CONTENT)