feat(runners): Include collected distance donation amount in runner detail

This commit is contained in:
Nicolai Ort 2025-05-01 16:02:28 +02:00
parent f4747c51de
commit 4494afc64b
Signed by: niggl
GPG Key ID: 13AFA55AF62F269F
2 changed files with 12 additions and 1 deletions

View File

@ -60,7 +60,7 @@ export class RunnerController {
@OnUndefined(RunnerNotFoundError)
@OpenAPI({ description: 'Lists all information about the runner whose id got provided.' })
async getOne(@Param('id') id: number) {
let runner = await this.runnerRepository.findOne({ id: id }, { relations: ['scans', 'group', 'group.parentGroup', 'scans.track', 'cards'] })
let runner = await this.runnerRepository.findOne({ id: id }, { relations: ['scans', 'group', 'group.parentGroup', 'scans.track', 'cards', 'distanceDonations'] })
if (!runner) { throw new RunnerNotFoundError(); }
return new ResponseRunner(runner, true);
}

View File

@ -27,6 +27,13 @@ export class ResponseRunner extends ResponseParticipant implements IResponse {
@IsInt()
distance: number;
/**
* The runner's current donation amount based on distance.
* Only available for queries for single runners.
*/
@IsInt()
donationAmount: number;
/**
* The runner's group.
*/
@ -50,6 +57,10 @@ export class ResponseRunner extends ResponseParticipant implements IResponse {
else { this.distance = runner.validScans.reduce((sum, current) => sum + current.distance, 0); }
if (runner.group) { this.group = runner.group.toResponse(); }
if (runner.distanceDonations) {
this.donationAmount = runner.distanceDonations.reduce((sum, current) => sum + (current.amountPerDistance * runner.distance / 1000), 0);
}
if (generateSelfServiceLink) {
const token = JwtCreator.createSelfService(runner);
this.selfserviceLink = `${process.env.SELFSERVICE_URL}/profile/${token}`;