Little bugfix

ref #13
This commit is contained in:
Nicolai Ort 2020-12-05 11:36:33 +01:00
parent aca13f7308
commit 9c63a34fe1
2 changed files with 5 additions and 7 deletions

View File

@ -84,7 +84,7 @@ export class RunnerController {
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
@OpenAPI({ description: 'Delete a specified runner (if it exists).' })
async remove(@Param('id') id: number, @QueryParam("force") force: boolean) {
let runner = await this.runnerRepository.findOne({ id: id });
const runner = await this.runnerRepository.findOne({ id: id });
if (!runner) {
throw new RunnerNotFoundError();

View File

@ -4,7 +4,6 @@ import { getConnectionManager, Repository } from 'typeorm';
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
import { RunnerTeamHasRunnersError, RunnerTeamIdsNotMatchingError, RunnerTeamNotFoundError } from '../errors/RunnerTeamErrors';
import { CreateRunnerTeam } from '../models/creation/CreateRunnerTeam';
import { Runner } from '../models/entities/Runner';
import { RunnerTeam } from '../models/entities/RunnerTeam';
import { ResponseRunnerTeam } from '../models/responses/ResponseRunnerTeam';
import { RunnerController } from './RunnerController';
@ -89,21 +88,20 @@ export class RunnerTeamController {
@ResponseSchema(RunnerTeamHasRunnersError, { statusCode: 406 })
@OpenAPI({ description: 'Delete a specified runnerTeam (if it exists).' })
async remove(@Param('id') id: number, @QueryParam("force") force: boolean) {
let runnerTeam = await this.runnerTeamRepository.findOne({ id: id }, { relations: ['parentGroup', 'contact'] });
let runnerTeam = await this.runnerTeamRepository.findOne({ id: id }, { relations: ['parentGroup', 'contact', 'runners'] });
if (!runnerTeam) {
throw new RunnerTeamNotFoundError();
}
let runners: Runner[] = await runnerTeam.getRunners()
if (!force) {
if (runners.length != 0) {
if (runnerTeam.runners.length != 0) {
throw new RunnerTeamHasRunnersError();
}
}
const runnerController = new RunnerController()
runners.forEach(runner => {
runnerController.remove(runner.id, true)
await runnerTeam.runners.forEach(async runner => {
await runnerController.remove(runner.id, true);
});
const responseTeam = new ResponseRunnerTeam(runnerTeam);