Switched the create classes over to the new address implementation

ref #105
This commit is contained in:
2021-01-16 16:55:30 +01:00
parent dafac06bc8
commit 2cd15d25e9
5 changed files with 13 additions and 48 deletions

View File

@@ -1,6 +1,4 @@
import { IsInt, IsOptional } from 'class-validator';
import { getConnectionManager } from 'typeorm';
import { AddressNotFoundError } from '../../../errors/AddressErrors';
import { IsObject, IsOptional } from 'class-validator';
import { Address } from '../../entities/Address';
import { RunnerOrganisation } from '../../entities/RunnerOrganisation';
import { CreateRunnerGroup } from './CreateRunnerGroup';
@@ -12,19 +10,9 @@ export class CreateRunnerOrganisation extends CreateRunnerGroup {
/**
* The new organisation's address's id.
*/
@IsInt()
@IsOptional()
address?: number;
/**
* Gets the org's address by it's id.
*/
public async getAddress(): Promise<Address> {
if (!this.address) { return null; }
let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address });
if (!address) { throw new AddressNotFoundError; }
return address;
}
@IsObject()
address?: Address;
/**
* Creates a new RunnerOrganisation entity from this.
@@ -34,7 +22,7 @@ export class CreateRunnerOrganisation extends CreateRunnerGroup {
newRunnerOrganisation.name = this.name;
newRunnerOrganisation.contact = await this.getContact();
newRunnerOrganisation.address = await this.getAddress();
newRunnerOrganisation.address = this.address;
return newRunnerOrganisation;
}