Impementing more methods for the runner orgs

This commit is contained in:
2020-12-04 17:06:37 +01:00
parent 330cbd5f57
commit 0c6528bdc5
2 changed files with 46 additions and 11 deletions

View File

@@ -1,11 +1,10 @@
import { JsonController, Param, Body, Get, Post, Put, Delete, OnUndefined } from 'routing-controllers';
import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers';
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
import { getConnectionManager, Repository } from 'typeorm';
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
import { RunnerOrganisation } from '../models/entities/RunnerOrganisation';
import { RunnerOrganisationIdsNotMatchingError, RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors';
import { RunnerOrganisationHasRunnersError, RunnerOrganisationHasTeamsError, RunnerOrganisationIdsNotMatchingError, RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors';
import { CreateRunnerOrganisation } from '../models/creation/CreateRunnerOrganisation';
import { RunnerGroup } from '../models/entities/RunnerGroup';
import { RunnerOrganisation } from '../models/entities/RunnerOrganisation';
@JsonController('/organisations')
@@ -74,13 +73,25 @@ export class RunnerOrganisationController {
@ResponseSchema(RunnerOrganisation)
@ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 })
@OpenAPI({ description: 'Delete a specified runnerOrganisation (if it exists).' })
async remove(@Param('id') id: number) {
async remove(@Param('id') id: number, @QueryParam("force") force) {
let runnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id });
if (!runnerOrganisation) {
throw new RunnerOrganisationNotFoundError();
}
if (!force) {
if (runnerOrganisation.runners.length != 0) {
throw new RunnerOrganisationHasRunnersError();
}
if (runnerOrganisation.teams.length != 0) {
throw new RunnerOrganisationHasTeamsError();
}
}
//TODO: Delete runner and teams
await this.runnerOrganisationRepository.delete(runnerOrganisation);
return runnerOrganisation;
}