Relations for distanceDonation

ref #11
This commit is contained in:
Nicolai Ort 2020-12-01 19:10:52 +01:00
parent dca9aef258
commit 1c43442300
2 changed files with 8 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import { Entity, Column } from "typeorm";
import { Entity, Column, ManyToOne } from "typeorm";
import { IsInt, IsNotEmpty, IsPositive,} from "class-validator";
import { Donation } from "./Donation";
import { Runner } from "./Runner";
@ -14,7 +14,7 @@ export class DistanceDonation extends Donation {
*/
@Column()
@IsNotEmpty()
//TODO:Relation
@ManyToOne(() => Runner, runner => runner.distanceDonations)
runner: Runner;
/**
@ -33,7 +33,7 @@ export class DistanceDonation extends Donation {
public get amount(): number {
let calculatedAmount = -1;
try {
//calculatedAmount = this.amountPerDistance * this.runner.getDistance();
calculatedAmount = this.amountPerDistance * this.runner.getDistance();
} catch (error) {
throw error;
}

View File

@ -1,7 +1,8 @@
import { Entity, Column } from "typeorm";
import { Entity, Column, OneToMany } from "typeorm";
import { IsNotEmpty,} from "class-validator";
import { Participant } from "./Participant";
import { RunnerGroup } from "./RunnerGroup";
import { DistanceDonation } from "./DistanceDonation";
/**
* Defines a runner.
@ -15,4 +16,7 @@ export class Runner extends Participant {
@IsNotEmpty()
//TODO:Relation
group: RunnerGroup;
@OneToMany(() => DistanceDonation, distanceDonation => distanceDonation.runner)
distanceDonations: DistanceDonation[];
}