Now organisations and teams can import runners

This commit is contained in:
2020-12-17 17:14:08 +01:00
parent 97494aeaf7
commit 71228fbf33
2 changed files with 20 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
import { IsNotEmpty, IsString } from 'class-validator';
import { getConnectionManager } from 'typeorm';
import { RunnerGroupNeededError } from '../../errors/RunnerErrors';
import { RunnerOrganisationNotFoundError } from '../../errors/RunnerOrganisationErrors';
import { RunnerGroup } from '../entities/RunnerGroup';
import { RunnerOrganisation } from '../entities/RunnerOrganisation';
@@ -29,17 +30,20 @@ export class ImportSchoolRunner extends ImportRunner {
return newRunner;
}
public async getGroup(orgID: number): Promise<RunnerGroup> {
if (this.class === undefined) {
throw new Error("TODO:Error for runner missing teams");
public async getGroup(groupID: number): Promise<RunnerGroup> {
if (this.class === undefined && groupID === undefined) {
throw new RunnerGroupNeededError();
}
let org = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: orgID });
let team = await getConnectionManager().get().getRepository(RunnerTeam).findOne({ id: groupID });
if (team) { return team; }
let org = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: groupID });
if (!org) {
throw new RunnerOrganisationNotFoundError();
}
let team = await getConnectionManager().get().getRepository(RunnerTeam).findOne({ name: this.class, parentGroup: org });
team = await getConnectionManager().get().getRepository(RunnerTeam).findOne({ name: this.class, parentGroup: org });
if (!team) {
let newRunnerTeam: RunnerTeam = new RunnerTeam();
newRunnerTeam.name = this.class;