feat(donors): Resolve donations with donors via pagination

This commit is contained in:
Nicolai Ort 2023-04-19 18:10:26 +02:00
parent b9fe9f1c24
commit 12a9ae2493
Signed by: niggl
GPG Key ID: 13AFA55AF62F269F
2 changed files with 12 additions and 1 deletions

View File

@ -53,7 +53,9 @@ export class ResponseDonation implements IResponse {
*/ */
public constructor(donation: Donation) { public constructor(donation: Donation) {
this.id = donation.id; this.id = donation.id;
this.donor = donation.donor.toResponse(); if (donation.donor) {
this.donor = donation.donor.toResponse();
}
this.amount = donation.amount; this.amount = donation.amount;
this.paidAmount = donation.paidAmount || 0; this.paidAmount = donation.paidAmount || 0;
if (this.paidAmount < this.amount) { if (this.paidAmount < this.amount) {

View File

@ -4,6 +4,7 @@ import {
import { Donor } from '../entities/Donor'; import { Donor } from '../entities/Donor';
import { ResponseObjectType } from '../enums/ResponseObjectType'; import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse'; import { IResponse } from './IResponse';
import { ResponseDonation } from './ResponseDonation';
import { ResponseParticipant } from './ResponseParticipant'; import { ResponseParticipant } from './ResponseParticipant';
/** /**
@ -34,6 +35,8 @@ export class ResponseDonor extends ResponseParticipant implements IResponse {
@IsInt() @IsInt()
paidDonationAmount: number; paidDonationAmount: number;
donations: Array<ResponseDonation>;
/** /**
* Creates a ResponseRunner object from a runner. * Creates a ResponseRunner object from a runner.
* @param runner The user the response shall be build for. * @param runner The user the response shall be build for.
@ -43,5 +46,11 @@ export class ResponseDonor extends ResponseParticipant implements IResponse {
this.receiptNeeded = donor.receiptNeeded; this.receiptNeeded = donor.receiptNeeded;
this.donationAmount = donor.donationAmount; this.donationAmount = donor.donationAmount;
this.paidDonationAmount = donor.paidDonationAmount; this.paidDonationAmount = donor.paidDonationAmount;
this.donations = new Array<ResponseDonation>();
if (donor.donations?.length > 0) {
for (const donation of donor.donations) {
this.donations.push(donation.toResponse())
}
}
} }
} }