Switched the update classes over to the new address implementation
ref #105
This commit is contained in:
parent
2cd15d25e9
commit
d0df5dd641
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue