Added donor donation amount to the donor response
Some checks failed
continuous-integration/drone/pr Build is failing
Some checks failed
continuous-integration/drone/pr Build is failing
ref #66
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user