Merge pull request 'Selfservice donations reformatting feature/187-selfservice_donation' (#188) from feature/187-selfservice_donation into dev
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
Reviewed-on: #188
This commit is contained in:
commit
d837654617
@ -35,4 +35,5 @@ export enum ResponseObjectType {
|
|||||||
USER = 'USER',
|
USER = 'USER',
|
||||||
USERGROUP = 'USERGROUP',
|
USERGROUP = 'USERGROUP',
|
||||||
USERPERMISSIONS = 'USERPERMISSIONS',
|
USERPERMISSIONS = 'USERPERMISSIONS',
|
||||||
|
SELFSERVICEDONOR = 'SELFSERVICEDONOR'
|
||||||
}
|
}
|
@ -2,6 +2,7 @@ import { IsInt, IsNotEmpty, IsPositive } from 'class-validator';
|
|||||||
import { DistanceDonation } from '../entities/DistanceDonation';
|
import { DistanceDonation } from '../entities/DistanceDonation';
|
||||||
import { ResponseObjectType } from '../enums/ResponseObjectType';
|
import { ResponseObjectType } from '../enums/ResponseObjectType';
|
||||||
import { IResponse } from './IResponse';
|
import { IResponse } from './IResponse';
|
||||||
|
import { ResponseSelfServiceDonor } from './ResponseSelfServiceDonor';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the runner selfservice donation response.
|
* Defines the runner selfservice donation response.
|
||||||
@ -18,7 +19,7 @@ export class ResponseSelfServiceDonation implements IResponse {
|
|||||||
* The donation's donor.
|
* The donation's donor.
|
||||||
*/
|
*/
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
donor: string;
|
donor: ResponseSelfServiceDonor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The donation's amount in the smalles unit of your currency (default: euro cent).
|
* 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;
|
amountPerDistance: number;
|
||||||
|
|
||||||
public constructor(donation: DistanceDonation) {
|
public constructor(donation: DistanceDonation) {
|
||||||
if (!donation.donor.middlename) { this.donor = donation.donor.firstname + " " + donation.donor.lastname; }
|
this.donor = new ResponseSelfServiceDonor(donation.donor);
|
||||||
else { this.donor = donation.donor.firstname + " " + donation.donor.middlename + " " + donation.donor.lastname; }
|
|
||||||
|
|
||||||
this.amountPerDistance = donation.amountPerDistance;
|
this.amountPerDistance = donation.amountPerDistance;
|
||||||
this.amount = donation.amount;
|
this.amount = donation.amount;
|
||||||
}
|
}
|
||||||
|
51
src/models/responses/ResponseSelfServiceDonor.ts
Normal file
51
src/models/responses/ResponseSelfServiceDonor.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -38,10 +38,10 @@ export class ResponseSelfServiceRunner extends ResponseParticipant implements IR
|
|||||||
group: string;
|
group: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The runner's associated donations.
|
* The runner's associated distance donations.
|
||||||
*/
|
*/
|
||||||
@IsString()
|
@IsString()
|
||||||
donations: ResponseSelfServiceDonation[]
|
distanceDonations: ResponseSelfServiceDonation[]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The runner's self-service jwt for auth.
|
* The runner's self-service jwt for auth.
|
||||||
@ -60,7 +60,7 @@ export class ResponseSelfServiceRunner extends ResponseParticipant implements IR
|
|||||||
this.distance = runner.distance;
|
this.distance = runner.distance;
|
||||||
this.donationAmount = runner.distanceDonationAmount;
|
this.donationAmount = runner.distanceDonationAmount;
|
||||||
this.group = this.getTeamString(runner.group);
|
this.group = this.getTeamString(runner.group);
|
||||||
this.donations = this.getDonations(runner.distanceDonations);
|
this.distanceDonations = this.getDonations(runner.distanceDonations);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user