parent
6c53701a59
commit
55f72c35a6
@ -1,5 +1,6 @@
|
|||||||
import { IsInt, IsNotEmpty, IsPositive } from "class-validator";
|
import { IsInt, IsNotEmpty, IsPositive } from "class-validator";
|
||||||
import { ChildEntity, Column, ManyToOne } from "typeorm";
|
import { ChildEntity, Column, ManyToOne } from "typeorm";
|
||||||
|
import { ResponseDistanceDonation } from '../responses/ResponseDistanceDonation';
|
||||||
import { Donation } from "./Donation";
|
import { Donation } from "./Donation";
|
||||||
import { Runner } from "./Runner";
|
import { Runner } from "./Runner";
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ export class DistanceDonation extends Donation {
|
|||||||
* Get's calculated from the runner's distance ran and the amount donated per kilometer.
|
* Get's calculated from the runner's distance ran and the amount donated per kilometer.
|
||||||
*/
|
*/
|
||||||
public get amount(): number {
|
public get amount(): number {
|
||||||
let calculatedAmount = -1;
|
let calculatedAmount = 0;
|
||||||
try {
|
try {
|
||||||
calculatedAmount = this.amountPerDistance * (this.runner.distance / 1000);
|
calculatedAmount = this.amountPerDistance * (this.runner.distance / 1000);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -43,7 +44,7 @@ export class DistanceDonation extends Donation {
|
|||||||
/**
|
/**
|
||||||
* Turns this entity into it's response class.
|
* Turns this entity into it's response class.
|
||||||
*/
|
*/
|
||||||
public toResponse(): DistanceDonation {
|
public toResponse(): ResponseDistanceDonation {
|
||||||
return null;
|
return new ResponseDistanceDonation(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user