Added basics for the runner team controller

ref #13
This commit is contained in:
2020-12-04 17:50:10 +01:00
parent 838cedfe6c
commit ca917b0577
4 changed files with 187 additions and 1 deletions

View File

@@ -0,0 +1,36 @@
import { IsInt, IsNotEmpty, IsString } from 'class-validator';
import { getConnectionManager } from 'typeorm';
import { RunnerOrganisationNotFoundError } from '../../errors/RunnerOrganisationErrors';
import { RunnerOrganisation } from '../entities/RunnerOrganisation';
import { RunnerTeam } from '../entities/RunnerTeam';
export class CreateRunnerTeam {
/**
* The teams's name.
*/
@IsString()
@IsNotEmpty()
name: string;
/**
* The team's parent group (organisation).
*/
@IsInt()
@IsNotEmpty()
parentId: number
/**
* Creates a RunnerTeam entity from this.
*/
public async toRunnerTeam(): Promise<RunnerTeam> {
let newRunnerTeam: RunnerTeam = new RunnerTeam();
newRunnerTeam.name = this.name;
newRunnerTeam.parentGroup = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: this.parentId });
if (!newRunnerTeam.parentGroup) {
throw new RunnerOrganisationNotFoundError();
}
return newRunnerTeam;
}
}

View File

@@ -1,5 +1,6 @@
import { Entity, Column, ManyToOne, ChildEntity } from "typeorm";
import { IsNotEmpty } from "class-validator";
import { ChildEntity, getConnectionManager, ManyToOne } from "typeorm";
import { Runner } from './Runner';
import { RunnerGroup } from "./RunnerGroup";
import { RunnerOrganisation } from "./RunnerOrganisation";
@@ -16,4 +17,12 @@ export class RunnerTeam extends RunnerGroup {
@IsNotEmpty()
@ManyToOne(() => RunnerOrganisation, org => org.teams, { nullable: true })
parentGroup?: RunnerOrganisation;
/**
* Returns all runners associated with this team.
*/
public async getRunners() {
let runnerRepo = await getConnectionManager().get().getRepository(Runner);
return await runnerRepo.find({ group: this });
}
}