Added comments and decorators for existing create models

ref #13
This commit is contained in:
Nicolai Ort 2020-12-03 20:49:55 +01:00
parent 36b2e82f4e
commit 330cbd5f57
2 changed files with 67 additions and 21 deletions

View File

@ -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<Runner> {
let newRunner: Runner = new Runner();

View File

@ -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<RunnerOrganisation> {
let newRunnerOrganisation: RunnerOrganisation = new RunnerOrganisation();