parent
ef54dd5e9c
commit
aca13f7308
@ -55,7 +55,8 @@ export class RunnerController {
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ResponseRunner(await this.runnerRepository.save(runner));
|
runner = await this.runnerRepository.save(runner)
|
||||||
|
return new ResponseRunner(await this.runnerRepository.findOne(runner, { relations: ['scans', 'group'] }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put('/:id')
|
@Put('/:id')
|
||||||
|
@ -58,9 +58,8 @@ export class RunnerOrganisationController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
runnerOrganisation = await this.runnerOrganisationRepository.save(runnerOrganisation);
|
runnerOrganisation = await this.runnerOrganisationRepository.save(runnerOrganisation);
|
||||||
runnerOrganisation = await this.runnerOrganisationRepository.findOne(runnerOrganisation, { relations: ['address', 'contact', 'teams'] });
|
|
||||||
|
|
||||||
return new ResponseRunnerOrganisation(runnerOrganisation);
|
return new ResponseRunnerOrganisation(await this.runnerOrganisationRepository.findOne(runnerOrganisation, { relations: ['address', 'contact', 'teams'] }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put('/:id')
|
@Put('/:id')
|
||||||
|
@ -28,18 +28,10 @@ export class DistanceDonation extends Donation {
|
|||||||
* The donation's amount in cents (or whatever your currency's smallest unit is.).
|
* The donation's amount in cents (or whatever your currency's smallest unit is.).
|
||||||
* The exact implementation may differ for each type of 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;
|
let calculatedAmount = -1;
|
||||||
try {
|
try {
|
||||||
calculatedAmount = this.amountPerDistance * await this.runner.distance();
|
calculatedAmount = this.amountPerDistance * this.runner.distance;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { IsInt, IsNotEmpty } from "class-validator";
|
import { IsInt, IsNotEmpty } from "class-validator";
|
||||||
import { ChildEntity, getConnectionManager, ManyToOne, OneToMany } from "typeorm";
|
import { ChildEntity, ManyToOne, OneToMany } from "typeorm";
|
||||||
import { DistanceDonation } from "./DistanceDonation";
|
import { DistanceDonation } from "./DistanceDonation";
|
||||||
import { Participant } from "./Participant";
|
import { Participant } from "./Participant";
|
||||||
import { RunnerCard } from "./RunnerCard";
|
import { RunnerCard } from "./RunnerCard";
|
||||||
@ -36,25 +36,18 @@ export class Runner extends Participant {
|
|||||||
@OneToMany(() => Scan, scan => scan.runner, { nullable: true })
|
@OneToMany(() => Scan, scan => scan.runner, { nullable: true })
|
||||||
scans: Scan[];
|
scans: Scan[];
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
* Returns all valid scans associated with this runner.
|
||||||
*/
|
*/
|
||||||
public async getValidScans(): Promise<Scan[]> {
|
public get validScans(): Scan[] {
|
||||||
return (await this.getScans()).filter(scan => { scan.valid === true });
|
return this.scans.filter(scan => { scan.valid === true });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the total distance ran by this runner.
|
* Returns the total distance ran by this runner.
|
||||||
*/
|
*/
|
||||||
@IsInt()
|
@IsInt()
|
||||||
public async distance(): Promise<number> {
|
public get distance(): number {
|
||||||
return await (await this.getValidScans()).reduce((sum, current) => sum + current.distance, 0);
|
return this.validScans.reduce((sum, current) => sum + current.distance, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,7 +15,7 @@ export class RunnerTeam extends RunnerGroup {
|
|||||||
* Optional
|
* Optional
|
||||||
*/
|
*/
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@ManyToOne(() => RunnerOrganisation, org => org.teams, { nullable: false })
|
@ManyToOne(() => RunnerOrganisation, org => org.teams, { nullable: true })
|
||||||
parentGroup?: RunnerOrganisation;
|
parentGroup?: RunnerOrganisation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user