parent
aca13f7308
commit
9c63a34fe1
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue