From 02bb6342575de23074c4117fbc93c3fc26ecd717 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 12 Jan 2021 18:07:41 +0100 Subject: [PATCH] Implemented a response donation interface ref #66 --- src/models/responses/IResponseDonation.ts | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/models/responses/IResponseDonation.ts diff --git a/src/models/responses/IResponseDonation.ts b/src/models/responses/IResponseDonation.ts new file mode 100644 index 0000000..f07b7d0 --- /dev/null +++ b/src/models/responses/IResponseDonation.ts @@ -0,0 +1,37 @@ +import { IsInt, IsNotEmpty, IsPositive } from "class-validator"; +import { Donation } from '../entities/Donation'; +import { ResponseDonor } from './ResponseDonor'; + +/** + * Defines the donation response interface. +*/ +export abstract class IResponseDonation { + /** + * The donation's id. + */ + @IsInt() + @IsPositive() + id: number; + + /** + * The donation's donor. + */ + @IsNotEmpty() + donor: ResponseDonor; + + /** + * The donation's amount in the smalles unit of your currency (default: euro cent). + */ + @IsInt() + amount: number; + + /** + * Creates a IResponseDonation object from a scan. + * @param donation The donation the response shall be build for. + */ + public constructor(donation: Donation) { + this.id = donation.id; + this.donor = donation.donor.toResponse(); + this.amount = donation.amount; + } +}