import { IsInt, IsOptional } from 'class-validator'; import { getConnectionManager } from 'typeorm'; import { AddressNotFoundError, AddressWrongTypeError } from '../../errors/AddressErrors'; import { Address } from '../entities/Address'; import { RunnerOrganisation } from '../entities/RunnerOrganisation'; import { CreateRunnerGroup } from './CreateRunnerGroup'; export class CreateRunnerOrganisation extends CreateRunnerGroup { /** * The new organisation's address. * Must be of type number (address id), createAddress (new address) or address (existing address) * Optional. */ @IsInt() @IsOptional() address?: number; /** * Creates a Participant entity from this. */ public async getAddress(): Promise
{ if (this.address === undefined) { return null; } if (!isNaN(this.address)) { let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address }); if (!address) { throw new AddressNotFoundError; } return address; } throw new AddressWrongTypeError; } /** * Creates a RunnerOrganisation entity from this. */ public async toRunnerOrganisation(): Promise