|
|
|
@@ -7,11 +7,12 @@ import { CreateRunnerOrganisation } from '../models/creation/CreateRunnerOrganis
|
|
|
|
|
import { Runner } from '../models/entities/Runner';
|
|
|
|
|
import { RunnerOrganisation } from '../models/entities/RunnerOrganisation';
|
|
|
|
|
import { RunnerTeam } from '../models/entities/RunnerTeam';
|
|
|
|
|
import { ResponseRunnerOrganisation } from '../models/responses/ResponseRunnerOrganisation';
|
|
|
|
|
import { RunnerController } from './RunnerController';
|
|
|
|
|
import { RunnerTeamController } from './RunnerTeamController';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@JsonController('/organisations')
|
|
|
|
|
@JsonController('/organisation')
|
|
|
|
|
//@Authorized('RUNNERS:read')
|
|
|
|
|
export class RunnerOrganisationController {
|
|
|
|
|
private runnerOrganisationRepository: Repository<RunnerOrganisation>;
|
|
|
|
@@ -24,23 +25,29 @@ export class RunnerOrganisationController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get()
|
|
|
|
|
@ResponseSchema(RunnerOrganisation, { isArray: true })
|
|
|
|
|
@ResponseSchema(ResponseRunnerOrganisation, { isArray: true })
|
|
|
|
|
@OpenAPI({ description: 'Lists all runnerOrganisations.' })
|
|
|
|
|
getAll() {
|
|
|
|
|
return this.runnerOrganisationRepository.find({ relations: ['address', 'contact', 'teams'] });
|
|
|
|
|
async getAll() {
|
|
|
|
|
let responseTeams: ResponseRunnerOrganisation[] = new Array<ResponseRunnerOrganisation>();
|
|
|
|
|
const runners = await this.runnerOrganisationRepository.find({ relations: ['address', 'contact', 'teams'] });
|
|
|
|
|
console.log(runners);
|
|
|
|
|
runners.forEach(runner => {
|
|
|
|
|
responseTeams.push(new ResponseRunnerOrganisation(runner));
|
|
|
|
|
});
|
|
|
|
|
return responseTeams;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('/:id')
|
|
|
|
|
@ResponseSchema(RunnerOrganisation)
|
|
|
|
|
@ResponseSchema(ResponseRunnerOrganisation)
|
|
|
|
|
@ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 })
|
|
|
|
|
@OnUndefined(RunnerOrganisationNotFoundError)
|
|
|
|
|
@OpenAPI({ description: 'Returns a runnerOrganisation of a specified id (if it exists)' })
|
|
|
|
|
getOne(@Param('id') id: number) {
|
|
|
|
|
return this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['address', 'contact', 'teams'] });
|
|
|
|
|
async getOne(@Param('id') id: number) {
|
|
|
|
|
return new ResponseRunnerOrganisation(await this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['address', 'contact', 'teams'] }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post()
|
|
|
|
|
@ResponseSchema(RunnerOrganisation)
|
|
|
|
|
@ResponseSchema(ResponseRunnerOrganisation)
|
|
|
|
|
@OpenAPI({ description: 'Create a new runnerOrganisation object (id will be generated automagicly).' })
|
|
|
|
|
async post(@Body({ validate: true }) createRunnerOrganisation: CreateRunnerOrganisation) {
|
|
|
|
|
let runnerOrganisation;
|
|
|
|
@@ -50,11 +57,14 @@ export class RunnerOrganisationController {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this.runnerOrganisationRepository.save(runnerOrganisation);
|
|
|
|
|
runnerOrganisation = await this.runnerOrganisationRepository.save(runnerOrganisation);
|
|
|
|
|
runnerOrganisation = await this.runnerOrganisationRepository.findOne(runnerOrganisation, { relations: ['address', 'contact', 'teams'] });
|
|
|
|
|
|
|
|
|
|
return new ResponseRunnerOrganisation(runnerOrganisation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put('/:id')
|
|
|
|
|
@ResponseSchema(RunnerOrganisation)
|
|
|
|
|
@ResponseSchema(ResponseRunnerOrganisation)
|
|
|
|
|
@ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 })
|
|
|
|
|
@ResponseSchema(RunnerOrganisationIdsNotMatchingError, { statusCode: 406 })
|
|
|
|
|
@OpenAPI({ description: "Update a runnerOrganisation object (id can't be changed)." })
|
|
|
|
@@ -70,14 +80,15 @@ export class RunnerOrganisationController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await this.runnerOrganisationRepository.update(oldRunnerOrganisation, runnerOrganisation);
|
|
|
|
|
return runnerOrganisation;
|
|
|
|
|
|
|
|
|
|
runnerOrganisation = await this.runnerOrganisationRepository.findOne(runnerOrganisation, { relations: ['address', 'contact', 'teams'] });
|
|
|
|
|
return new ResponseRunnerOrganisation(runnerOrganisation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete('/:id')
|
|
|
|
|
@ResponseSchema(RunnerOrganisation)
|
|
|
|
|
@ResponseSchema(ResponseRunnerOrganisation)
|
|
|
|
|
@ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 })
|
|
|
|
|
@ResponseSchema(RunnerOrganisationHasRunnersError, { statusCode: 406 })
|
|
|
|
|
@ResponseSchema(RunnerOrganisationHasTeamsError, { statusCode: 406 })
|
|
|
|
|
@OpenAPI({ description: 'Delete a specified runnerOrganisation (if it exists).' })
|
|
|
|
|
async remove(@Param('id') id: number, @QueryParam("force") force: boolean) {
|
|
|
|
|
let runnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['address', 'contact', 'teams'] });
|
|
|
|
@@ -87,25 +98,29 @@ export class RunnerOrganisationController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let runners: Runner[] = await runnerOrganisation.getRunners()
|
|
|
|
|
|
|
|
|
|
if (!force && runners.length != 0) {
|
|
|
|
|
throw new RunnerOrganisationHasRunnersError();
|
|
|
|
|
if (!force) {
|
|
|
|
|
if (runners.length != 0) {
|
|
|
|
|
throw new RunnerOrganisationHasRunnersError();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const runnerController = new RunnerController()
|
|
|
|
|
await runners.forEach(async runner => {
|
|
|
|
|
await runnerController.remove(runner.id, true);
|
|
|
|
|
runners.forEach(runner => {
|
|
|
|
|
runnerController.remove(runner.id, true)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let teams: RunnerTeam[] = await runnerOrganisation.getTeams()
|
|
|
|
|
if (!force && teams.length != 0) {
|
|
|
|
|
throw new RunnerOrganisationHasTeamsError();
|
|
|
|
|
if (!force) {
|
|
|
|
|
if (teams.length != 0) {
|
|
|
|
|
throw new RunnerOrganisationHasTeamsError();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const teamController = new RunnerTeamController()
|
|
|
|
|
await teams.forEach(async team => {
|
|
|
|
|
await teamController.remove(team.id, true);
|
|
|
|
|
teams.forEach(team => {
|
|
|
|
|
teamController.remove(team.id, true)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await this.runnerOrganisationRepository.delete(runnerOrganisation);
|
|
|
|
|
return runnerOrganisation;
|
|
|
|
|
const responseOrganisation = new ResponseRunnerOrganisation(runnerOrganisation);
|
|
|
|
|
await this.runnerOrganisationRepository.delete({ id: runnerOrganisation.id });
|
|
|
|
|
return responseOrganisation;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|