From 179add80f480cd10f2951d8f7077164da840d4d0 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Sat, 5 Dec 2020 12:18:24 +0100 Subject: [PATCH] Now throwing errors even faster ref #13 --- src/controllers/RunnerController.ts | 1 + src/controllers/RunnerOrganisationController.ts | 5 +---- src/controllers/RunnerTeamController.ts | 5 +---- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/controllers/RunnerController.ts b/src/controllers/RunnerController.ts index 026b4a6..6508f67 100644 --- a/src/controllers/RunnerController.ts +++ b/src/controllers/RunnerController.ts @@ -84,6 +84,7 @@ export class RunnerController { @ResponseSchema(RunnerNotFoundError, { statusCode: 404 }) @OpenAPI({ description: 'Delete a specified runner (if it exists).' }) async remove(@EntityFromParam('id') runner: Runner, @QueryParam("force") force: boolean) { + if (!runner) { throw new RunnerNotFoundError(); } const responseRunner = await this.runnerRepository.findOne(runner, { relations: ['scans', 'group'] }); if (!runner) { diff --git a/src/controllers/RunnerOrganisationController.ts b/src/controllers/RunnerOrganisationController.ts index 127cb55..8cfef6a 100644 --- a/src/controllers/RunnerOrganisationController.ts +++ b/src/controllers/RunnerOrganisationController.ts @@ -89,12 +89,9 @@ export class RunnerOrganisationController { @ResponseSchema(RunnerOrganisationHasRunnersError, { statusCode: 406 }) @OpenAPI({ description: 'Delete a specified runnerOrganisation (if it exists).' }) async remove(@EntityFromParam('id') organisation: RunnerOrganisation, @QueryParam("force") force: boolean) { + if (!organisation) { throw new RunnerOrganisationNotFoundError() } let runnerOrganisation = await this.runnerOrganisationRepository.findOne(organisation, { relations: ['address', 'contact', 'runners', 'teams'] }); - if (!runnerOrganisation) { - throw new RunnerOrganisationNotFoundError(); - } - if (!force) { if (runnerOrganisation.teams.length != 0) { throw new RunnerOrganisationHasTeamsError(); diff --git a/src/controllers/RunnerTeamController.ts b/src/controllers/RunnerTeamController.ts index b0061b5..1b7627d 100644 --- a/src/controllers/RunnerTeamController.ts +++ b/src/controllers/RunnerTeamController.ts @@ -88,12 +88,9 @@ export class RunnerTeamController { @ResponseSchema(RunnerTeamHasRunnersError, { statusCode: 406 }) @OpenAPI({ description: 'Delete a specified runnerTeam (if it exists).' }) async remove(@EntityFromParam('id') team: RunnerTeam, @QueryParam("force") force: boolean) { + if (!team) { throw new RunnerTeamNotFoundError(); } let runnerTeam = await this.runnerTeamRepository.findOne(team, { relations: ['parentGroup', 'contact', 'runners'] }); - if (!runnerTeam) { - throw new RunnerTeamNotFoundError(); - } - if (!force) { if (runnerTeam.runners.length != 0) { throw new RunnerTeamHasRunnersError();