Part 1 of the relation fix
This commit is contained in:
parent
056413560e
commit
c53e94d205
|
@ -24,7 +24,8 @@ export class RunnerController {
|
|||
@OpenAPI({ description: 'Lists all runners.' })
|
||||
async getAll() {
|
||||
let responseRunners: ResponseRunner[] = new Array<ResponseRunner>();
|
||||
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()
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -54,7 +54,7 @@ export class Runner extends Participant {
|
|||
* 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);
|
||||
public get distance(): number {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue