From b89f7ac1b4ddd6e53e6e2e8330c1fa2170b48591 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 20 Jan 2021 19:43:20 +0100 Subject: [PATCH] Created a donation respoinse class for the runner selfservice ref #111 --- .../responses/ResponseSelfServiceDonation.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/models/responses/ResponseSelfServiceDonation.ts diff --git a/src/models/responses/ResponseSelfServiceDonation.ts b/src/models/responses/ResponseSelfServiceDonation.ts new file mode 100644 index 0000000..4f10f3c --- /dev/null +++ b/src/models/responses/ResponseSelfServiceDonation.ts @@ -0,0 +1,36 @@ +import { IsInt, IsNotEmpty, IsPositive } from 'class-validator'; +import { DistanceDonation } from '../entities/DistanceDonation'; + +/** + * Defines the runner selfservice donation response. + * Why? B/C runner's are not allowed to view all information available to admin users. +*/ +export class ResponseSelfServiceDonation { + /** + * The donation's donor. + */ + @IsNotEmpty() + donor: string; + + /** + * The donation's amount in the smalles unit of your currency (default: euro cent). + */ + @IsInt() + amount: number; + + /** + * The donation's amount donated per distance. + * The amount the donor set to be donated per kilometer that the runner ran. + */ + @IsInt() + @IsPositive() + amountPerDistance: number; + + public constructor(donation: DistanceDonation) { + if (!donation.donor.middlename) { this.donor = donation.donor.firstname + " " + donation.donor.lastname; } + else { this.donor = donation.donor.firstname + " " + donation.donor.middlename + " " + donation.donor.lastname; } + + this.amountPerDistance = donation.amountPerDistance; + this.amount = donation.amount; + } +} \ No newline at end of file