Switched the update classes over to the new address implementation

ref #105
This commit is contained in:
Nicolai Ort 2021-01-16 16:56:46 +01:00
parent 2cd15d25e9
commit d0df5dd641
3 changed files with 6 additions and 18 deletions

View File

@ -33,7 +33,7 @@ export class UpdateDonor extends CreateParticipant {
donor.phone = this.phone;
donor.email = this.email;
donor.receiptNeeded = this.receiptNeeded;
donor.address = await this.getAddress();
donor.address = this.address;
if (this.receiptNeeded == true && this.address == null) {
throw new DonorReceiptAddressNeededError()

View File

@ -35,7 +35,7 @@ export class UpdateRunner extends CreateParticipant {
runner.phone = this.phone;
runner.email = this.email;
runner.group = await this.getGroup();
runner.address = await this.getAddress();
runner.address = this.address;
return runner;
}

View File

@ -1,6 +1,4 @@
import { IsInt, IsOptional } from 'class-validator';
import { getConnectionManager } from 'typeorm';
import { AddressNotFoundError } from '../../../errors/AddressErrors';
import { IsInt, IsObject, IsOptional } from 'class-validator';
import { Address } from '../../entities/Address';
import { RunnerOrganisation } from '../../entities/RunnerOrganisation';
import { CreateRunnerGroup } from '../create/CreateRunnerGroup';
@ -20,19 +18,9 @@ export class UpdateRunnerOrganisation extends CreateRunnerGroup {
/**
* The updated organisation's address's id.
*/
@IsInt()
@IsOptional()
address?: number;
/**
* Loads the organisation's address based on 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;
/**
* Updates a provided RunnerOrganisation entity based on this.
@ -41,7 +29,7 @@ export class UpdateRunnerOrganisation extends CreateRunnerGroup {
organisation.name = this.name;
organisation.contact = await this.getContact();
organisation.address = await this.getAddress();
organisation.address = this.address;
return organisation;
}