First part of the action comment refactoring
ref #39 Why did i volunteer for this? It's just a glorified sleeping aid 😴
This commit is contained in:
@@ -7,6 +7,10 @@ import { RunnerOrganisation } from '../entities/RunnerOrganisation';
|
||||
import { RunnerTeam } from '../entities/RunnerTeam';
|
||||
import { CreateRunner } from './CreateRunner';
|
||||
|
||||
/**
|
||||
* Special class used to import runners from csv files - or json arrays created from csv to be exact.
|
||||
* Why you ask? Because the past has shown us that a non excel/csv based workflow is too much for most schools.
|
||||
*/
|
||||
export class ImportRunner {
|
||||
|
||||
/**
|
||||
@@ -18,7 +22,6 @@ export class ImportRunner {
|
||||
|
||||
/**
|
||||
* The new runner's middle name.
|
||||
* Optional.
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@@ -32,18 +35,26 @@ export class ImportRunner {
|
||||
lastname: string;
|
||||
|
||||
/**
|
||||
* The new runner's class (if not provided otherwise).
|
||||
* The new runner's team's name (if not provided otherwise).
|
||||
* The team will automaticly get generated if it doesn't exist in this org yet.
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
team?: string;
|
||||
|
||||
/**
|
||||
* Just an alias for team, because this is usually only used for importing data from schools.
|
||||
*/
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
public set class(value: string) {
|
||||
this.team = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a CreateRunner object based on this.
|
||||
* @param groupID Either the id of the new runner's group or the id of the org that the new runner's team is a part of.
|
||||
*/
|
||||
public async toCreateRunner(groupID: number): Promise<CreateRunner> {
|
||||
let newRunner: CreateRunner = new CreateRunner();
|
||||
|
||||
@@ -55,25 +66,28 @@ export class ImportRunner {
|
||||
return newRunner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get's the new runners group.
|
||||
* @param groupID Either the id of the new runner's group or the id of the org that the new runner's team is a part of.
|
||||
*/
|
||||
public async getGroup(groupID: number): Promise<RunnerGroup> {
|
||||
if (this.team === undefined && groupID === undefined) {
|
||||
throw new RunnerGroupNeededError();
|
||||
}
|
||||
|
||||
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) {
|
||||
let group = await getConnectionManager().get().getRepository(RunnerGroup).findOne({ id: groupID });
|
||||
if (group instanceof RunnerTeam) { return group; }
|
||||
if (!(group instanceof RunnerOrganisation) || !group) {
|
||||
throw new RunnerOrganisationNotFoundError();
|
||||
}
|
||||
if (this.team === undefined) { return org; }
|
||||
|
||||
team = await getConnectionManager().get().getRepository(RunnerTeam).findOne({ name: this.team, parentGroup: org });
|
||||
if (this.team === undefined) { return group; }
|
||||
|
||||
let team = await getConnectionManager().get().getRepository(RunnerTeam).findOne({ name: this.team, parentGroup: org });
|
||||
if (!team) {
|
||||
let newRunnerTeam: RunnerTeam = new RunnerTeam();
|
||||
newRunnerTeam.name = this.team;
|
||||
newRunnerTeam.parentGroup = org;
|
||||
newRunnerTeam.parentGroup = group;
|
||||
team = await getConnectionManager().get().getRepository(RunnerTeam).save(newRunnerTeam);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user