Working(tm) implementation of group and team deletion

ref #13
This commit is contained in:
2020-12-04 18:15:38 +01:00
parent c4f02023b9
commit 795599fd38
5 changed files with 56 additions and 23 deletions

View File

@@ -1,13 +1,12 @@
import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, Entity, TableInheritance } from "typeorm";
import {
IsInt,
IsNotEmpty,
IsOptional,
IsString,
IsString
} from "class-validator";
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
import { GroupContact } from "./GroupContact";
import { Runner } from "./Runner";
import { RunnerTeam } from "./RunnerTeam";
/**
* Defines the runnerGroup interface.
@@ -44,4 +43,6 @@ export abstract class RunnerGroup {
*/
@OneToMany(() => Runner, runner => runner.group, { nullable: true })
runners: Runner[];
public abstract getRunners();
}

View File

@@ -1,7 +1,8 @@
import { Entity, Column, ManyToOne, OneToMany, ChildEntity } from "typeorm";
import { IsOptional, } from "class-validator";
import { RunnerGroup } from "./RunnerGroup";
import { IsOptional } from "class-validator";
import { ChildEntity, getConnectionManager, ManyToOne, OneToMany } from "typeorm";
import { Address } from "./Address";
import { Runner } from './Runner';
import { RunnerGroup } from "./RunnerGroup";
import { RunnerTeam } from "./RunnerTeam";
/**
@@ -23,6 +24,26 @@ export class RunnerOrganisation extends RunnerGroup {
*/
@OneToMany(() => RunnerTeam, team => team.parentGroup, { nullable: true })
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() {
return await getConnectionManager().get().getRepository(RunnerTeam).find({ parentGroup: this });
}