Moved to a "cleaner" directory structure

ref #11
This commit is contained in:
2020-12-03 20:38:47 +01:00
parent 3a04bb54bd
commit e8727ca922
27 changed files with 145 additions and 145 deletions

View File

@@ -0,0 +1,58 @@
import { IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsPositive, IsString } from 'class-validator';
import { Runner } from '../entities/Runner';
import { getConnectionManager, Repository } from 'typeorm';
import { group } from 'console';
import { RunnerOnlyOneGroupAllowedError, RunnerGroupNeededError, RunnerGroupNotFoundError } from '../../errors/RunnerErrors';
import { RunnerOrganisation } from '../entities/RunnerOrganisation';
import { RunnerTeam } from '../entities/RunnerTeam';
import { RunnerGroup } from '../entities/RunnerGroup';
import { Address } from 'cluster';
export class CreateRunner {
@IsString()
firstname: string;
@IsString()
middlename?: string;
@IsString()
lastname: string;
@IsString()
phone?: string;
@IsString()
email?: string;
@IsInt()
@IsOptional()
teamId?: number
@IsInt()
@IsOptional()
orgId?: number
public async toRunner(): Promise<Runner> {
let newRunner: Runner = new Runner();
if (this.teamId !== undefined && this.orgId !== undefined) {
throw new RunnerOnlyOneGroupAllowedError();
}
if (this.teamId === undefined && this.orgId === undefined) {
throw new RunnerGroupNeededError();
}
if (this.teamId) {
newRunner.group = await getConnectionManager().get().getRepository(RunnerTeam).findOne({ id: this.teamId });
}
if (this.orgId) {
newRunner.group = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: this.orgId });
}
if (!newRunner.group) {
throw new RunnerGroupNotFoundError();
}
newRunner.firstname = this.firstname;
newRunner.middlename = this.middlename;
newRunner.lastname = this.lastname;
newRunner.phone = this.phone;
newRunner.email = this.email;
console.log(newRunner)
return newRunner;
}
}

View File

@@ -0,0 +1,15 @@
import { IsString } from 'class-validator';
import { RunnerOrganisation } from '../entities/RunnerOrganisation';
export class CreateRunnerOrganisation {
@IsString()
name: string;
public async toRunnerOrganisation(): Promise<RunnerOrganisation> {
let newRunnerOrganisation: RunnerOrganisation = new RunnerOrganisation();
newRunnerOrganisation.name = this.name;
return newRunnerOrganisation;
}
}

View File

@@ -0,0 +1,30 @@
import { IsInt, IsNotEmpty, IsPositive, IsString } from 'class-validator';
import { Track } from '../entities/Track';
export class CreateTrack {
/**
* The track's name.
*/
@IsString()
@IsNotEmpty()
name: string;
/**
* The track's distance in meters (must be greater 0).
*/
@IsInt()
@IsPositive()
distance: number;
/**
* Converts a Track object based on this.
*/
public toTrack(): Track {
let newTrack: Track = new Track();
newTrack.name = this.name;
newTrack.distance = this.distance;
return newTrack;
}
}