Added distance Donation
This commit is contained in:
parent
a8d1ec6f9b
commit
6c32a9ebe9
|
@ -0,0 +1,42 @@
|
|||
import { Entity, Column } from "typeorm";
|
||||
import { IsInt, IsNotEmpty, IsPositive,} from "class-validator";
|
||||
import { Donation } from "./Donation";
|
||||
import { Runner } from "./Runner";
|
||||
|
||||
/**
|
||||
* Defines a distance based donation.
|
||||
* Here people donate a certain amout per kilometer
|
||||
*/
|
||||
@Entity()
|
||||
export class DistanceDonation extends Donation {
|
||||
/**
|
||||
* The runner associated.
|
||||
*/
|
||||
@Column()
|
||||
@IsNotEmpty()
|
||||
//TODO:Relation
|
||||
runner: Runner;
|
||||
|
||||
/**
|
||||
* The amount the donor set to be donated per kilometer that the runner ran.
|
||||
*/
|
||||
@Column()
|
||||
@IsInt()
|
||||
@IsPositive()
|
||||
amountPerDistance: number;
|
||||
|
||||
/**
|
||||
* The donation's amount in cents (or whatever your currency's smallest unit is.).
|
||||
* The exact implementation may differ for each type of donation.
|
||||
*/
|
||||
@IsInt()
|
||||
public get amount(): number {
|
||||
let calculatedAmount = -1;
|
||||
try {
|
||||
calculatedAmount = this.amountPerDistance * this.runner.getDistance();
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
return calculatedAmount;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue