Merge pull request 'Selfservice donations reformatting feature/187-selfservice_donation' (#188) from feature/187-selfservice_donation into dev
continuous-integration/drone/push Build was killed Details

Reviewed-on: #188
This commit is contained in:
Nicolai Ort 2021-04-03 16:13:34 +00:00
commit d837654617
4 changed files with 58 additions and 7 deletions

View File

@ -35,4 +35,5 @@ export enum ResponseObjectType {
USER = 'USER',
USERGROUP = 'USERGROUP',
USERPERMISSIONS = 'USERPERMISSIONS',
SELFSERVICEDONOR = 'SELFSERVICEDONOR'
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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);
}
/**