Added donor donation amount to the donor response
Some checks failed
continuous-integration/drone/pr Build is failing

ref #66
This commit is contained in:
2021-01-13 17:32:10 +01:00
parent cd5e4bbd60
commit bba35d189e
4 changed files with 26 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
import { IsBoolean } from "class-validator";
import { IsBoolean, IsInt } from "class-validator";
import { ChildEntity, Column, OneToMany } from "typeorm";
import { ResponseDonor } from '../responses/ResponseDonor';
import { Donation } from './Donation';
@@ -24,6 +24,15 @@ export class Donor extends Participant {
@OneToMany(() => Donation, donation => donation.donor, { nullable: true })
donations: Donation[];
/**
* Returns the total donations of a donor based on his linked donations.
*/
@IsInt()
public get donationAmount(): number {
if (!this.donations) { return 0; }
return this.donations.reduce((sum, current) => sum + current.amount, 0);
}
/**
* Turns this entity into it's response class.
*/