diff --git a/src/controllers/RunnerController.ts b/src/controllers/RunnerController.ts index 6885d3c..14658da 100644 --- a/src/controllers/RunnerController.ts +++ b/src/controllers/RunnerController.ts @@ -24,7 +24,8 @@ export class RunnerController { @OpenAPI({ description: 'Lists all runners.' }) async getAll() { let responseRunners: ResponseRunner[] = new Array(); - const runners = await this.runnerRepository.find(); + const runners = await this.runnerRepository.find({ relations: ['scans', 'group'] }); + console.log(runners); runners.forEach(runner => { responseRunners.push(new ResponseRunner(runner)); }); @@ -37,7 +38,7 @@ export class RunnerController { @OnUndefined(RunnerNotFoundError) @OpenAPI({ description: 'Returns a runner of a specified id (if it exists)' }) async getOne(@Param('id') id: number) { - return new ResponseRunner(await this.runnerRepository.findOne({ id: id })); + return new ResponseRunner(await this.runnerRepository.findOne({ id: id }, { relations: ['scans', 'group'] })); } @Post() diff --git a/src/controllers/RunnerOrganisationController.ts b/src/controllers/RunnerOrganisationController.ts index 2ad2e25..bee281f 100644 --- a/src/controllers/RunnerOrganisationController.ts +++ b/src/controllers/RunnerOrganisationController.ts @@ -27,7 +27,7 @@ export class RunnerOrganisationController { @ResponseSchema(RunnerOrganisation, { isArray: true }) @OpenAPI({ description: 'Lists all runnerOrganisations.' }) getAll() { - return this.runnerOrganisationRepository.find(); + return this.runnerOrganisationRepository.find({ relations: ['address', 'contact', 'teams'] }); } @Get('/:id') @@ -36,7 +36,7 @@ export class RunnerOrganisationController { @OnUndefined(RunnerOrganisationNotFoundError) @OpenAPI({ description: 'Returns a runnerOrganisation of a specified id (if it exists)' }) getOne(@Param('id') id: number) { - return this.runnerOrganisationRepository.findOne({ id: id }); + return this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['address', 'contact', 'teams'] }); } @Post() @@ -59,7 +59,7 @@ export class RunnerOrganisationController { @ResponseSchema(RunnerOrganisationIdsNotMatchingError, { statusCode: 406 }) @OpenAPI({ description: "Update a runnerOrganisation object (id can't be changed)." }) async put(@Param('id') id: number, @EntityFromBody() runnerOrganisation: RunnerOrganisation) { - let oldRunnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id }); + let oldRunnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['address', 'contact', 'teams'] }); if (!oldRunnerOrganisation) { throw new RunnerOrganisationNotFoundError(); @@ -80,7 +80,7 @@ export class RunnerOrganisationController { @ResponseSchema(RunnerOrganisationHasTeamsError, { statusCode: 406 }) @OpenAPI({ description: 'Delete a specified runnerOrganisation (if it exists).' }) async remove(@Param('id') id: number, @QueryParam("force") force: boolean) { - let runnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id }); + let runnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['address', 'contact', 'teams'] }); if (!runnerOrganisation) { throw new RunnerOrganisationNotFoundError(); diff --git a/src/controllers/RunnerTeamController.ts b/src/controllers/RunnerTeamController.ts index ecbe9a2..37b4c9d 100644 --- a/src/controllers/RunnerTeamController.ts +++ b/src/controllers/RunnerTeamController.ts @@ -25,7 +25,7 @@ export class RunnerTeamController { @ResponseSchema(RunnerTeam, { isArray: true }) @OpenAPI({ description: 'Lists all runnerTeams.' }) getAll() { - return this.runnerTeamRepository.find(); + return this.runnerTeamRepository.find({ relations: ['parentGroup', 'contact'] }); } @Get('/:id') @@ -34,7 +34,7 @@ export class RunnerTeamController { @OnUndefined(RunnerTeamNotFoundError) @OpenAPI({ description: 'Returns a runnerTeam of a specified id (if it exists)' }) getOne(@Param('id') id: number) { - return this.runnerTeamRepository.findOne({ id: id }); + return this.runnerTeamRepository.findOne({ id: id }, { relations: ['parentGroup', 'contact'] }); } @Post() @@ -57,7 +57,7 @@ export class RunnerTeamController { @ResponseSchema(RunnerTeamIdsNotMatchingError, { statusCode: 406 }) @OpenAPI({ description: "Update a runnerTeam object (id can't be changed)." }) async put(@Param('id') id: number, @EntityFromBody() runnerTeam: RunnerTeam) { - let oldRunnerTeam = await this.runnerTeamRepository.findOne({ id: id }); + let oldRunnerTeam = await this.runnerTeamRepository.findOne({ id: id }, { relations: ['parentGroup', 'contact'] }); if (!oldRunnerTeam) { throw new RunnerTeamNotFoundError(); @@ -77,7 +77,7 @@ export class RunnerTeamController { @ResponseSchema(RunnerTeamHasRunnersError, { statusCode: 406 }) @OpenAPI({ description: 'Delete a specified runnerTeam (if it exists).' }) async remove(@Param('id') id: number, @QueryParam("force") force: boolean) { - let runnerTeam = await this.runnerTeamRepository.findOne({ id: id }); + let runnerTeam = await this.runnerTeamRepository.findOne({ id: id }, { relations: ['parentGroup', 'contact'] }); if (!runnerTeam) { throw new RunnerTeamNotFoundError(); diff --git a/src/models/entities/Runner.ts b/src/models/entities/Runner.ts index 7a8d0ad..2496d98 100644 --- a/src/models/entities/Runner.ts +++ b/src/models/entities/Runner.ts @@ -54,7 +54,7 @@ export class Runner extends Participant { * Returns the total distance ran by this runner. */ @IsInt() - public async distance(): Promise { - return await (await this.getValidScans()).reduce((sum, current) => sum + current.distance, 0); + public get distance(): number { + return 0; } } \ No newline at end of file diff --git a/src/models/responses/ResponseRunner.ts b/src/models/responses/ResponseRunner.ts index b2f3dfe..591c0a3 100644 --- a/src/models/responses/ResponseRunner.ts +++ b/src/models/responses/ResponseRunner.ts @@ -72,7 +72,7 @@ export class ResponseRunner { this.lastname = runner.lastname; this.phone = runner.phone; this.email = runner.email; - this.distance = runner.distance; + this.distance = runner.scans.reduce((sum, current) => sum + current.distance, 0); this.group = runner.group; } }