From 330cbd5f57a9f16cbf277ea57fadefcb6d24e0fa Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Thu, 3 Dec 2020 20:49:55 +0100 Subject: [PATCH] Added comments and decorators for existing create models ref #13 --- src/models/creation/CreateRunner.ts | 79 ++++++++++++++----- .../creation/CreateRunnerOrganisation.ts | 9 ++- 2 files changed, 67 insertions(+), 21 deletions(-) diff --git a/src/models/creation/CreateRunner.ts b/src/models/creation/CreateRunner.ts index 178c5fb..b68a90b 100644 --- a/src/models/creation/CreateRunner.ts +++ b/src/models/creation/CreateRunner.ts @@ -1,31 +1,70 @@ -import { IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsPositive, IsString } from 'class-validator'; +import { IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString } from 'class-validator'; +import { getConnectionManager } from 'typeorm'; +import { RunnerGroupNeededError, RunnerGroupNotFoundError, RunnerOnlyOneGroupAllowedError } from '../../errors/RunnerErrors'; 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 { + /** + * The new runner's first name. + */ @IsString() + @IsNotEmpty() firstname: string; - @IsString() - middlename?: string; - @IsString() - lastname: string; - @IsString() - phone?: string; - @IsString() - email?: string; - @IsInt() - @IsOptional() - teamId?: number - @IsInt() - @IsOptional() - orgId?: number + /** + * The new runner's middle name. + * Optional. + */ + @IsString() + @IsNotEmpty() + middlename?: string; + + /** + * The new runner's last name. + */ + @IsString() + @IsNotEmpty() + lastname: string; + + /** + * The new runner's phone number. + * Optional. + */ + @IsString() + @IsOptional() + @IsPhoneNumber("ZZ") + phone?: string; + + /** + * The new runner's e-mail address. + * Optional. + */ + @IsString() + @IsOptional() + @IsEmail() + email?: string; + + /** + * The new runner's team's id. + * Either provide this or his organisation's id. + */ + @IsInt() + @IsOptional() + teamId?: number; + + /** + * The new runner's organisation's id. + * Either provide this or his teams's id. + */ + @IsInt() + @IsOptional() + orgId?: number; + + /** + * Creates a Runner entity from this. + */ public async toRunner(): Promise { let newRunner: Runner = new Runner(); diff --git a/src/models/creation/CreateRunnerOrganisation.ts b/src/models/creation/CreateRunnerOrganisation.ts index f054e5a..ff4ec65 100644 --- a/src/models/creation/CreateRunnerOrganisation.ts +++ b/src/models/creation/CreateRunnerOrganisation.ts @@ -1,10 +1,17 @@ -import { IsString } from 'class-validator'; +import { IsNotEmpty, IsString } from 'class-validator'; import { RunnerOrganisation } from '../entities/RunnerOrganisation'; export class CreateRunnerOrganisation { + /** + * The Organisation's name. + */ @IsString() + @IsNotEmpty() name: string; + /** + * Creates a RunnerOrganisation entity from this. + */ public async toRunnerOrganisation(): Promise { let newRunnerOrganisation: RunnerOrganisation = new RunnerOrganisation();