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;
}
}