From 57b9c2babcd68d69d1cbb240a86c2897717ba758 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Sat, 16 Jan 2021 20:19:09 +0100 Subject: [PATCH] Implemented adress deletion (through reset) ref #105 --- src/models/actions/update/UpdateDonor.ts | 3 ++- src/models/actions/update/UpdateRunner.ts | 3 ++- src/models/actions/update/UpdateRunnerOrganisation.ts | 3 ++- src/models/entities/Address.ts | 8 ++++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/models/actions/update/UpdateDonor.ts b/src/models/actions/update/UpdateDonor.ts index db6a745..7b6fcfa 100644 --- a/src/models/actions/update/UpdateDonor.ts +++ b/src/models/actions/update/UpdateDonor.ts @@ -34,7 +34,8 @@ export class UpdateDonor extends CreateParticipant { donor.phone = this.phone; donor.email = this.email; donor.receiptNeeded = this.receiptNeeded; - donor.address = this.address; + if (!this.address) { donor.address.reset(); } + else { donor.address = this.address; } Address.validate(donor.address); if (this.receiptNeeded == true && Address.isValidAddress(donor.address) == false) { throw new DonorReceiptAddressNeededError() diff --git a/src/models/actions/update/UpdateRunner.ts b/src/models/actions/update/UpdateRunner.ts index 1202ad0..2df10fe 100644 --- a/src/models/actions/update/UpdateRunner.ts +++ b/src/models/actions/update/UpdateRunner.ts @@ -36,7 +36,8 @@ export class UpdateRunner extends CreateParticipant { runner.phone = this.phone; runner.email = this.email; runner.group = await this.getGroup(); - runner.address = this.address; + if (!this.address) { runner.address.reset(); } + else { runner.address = this.address; } Address.validate(runner.address); return runner; diff --git a/src/models/actions/update/UpdateRunnerOrganisation.ts b/src/models/actions/update/UpdateRunnerOrganisation.ts index e53ade1..b34bc8f 100644 --- a/src/models/actions/update/UpdateRunnerOrganisation.ts +++ b/src/models/actions/update/UpdateRunnerOrganisation.ts @@ -29,7 +29,8 @@ export class UpdateRunnerOrganisation extends CreateRunnerGroup { organisation.name = this.name; organisation.contact = await this.getContact(); - organisation.address = this.address; + if (!this.address) { organisation.address.reset(); } + else { organisation.address = this.address; } Address.validate(organisation.address); return organisation; diff --git a/src/models/entities/Address.ts b/src/models/entities/Address.ts index ea35f7c..21ec92a 100644 --- a/src/models/entities/Address.ts +++ b/src/models/entities/Address.ts @@ -58,6 +58,14 @@ export class Address { @IsNotEmpty() country: string; + public reset() { + this.address1 = null; + this.address2 = null; + this.city = null; + this.country = null; + this.postalcode = null; + } + /** * Checks if this is a valid address */