A step towards inheritance for the create* objects relating to runner groups
ref #13
This commit is contained in:
parent
48484f04c9
commit
5d7d80d2e7
|
@ -0,0 +1,30 @@
|
|||
import { IsNotEmpty, IsObject, IsOptional, IsString } from 'class-validator';
|
||||
import { GroupContact } from '../entities/GroupContact';
|
||||
|
||||
export abstract class CreateRunnerGroup {
|
||||
/**
|
||||
* The group's name.
|
||||
*/
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* The group's contact.
|
||||
* Optional
|
||||
*/
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
contact?: GroupContact;
|
||||
|
||||
/**
|
||||
* Deals with the contact for groups this.
|
||||
*/
|
||||
public async getContact(): Promise<GroupContact> {
|
||||
let newGroupContact: GroupContact;
|
||||
|
||||
//TODO:
|
||||
|
||||
return newGroupContact;
|
||||
}
|
||||
}
|
|
@ -1,13 +1,47 @@
|
|||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
import { IsInt, IsObject, IsOptional } from 'class-validator';
|
||||
import { getConnectionManager } from 'typeorm';
|
||||
import { ParticipantOnlyOneAddressAllowedError } from '../../errors/ParticipantErrors';
|
||||
import { Address } from '../entities/Address';
|
||||
import { RunnerOrganisation } from '../entities/RunnerOrganisation';
|
||||
import { CreateAddress } from './CreateAddress';
|
||||
import { CreateRunnerGroup } from './CreateRunnerGroup';
|
||||
|
||||
export class CreateRunnerOrganisation {
|
||||
export class CreateRunnerOrganisation extends CreateRunnerGroup {
|
||||
/**
|
||||
* The Organisation's name.
|
||||
* The new participant's address's id.
|
||||
* Optional - please provide either addressId or address.
|
||||
*/
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
name: string;
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
addressId?: number;
|
||||
|
||||
/**
|
||||
* The new participant's address.
|
||||
* Optional - please provide either addressId or address.
|
||||
*/
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
address?: CreateAddress;
|
||||
|
||||
/**
|
||||
* Creates a Participant entity from this.
|
||||
*/
|
||||
public async getAddress(): Promise<Address> {
|
||||
let address: Address;
|
||||
|
||||
if (this.addressId !== undefined && this.address !== undefined) {
|
||||
throw new ParticipantOnlyOneAddressAllowedError
|
||||
}
|
||||
if (this.addressId === undefined && this.address === undefined) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.addressId) {
|
||||
return await getConnectionManager().get().getRepository(Address).findOne({ id: this.addressId });
|
||||
}
|
||||
|
||||
return this.address.toAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a RunnerOrganisation entity from this.
|
||||
|
@ -16,6 +50,8 @@ export class CreateRunnerOrganisation {
|
|||
let newRunnerOrganisation: RunnerOrganisation = new RunnerOrganisation();
|
||||
|
||||
newRunnerOrganisation.name = this.name;
|
||||
newRunnerOrganisation.contact = await this.getContact();
|
||||
newRunnerOrganisation.address = await this.getAddress();
|
||||
|
||||
return newRunnerOrganisation;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue