Reverted to id based relation setter

ref #13
This commit is contained in:
2020-12-05 17:04:22 +01:00
parent 4352910d54
commit 65b2399eaa
10 changed files with 34 additions and 79 deletions

View File

@@ -1,9 +1,8 @@
import { IsObject } from 'class-validator';
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 { CreateAddress } from './CreateAddress';
import { CreateRunnerGroup } from './CreateRunnerGroup';
export class CreateRunnerOrganisation extends CreateRunnerGroup {
@@ -12,8 +11,9 @@ export class CreateRunnerOrganisation extends CreateRunnerGroup {
* Must be of type number (address id), createAddress (new address) or address (existing address)
* Optional.
*/
@IsObject()
address?: number | CreateAddress | Address;
@IsInt()
@IsOptional()
address?: number;
/**
* Creates a Participant entity from this.
@@ -22,12 +22,6 @@ export class CreateRunnerOrganisation extends CreateRunnerGroup {
if (this.address === undefined) {
return null;
}
if (this.address! instanceof Address) {
return this.address;
}
if (this.address! instanceof CreateAddress) {
return this.address.toAddress();
}
if (!isNaN(this.address)) {
let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address });
if (!address) { throw new AddressNotFoundError; }