From 8ae4b8582749332f4fb081eee0c520293347001f Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 14 Apr 2021 18:49:44 +0200 Subject: [PATCH] Added payedDonationAmount to donor and responsedonor ref #193 --- src/models/entities/Donor.ts | 9 +++++++++ src/models/responses/ResponseDonor.ts | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/models/entities/Donor.ts b/src/models/entities/Donor.ts index acf5536..2692e81 100644 --- a/src/models/entities/Donor.ts +++ b/src/models/entities/Donor.ts @@ -33,6 +33,15 @@ export class Donor extends Participant { return this.donations.reduce((sum, current) => sum + current.amount, 0); } + /** + * Returns the total payed donations of a donor based on his linked donations. + */ + @IsInt() + public get payedDonationAmount(): number { + if (!this.donations) { return 0; } + return this.donations.reduce((sum, current) => sum + current.payedAmount, 0); + } + /** * Turns this entity into it's response class. */ diff --git a/src/models/responses/ResponseDonor.ts b/src/models/responses/ResponseDonor.ts index 2b1e3fc..d3d2c84 100644 --- a/src/models/responses/ResponseDonor.ts +++ b/src/models/responses/ResponseDonor.ts @@ -28,6 +28,12 @@ export class ResponseDonor extends ResponseParticipant implements IResponse { @IsInt() donationAmount: number; + /** + * Returns the total payed donations of a donor based on his linked donations. + */ + @IsInt() + payedDonationAmount: number; + /** * Creates a ResponseRunner object from a runner. * @param runner The user the response shall be build for.