feat(stats): Added donation count and donor count to stats

This commit is contained in:
Nicolai Ort 2023-04-19 15:41:43 +02:00
parent 301f334674
commit 6f39ac42da
Signed by: niggl
GPG Key ID: 13AFA55AF62F269F

View File

@ -58,6 +58,18 @@ export class ResponseStats implements IResponse {
@IsInt() @IsInt()
total_donation: number; total_donation: number;
/**
* The total donation count.
*/
@IsInt()
total_donations: number;
/**
* The total donor count.
*/
@IsInt()
total_donors: number;
/** /**
* The average distance ran per runner. * The average distance ran per runner.
*/ */
@ -73,7 +85,7 @@ export class ResponseStats implements IResponse {
* @param scans Array containing all scans - no relations have to be resolved. * @param scans Array containing all scans - no relations have to be resolved.
* @param donations Array containing all donations - the following relations have to be resolved: runner, runner.scans, runner.scans.track * @param donations Array containing all donations - the following relations have to be resolved: runner, runner.scans, runner.scans.track
*/ */
public constructor(runners: number, teams: number, orgs: number, users: number, scans: number, donations: Donation[], distance: number) { public constructor(runners: number, teams: number, orgs: number, users: number, scans: number, donations: Donation[], distance: number, donors: number) {
this.total_runners = runners; this.total_runners = runners;
this.total_teams = teams; this.total_teams = teams;
this.total_orgs = orgs; this.total_orgs = orgs;
@ -81,6 +93,8 @@ export class ResponseStats implements IResponse {
this.total_scans = scans; this.total_scans = scans;
this.total_distance = distance; this.total_distance = distance;
this.total_donation = donations.reduce((sum, current) => sum + current.amount, 0); this.total_donation = donations.reduce((sum, current) => sum + current.amount, 0);
this.total_donations = donations.length;
this.total_donors = donors;
this.average_distance = this.total_distance / this.total_runners; this.average_distance = this.total_distance / this.total_runners;
} }
} }