parent
c4f02023b9
commit
795599fd38
@ -1,10 +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 { getConnectionManager, Repository } from 'typeorm';
|
||||||
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
||||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
|
||||||
import { Runner } from '../models/entities/Runner';
|
|
||||||
import { RunnerGroupNeededError, RunnerGroupNotFoundError, RunnerIdsNotMatchingError, RunnerNotFoundError, RunnerOnlyOneGroupAllowedError } from '../errors/RunnerErrors';
|
import { RunnerGroupNeededError, RunnerGroupNotFoundError, RunnerIdsNotMatchingError, RunnerNotFoundError, RunnerOnlyOneGroupAllowedError } from '../errors/RunnerErrors';
|
||||||
import { CreateRunner } from '../models/creation/CreateRunner';
|
import { CreateRunner } from '../models/creation/CreateRunner';
|
||||||
|
import { Runner } from '../models/entities/Runner';
|
||||||
|
|
||||||
|
|
||||||
@JsonController('/runners')
|
@JsonController('/runners')
|
||||||
@ -76,7 +76,7 @@ export class RunnerController {
|
|||||||
@ResponseSchema(Runner)
|
@ResponseSchema(Runner)
|
||||||
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
||||||
@OpenAPI({ description: 'Delete a specified runner (if it exists).' })
|
@OpenAPI({ description: 'Delete a specified runner (if it exists).' })
|
||||||
async remove(@Param('id') id: number) {
|
async remove(@Param('id') id: number, @QueryParam("force") force: boolean) {
|
||||||
let runner = await this.runnerRepository.findOne({ id: id });
|
let runner = await this.runnerRepository.findOne({ id: id });
|
||||||
|
|
||||||
if (!runner) {
|
if (!runner) {
|
||||||
|
@ -4,7 +4,11 @@ import { getConnectionManager, Repository } from 'typeorm';
|
|||||||
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
||||||
import { RunnerOrganisationHasRunnersError, RunnerOrganisationHasTeamsError, RunnerOrganisationIdsNotMatchingError, RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors';
|
import { RunnerOrganisationHasRunnersError, RunnerOrganisationHasTeamsError, RunnerOrganisationIdsNotMatchingError, RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors';
|
||||||
import { CreateRunnerOrganisation } from '../models/creation/CreateRunnerOrganisation';
|
import { CreateRunnerOrganisation } from '../models/creation/CreateRunnerOrganisation';
|
||||||
|
import { Runner } from '../models/entities/Runner';
|
||||||
import { RunnerOrganisation } from '../models/entities/RunnerOrganisation';
|
import { RunnerOrganisation } from '../models/entities/RunnerOrganisation';
|
||||||
|
import { RunnerTeam } from '../models/entities/RunnerTeam';
|
||||||
|
import { RunnerController } from './RunnerController';
|
||||||
|
import { RunnerTeamController } from './RunnerTeamController';
|
||||||
|
|
||||||
|
|
||||||
@JsonController('/organisations')
|
@JsonController('/organisations')
|
||||||
@ -72,25 +76,34 @@ export class RunnerOrganisationController {
|
|||||||
@Delete('/:id')
|
@Delete('/:id')
|
||||||
@ResponseSchema(RunnerOrganisation)
|
@ResponseSchema(RunnerOrganisation)
|
||||||
@ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 })
|
@ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 })
|
||||||
|
@ResponseSchema(RunnerOrganisationHasRunnersError, { statusCode: 406 })
|
||||||
|
@ResponseSchema(RunnerOrganisationHasTeamsError, { statusCode: 406 })
|
||||||
@OpenAPI({ description: 'Delete a specified runnerOrganisation (if it exists).' })
|
@OpenAPI({ description: 'Delete a specified runnerOrganisation (if it exists).' })
|
||||||
async remove(@Param('id') id: number, @QueryParam("force") force) {
|
async remove(@Param('id') id: number, @QueryParam("force") force: boolean) {
|
||||||
let runnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id });
|
let runnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id });
|
||||||
|
|
||||||
if (!runnerOrganisation) {
|
if (!runnerOrganisation) {
|
||||||
throw new RunnerOrganisationNotFoundError();
|
throw new RunnerOrganisationNotFoundError();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!force) {
|
let runners: Runner[] = await runnerOrganisation.getRunners()
|
||||||
if (runnerOrganisation.runners.length != 0) {
|
|
||||||
throw new RunnerOrganisationHasRunnersError();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (runnerOrganisation.teams.length != 0) {
|
if (!force && runners.length != 0) {
|
||||||
throw new RunnerOrganisationHasTeamsError();
|
throw new RunnerOrganisationHasRunnersError();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
const runnerController = new RunnerController()
|
||||||
|
await runners.forEach(async runner => {
|
||||||
|
await runnerController.remove(runner.id, true);
|
||||||
|
});
|
||||||
|
|
||||||
//TODO: Delete runner and teams
|
let teams: RunnerTeam[] = await runnerOrganisation.getTeams()
|
||||||
|
if (!force && teams.length != 0) {
|
||||||
|
throw new RunnerOrganisationHasTeamsError();
|
||||||
|
}
|
||||||
|
const teamController = new RunnerTeamController()
|
||||||
|
await teams.forEach(async team => {
|
||||||
|
await teamController.remove(team.id, true);
|
||||||
|
});
|
||||||
|
|
||||||
await this.runnerOrganisationRepository.delete(runnerOrganisation);
|
await this.runnerOrganisationRepository.delete(runnerOrganisation);
|
||||||
return runnerOrganisation;
|
return runnerOrganisation;
|
||||||
|
@ -76,7 +76,7 @@ export class RunnerTeamController {
|
|||||||
@ResponseSchema(RunnerTeamNotFoundError, { statusCode: 404 })
|
@ResponseSchema(RunnerTeamNotFoundError, { statusCode: 404 })
|
||||||
@ResponseSchema(RunnerTeamHasRunnersError, { statusCode: 406 })
|
@ResponseSchema(RunnerTeamHasRunnersError, { statusCode: 406 })
|
||||||
@OpenAPI({ description: 'Delete a specified runnerTeam (if it exists).' })
|
@OpenAPI({ description: 'Delete a specified runnerTeam (if it exists).' })
|
||||||
async remove(@Param('id') id: number, @QueryParam("force") force) {
|
async remove(@Param('id') id: number, @QueryParam("force") force: boolean) {
|
||||||
let runnerTeam = await this.runnerTeamRepository.findOne({ id: id });
|
let runnerTeam = await this.runnerTeamRepository.findOne({ id: id });
|
||||||
|
|
||||||
if (!runnerTeam) {
|
if (!runnerTeam) {
|
||||||
@ -84,16 +84,14 @@ export class RunnerTeamController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let runners: Runner[] = await runnerTeam.getRunners()
|
let runners: Runner[] = await runnerTeam.getRunners()
|
||||||
|
|
||||||
if (!force) {
|
if (!force) {
|
||||||
if (runners.length != 0) {
|
if (runners.length != 0) {
|
||||||
throw new RunnerTeamHasRunnersError();
|
throw new RunnerTeamHasRunnersError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const runnerController = new RunnerController()
|
const runnerController = new RunnerController()
|
||||||
runners.forEach(runner => {
|
runners.forEach(runner => {
|
||||||
runnerController.remove(runner.id)
|
runnerController.remove(runner.id, true)
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.runnerTeamRepository.delete(runnerTeam);
|
await this.runnerTeamRepository.delete(runnerTeam);
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, Entity, TableInheritance } from "typeorm";
|
|
||||||
import {
|
import {
|
||||||
IsInt,
|
IsInt,
|
||||||
IsNotEmpty,
|
IsNotEmpty,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
IsString,
|
IsString
|
||||||
} from "class-validator";
|
} from "class-validator";
|
||||||
|
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
|
||||||
import { GroupContact } from "./GroupContact";
|
import { GroupContact } from "./GroupContact";
|
||||||
import { Runner } from "./Runner";
|
import { Runner } from "./Runner";
|
||||||
import { RunnerTeam } from "./RunnerTeam";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the runnerGroup interface.
|
* Defines the runnerGroup interface.
|
||||||
@ -44,4 +43,6 @@ export abstract class RunnerGroup {
|
|||||||
*/
|
*/
|
||||||
@OneToMany(() => Runner, runner => runner.group, { nullable: true })
|
@OneToMany(() => Runner, runner => runner.group, { nullable: true })
|
||||||
runners: Runner[];
|
runners: Runner[];
|
||||||
|
|
||||||
|
public abstract getRunners();
|
||||||
}
|
}
|
@ -1,7 +1,8 @@
|
|||||||
import { Entity, Column, ManyToOne, OneToMany, ChildEntity } from "typeorm";
|
import { IsOptional } from "class-validator";
|
||||||
import { IsOptional, } from "class-validator";
|
import { ChildEntity, getConnectionManager, ManyToOne, OneToMany } from "typeorm";
|
||||||
import { RunnerGroup } from "./RunnerGroup";
|
|
||||||
import { Address } from "./Address";
|
import { Address } from "./Address";
|
||||||
|
import { Runner } from './Runner';
|
||||||
|
import { RunnerGroup } from "./RunnerGroup";
|
||||||
import { RunnerTeam } from "./RunnerTeam";
|
import { RunnerTeam } from "./RunnerTeam";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,6 +24,26 @@ export class RunnerOrganisation extends RunnerGroup {
|
|||||||
*/
|
*/
|
||||||
@OneToMany(() => RunnerTeam, team => team.parentGroup, { nullable: true })
|
@OneToMany(() => RunnerTeam, team => team.parentGroup, { nullable: true })
|
||||||
teams: RunnerTeam[];
|
teams: RunnerTeam[];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all runners associated with this organisation or it's teams.
|
||||||
|
*/
|
||||||
|
public async getRunners() {
|
||||||
|
let runners: Runner[] = new Array<Runner>();
|
||||||
|
const teams = await this.getTeams();
|
||||||
|
|
||||||
|
await teams.forEach(async team => {
|
||||||
|
runners.push(... await team.getRunners());
|
||||||
|
});
|
||||||
|
await runners.push(... await getConnectionManager().get().getRepository(Runner).find({ group: this }));
|
||||||
|
|
||||||
|
return runners;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all teams associated with this organisation.
|
||||||
|
*/
|
||||||
public async getTeams() {
|
public async getTeams() {
|
||||||
return await getConnectionManager().get().getRepository(RunnerTeam).find({ parentGroup: this });
|
return await getConnectionManager().get().getRepository(RunnerTeam).find({ parentGroup: this });
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user