diff --git a/src/models/enums/ResponseObjectType.ts b/src/models/enums/ResponseObjectType.ts index c7fc527..91423cf 100644 --- a/src/models/enums/ResponseObjectType.ts +++ b/src/models/enums/ResponseObjectType.ts @@ -35,4 +35,5 @@ export enum ResponseObjectType { USER = 'USER', USERGROUP = 'USERGROUP', USERPERMISSIONS = 'USERPERMISSIONS', + SELFSERVICEDONOR = 'SELFSERVICEDONOR' } \ No newline at end of file diff --git a/src/models/responses/ResponseSelfServiceDonation.ts b/src/models/responses/ResponseSelfServiceDonation.ts index beb8fdc..38d5abf 100644 --- a/src/models/responses/ResponseSelfServiceDonation.ts +++ b/src/models/responses/ResponseSelfServiceDonation.ts @@ -2,6 +2,7 @@ import { IsInt, IsNotEmpty, IsPositive } from 'class-validator'; import { DistanceDonation } from '../entities/DistanceDonation'; import { ResponseObjectType } from '../enums/ResponseObjectType'; import { IResponse } from './IResponse'; +import { ResponseSelfServiceDonor } from './ResponseSelfServiceDonor'; /** * Defines the runner selfservice donation response. @@ -18,7 +19,7 @@ export class ResponseSelfServiceDonation implements IResponse { * The donation's donor. */ @IsNotEmpty() - donor: string; + donor: ResponseSelfServiceDonor; /** * The donation's amount in the smalles unit of your currency (default: euro cent). @@ -35,9 +36,7 @@ export class ResponseSelfServiceDonation implements IResponse { amountPerDistance: number; public constructor(donation: DistanceDonation) { - if (!donation.donor.middlename) { this.donor = donation.donor.firstname + " " + donation.donor.lastname; } - else { this.donor = donation.donor.firstname + " " + donation.donor.middlename + " " + donation.donor.lastname; } - + this.donor = new ResponseSelfServiceDonor(donation.donor); this.amountPerDistance = donation.amountPerDistance; this.amount = donation.amount; } diff --git a/src/models/responses/ResponseSelfServiceDonor.ts b/src/models/responses/ResponseSelfServiceDonor.ts new file mode 100644 index 0000000..a305233 --- /dev/null +++ b/src/models/responses/ResponseSelfServiceDonor.ts @@ -0,0 +1,51 @@ +import { IsInt, IsString } from "class-validator"; +import { Donor } from '../entities/Donor'; +import { ResponseObjectType } from '../enums/ResponseObjectType'; +import { IResponse } from './IResponse'; + +/** + * Defines the donor selfservice response. + * Why? B/C runner's are not allowed to view all information available to admin users. +*/ +export class ResponseSelfServiceDonor implements IResponse { + /** + * The responseType. + * This contains the type of class/entity this response contains. + */ + responseType: ResponseObjectType = ResponseObjectType.SELFSERVICEDONOR; + + /** + * The participant's id. + */ + @IsInt() + id: number; + + /** + * The participant's first name. + */ + @IsString() + firstname: string; + + /** + * The participant's middle name. + */ + @IsString() + middlename?: string; + + /** + * The participant's last name. + */ + @IsString() + lastname: string; + + /** + * Creates a ResponseSelfServiceDonor object from a runner. + * @param donor The donor the response shall be build for. + */ + public constructor(donor: Donor) { + this.id = donor.id; + this.firstname = donor.firstname; + this.middlename = donor.middlename; + this.lastname = donor.lastname; + } +} diff --git a/src/models/responses/ResponseSelfServiceRunner.ts b/src/models/responses/ResponseSelfServiceRunner.ts index 00fe9b9..f558e82 100644 --- a/src/models/responses/ResponseSelfServiceRunner.ts +++ b/src/models/responses/ResponseSelfServiceRunner.ts @@ -38,10 +38,10 @@ export class ResponseSelfServiceRunner extends ResponseParticipant implements IR group: string; /** - * The runner's associated donations. + * The runner's associated distance donations. */ @IsString() - donations: ResponseSelfServiceDonation[] + distanceDonations: ResponseSelfServiceDonation[] /** * The runner's self-service jwt for auth. @@ -60,7 +60,7 @@ export class ResponseSelfServiceRunner extends ResponseParticipant implements IR this.distance = runner.distance; this.donationAmount = runner.distanceDonationAmount; this.group = this.getTeamString(runner.group); - this.donations = this.getDonations(runner.distanceDonations); + this.distanceDonations = this.getDonations(runner.distanceDonations); } /**