import { IsBoolean, IsInt } from "class-validator"; import { Donor } from '../entities/Donor'; import { ResponseObjectType } from '../enums/ResponseObjectType'; import { IResponse } from './IResponse'; import { ResponseDonation } from './ResponseDonation'; import { ResponseParticipant } from './ResponseParticipant'; /** * Defines the donor response. */ export class ResponseDonor extends ResponseParticipant implements IResponse { /** * The responseType. * This contains the type of class/entity this response contains. */ responseType: ResponseObjectType = ResponseObjectType.DONOR; /** * Does this donor need a receipt? */ @IsBoolean() receiptNeeded: boolean; /** * Returns the total donations of a donor based on his linked donations. */ @IsInt() donationAmount: number; /** * Returns the total paid donations of a donor based on his linked donations. */ @IsInt() paidDonationAmount: number; donations: Array; /** * Creates a ResponseRunner object from a runner. * @param runner The user the response shall be build for. */ public constructor(donor: Donor) { super(donor); this.receiptNeeded = donor.receiptNeeded; this.donationAmount = donor.donationAmount; this.paidDonationAmount = donor.paidDonationAmount; this.donations = new Array(); if (donor.donations?.length > 0) { for (const donation of donor.donations) { this.donations.push(donation.toResponse()) } } } }