@@ -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();
|
||||
}
|
||||
@@ -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 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user