Merge branch 'dev' into feature/12-jwt-creation
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Entity, Column, ManyToOne, ChildEntity } from "typeorm";
|
||||
import { IsInt, IsNotEmpty, IsPositive, } from "class-validator";
|
||||
import { IsInt, IsNotEmpty, IsPositive } from "class-validator";
|
||||
import { ChildEntity, Column, ManyToOne } from "typeorm";
|
||||
import { Donation } from "./Donation";
|
||||
import { Runner } from "./Runner";
|
||||
|
||||
@@ -29,10 +29,17 @@ export class DistanceDonation extends Donation {
|
||||
* The exact implementation may differ for each type of donation.
|
||||
*/
|
||||
@IsInt()
|
||||
public get amount(): number {
|
||||
public get amount() {
|
||||
return this.getAmount();
|
||||
}
|
||||
|
||||
/**
|
||||
* The function that calculates the amount based on the runner object's distance.
|
||||
*/
|
||||
public async getAmount(): Promise<number> {
|
||||
let calculatedAmount = -1;
|
||||
try {
|
||||
calculatedAmount = this.amountPerDistance * this.runner.distance;
|
||||
calculatedAmount = this.amountPerDistance * await this.runner.distance();
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { PrimaryGeneratedColumn, Column, ManyToOne, Entity, TableInheritance } from "typeorm";
|
||||
import {
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsPositive,
|
||||
IsOptional
|
||||
} from "class-validator";
|
||||
import { Entity, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
|
||||
import { Participant } from "./Participant";
|
||||
|
||||
/**
|
||||
@@ -32,5 +31,5 @@ export abstract class Donation {
|
||||
* The donation's amount in cents (or whatever your currency's smallest unit is.).
|
||||
* The exact implementation may differ for each type of donation.
|
||||
*/
|
||||
abstract amount: number;
|
||||
abstract amount: number | Promise<number>;
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Entity, Column, OneToMany, ManyToOne, ChildEntity } from "typeorm";
|
||||
import { IsInt, IsNotEmpty, } from "class-validator";
|
||||
import { Participant } from "./Participant";
|
||||
import { RunnerGroup } from "./RunnerGroup";
|
||||
import { IsInt, IsNotEmpty } from "class-validator";
|
||||
import { ChildEntity, getConnectionManager, ManyToOne, OneToMany } from "typeorm";
|
||||
import { DistanceDonation } from "./DistanceDonation";
|
||||
import { Participant } from "./Participant";
|
||||
import { RunnerCard } from "./RunnerCard";
|
||||
import { RunnerGroup } from "./RunnerGroup";
|
||||
import { Scan } from "./Scan";
|
||||
|
||||
/**
|
||||
@@ -36,9 +36,25 @@ export class Runner extends Participant {
|
||||
@OneToMany(() => Scan, scan => scan.runner, { nullable: true })
|
||||
scans: Scan[];
|
||||
|
||||
@IsInt()
|
||||
public get distance(): number {
|
||||
return this.scans.filter(scan => scan.valid === true).reduce((sum, current) => sum + current.distance, 0);
|
||||
/**
|
||||
* Returns all scans associated with this runner.
|
||||
*/
|
||||
public async getScans(): Promise<Scan[]> {
|
||||
return await getConnectionManager().get().getRepository(Scan).find({ runner: this });
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Returns all valid scans associated with this runner.
|
||||
*/
|
||||
public async getValidScans(): Promise<Scan[]> {
|
||||
return (await this.getScans()).filter(scan => { scan.valid === true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total distance ran by this runner.
|
||||
*/
|
||||
@IsInt()
|
||||
public async distance(): Promise<number> {
|
||||
return await (await this.getValidScans()).reduce((sum, current) => sum + current.distance, 0);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, Entity, TableInheritance } from "typeorm";
|
||||
import {
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString,
|
||||
IsString
|
||||
} from "class-validator";
|
||||
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
|
||||
import { GroupContact } from "./GroupContact";
|
||||
import { Runner } from "./Runner";
|
||||
import { RunnerTeam } from "./RunnerTeam";
|
||||
|
||||
/**
|
||||
* Defines the runnerGroup interface.
|
||||
@@ -44,4 +43,6 @@ export abstract class RunnerGroup {
|
||||
*/
|
||||
@OneToMany(() => Runner, runner => runner.group, { nullable: true })
|
||||
runners: Runner[];
|
||||
|
||||
public abstract getRunners();
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Entity, Column, ManyToOne, OneToMany, ChildEntity } from "typeorm";
|
||||
import { IsOptional, } from "class-validator";
|
||||
import { RunnerGroup } from "./RunnerGroup";
|
||||
import { IsOptional } from "class-validator";
|
||||
import { ChildEntity, getConnectionManager, ManyToOne, OneToMany } from "typeorm";
|
||||
import { Address } from "./Address";
|
||||
import { Runner } from './Runner';
|
||||
import { RunnerGroup } from "./RunnerGroup";
|
||||
import { RunnerTeam } from "./RunnerTeam";
|
||||
|
||||
/**
|
||||
@@ -23,4 +24,27 @@ export class RunnerOrganisation extends RunnerGroup {
|
||||
*/
|
||||
@OneToMany(() => RunnerTeam, team => team.parentGroup, { nullable: true })
|
||||
teams: RunnerTeam[];
|
||||
|
||||
|
||||
/**
|
||||
* Returns all runners associated with this organisation or it's teams.
|
||||
*/
|
||||
public async getRunners() {
|
||||
let runners: Runner[] = new Array<Runner>();
|
||||
const teams = await this.getTeams();
|
||||
|
||||
await teams.forEach(async team => {
|
||||
runners.push(... await team.getRunners());
|
||||
});
|
||||
await runners.push(... await getConnectionManager().get().getRepository(Runner).find({ group: this }));
|
||||
|
||||
return runners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all teams associated with this organisation.
|
||||
*/
|
||||
public async getTeams() {
|
||||
return await getConnectionManager().get().getRepository(RunnerTeam).find({ parentGroup: this });
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Entity, Column, ManyToOne, ChildEntity } from "typeorm";
|
||||
import { IsNotEmpty } from "class-validator";
|
||||
import { ChildEntity, getConnectionManager, ManyToOne } from "typeorm";
|
||||
import { Runner } from './Runner';
|
||||
import { RunnerGroup } from "./RunnerGroup";
|
||||
import { RunnerOrganisation } from "./RunnerOrganisation";
|
||||
|
||||
@@ -16,4 +17,11 @@ export class RunnerTeam extends RunnerGroup {
|
||||
@IsNotEmpty()
|
||||
@ManyToOne(() => RunnerOrganisation, org => org.teams, { nullable: true })
|
||||
parentGroup?: RunnerOrganisation;
|
||||
|
||||
/**
|
||||
* Returns all runners associated with this team.
|
||||
*/
|
||||
public async getRunners() {
|
||||
return await getConnectionManager().get().getRepository(Runner).find({ group: this });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user