Merge branch 'dev' into feature/93-user_endpoints
All checks were successful
continuous-integration/drone/pr Build is passing
All checks were successful
continuous-integration/drone/pr Build is passing
This commit is contained in:
35
src/models/responses/ResponseDistanceDonation.ts
Normal file
35
src/models/responses/ResponseDistanceDonation.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { IsInt, IsObject, IsPositive } from 'class-validator';
|
||||
import { DistanceDonation } from '../entities/DistanceDonation';
|
||||
import { ResponseDonation } from './ResponseDonation';
|
||||
import { ResponseRunner } from './ResponseRunner';
|
||||
|
||||
/**
|
||||
* Defines the distance donation response.
|
||||
*/
|
||||
export class ResponseDistanceDonation extends ResponseDonation {
|
||||
|
||||
/**
|
||||
* The donation's associated runner.
|
||||
* Used as the source of the donation's distance.
|
||||
*/
|
||||
@IsObject()
|
||||
runner: ResponseRunner;
|
||||
|
||||
/**
|
||||
* The donation's amount donated per distance.
|
||||
* The amount the donor set to be donated per kilometer that the runner ran.
|
||||
*/
|
||||
@IsInt()
|
||||
@IsPositive()
|
||||
amountPerDistance: number;
|
||||
|
||||
/**
|
||||
* Creates a ResponseDistanceDonation object from a scan.
|
||||
* @param donation The distance donation the response shall be build for.
|
||||
*/
|
||||
public constructor(donation: DistanceDonation) {
|
||||
super(donation);
|
||||
this.runner = donation.runner.toResponse();
|
||||
this.amountPerDistance = donation.amountPerDistance;
|
||||
}
|
||||
}
|
||||
37
src/models/responses/ResponseDonation.ts
Normal file
37
src/models/responses/ResponseDonation.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { IsInt, IsNotEmpty, IsPositive } from "class-validator";
|
||||
import { Donation } from '../entities/Donation';
|
||||
import { ResponseDonor } from './ResponseDonor';
|
||||
|
||||
/**
|
||||
* Defines the donation response.
|
||||
*/
|
||||
export class ResponseDonation {
|
||||
/**
|
||||
* The donation's id.
|
||||
*/
|
||||
@IsInt()
|
||||
@IsPositive()
|
||||
id: number;
|
||||
|
||||
/**
|
||||
* The donation's donor.
|
||||
*/
|
||||
@IsNotEmpty()
|
||||
donor: ResponseDonor;
|
||||
|
||||
/**
|
||||
* The donation's amount in the smalles unit of your currency (default: euro cent).
|
||||
*/
|
||||
@IsInt()
|
||||
amount: number;
|
||||
|
||||
/**
|
||||
* Creates a ResponseDonation object from a scan.
|
||||
* @param donation The donation the response shall be build for.
|
||||
*/
|
||||
public constructor(donation: Donation) {
|
||||
this.id = donation.id;
|
||||
this.donor = donation.donor.toResponse();
|
||||
this.amount = donation.amount;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import {
|
||||
IsBoolean
|
||||
IsBoolean, IsInt
|
||||
} from "class-validator";
|
||||
import { Donor } from '../entities/Donor';
|
||||
import { ResponseParticipant } from './ResponseParticipant';
|
||||
@@ -15,6 +15,12 @@ export class ResponseDonor extends ResponseParticipant {
|
||||
@IsBoolean()
|
||||
receiptNeeded: boolean;
|
||||
|
||||
/**
|
||||
* Returns the total donations of a donor based on his linked donations.
|
||||
*/
|
||||
@IsInt()
|
||||
donationAmount: number;
|
||||
|
||||
/**
|
||||
* Creates a ResponseRunner object from a runner.
|
||||
* @param runner The user the response shall be build for.
|
||||
@@ -22,5 +28,6 @@ export class ResponseDonor extends ResponseParticipant {
|
||||
public constructor(donor: Donor) {
|
||||
super(donor);
|
||||
this.receiptNeeded = donor.receiptNeeded;
|
||||
this.donationAmount = donor.donationAmount;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user