backend/src/models/entities/RunnerTeam.ts
2020-12-04 17:51:27 +01:00

27 lines
762 B
TypeScript

import { IsNotEmpty } from "class-validator";
import { ChildEntity, getConnectionManager, ManyToOne } from "typeorm";
import { Runner } from './Runner';
import { RunnerGroup } from "./RunnerGroup";
import { RunnerOrganisation } from "./RunnerOrganisation";
/**
* Defines a runner team (class or deparment for example).
*/
@ChildEntity()
export class RunnerTeam extends RunnerGroup {
/**
* The team's parent group.
* Optional
*/
@IsNotEmpty()
@ManyToOne(() => RunnerOrganisation, org => org.teams, { nullable: true })
parentGroup?: RunnerOrganisation;
/**
* Returns all runners associated with this team.
*/
public async getRunners() {
return await getConnectionManager().get().getRepository(Runner).find({ group: this });
}
}