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.' })
|
@OpenAPI({ description: 'Lists all runners.' })
|
||||||
async getAll() {
|
async getAll() {
|
||||||
let responseRunners: ResponseRunner[] = new Array<ResponseRunner>();
|
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 => {
|
runners.forEach(runner => {
|
||||||
responseRunners.push(new ResponseRunner(runner));
|
responseRunners.push(new ResponseRunner(runner));
|
||||||
});
|
});
|
||||||
@ -37,7 +38,7 @@ export class RunnerController {
|
|||||||
@OnUndefined(RunnerNotFoundError)
|
@OnUndefined(RunnerNotFoundError)
|
||||||
@OpenAPI({ description: 'Returns a runner of a specified id (if it exists)' })
|
@OpenAPI({ description: 'Returns a runner of a specified id (if it exists)' })
|
||||||
async getOne(@Param('id') id: number) {
|
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()
|
@Post()
|
||||||
|
@ -27,7 +27,7 @@ export class RunnerOrganisationController {
|
|||||||
@ResponseSchema(RunnerOrganisation, { isArray: true })
|
@ResponseSchema(RunnerOrganisation, { isArray: true })
|
||||||
@OpenAPI({ description: 'Lists all runnerOrganisations.' })
|
@OpenAPI({ description: 'Lists all runnerOrganisations.' })
|
||||||
getAll() {
|
getAll() {
|
||||||
return this.runnerOrganisationRepository.find();
|
return this.runnerOrganisationRepository.find({ relations: ['address', 'contact', 'teams'] });
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('/:id')
|
@Get('/:id')
|
||||||
@ -36,7 +36,7 @@ export class RunnerOrganisationController {
|
|||||||
@OnUndefined(RunnerOrganisationNotFoundError)
|
@OnUndefined(RunnerOrganisationNotFoundError)
|
||||||
@OpenAPI({ description: 'Returns a runnerOrganisation of a specified id (if it exists)' })
|
@OpenAPI({ description: 'Returns a runnerOrganisation of a specified id (if it exists)' })
|
||||||
getOne(@Param('id') id: number) {
|
getOne(@Param('id') id: number) {
|
||||||
return this.runnerOrganisationRepository.findOne({ id: id });
|
return this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['address', 'contact', 'teams'] });
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ -59,7 +59,7 @@ export class RunnerOrganisationController {
|
|||||||
@ResponseSchema(RunnerOrganisationIdsNotMatchingError, { statusCode: 406 })
|
@ResponseSchema(RunnerOrganisationIdsNotMatchingError, { statusCode: 406 })
|
||||||
@OpenAPI({ description: "Update a runnerOrganisation object (id can't be changed)." })
|
@OpenAPI({ description: "Update a runnerOrganisation object (id can't be changed)." })
|
||||||
async put(@Param('id') id: number, @EntityFromBody() runnerOrganisation: RunnerOrganisation) {
|
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) {
|
if (!oldRunnerOrganisation) {
|
||||||
throw new RunnerOrganisationNotFoundError();
|
throw new RunnerOrganisationNotFoundError();
|
||||||
@ -80,7 +80,7 @@ export class RunnerOrganisationController {
|
|||||||
@ResponseSchema(RunnerOrganisationHasTeamsError, { statusCode: 406 })
|
@ResponseSchema(RunnerOrganisationHasTeamsError, { statusCode: 406 })
|
||||||
@OpenAPI({ description: 'Delete a specified runnerOrganisation (if it exists).' })
|
@OpenAPI({ description: 'Delete a specified runnerOrganisation (if it exists).' })
|
||||||
async remove(@Param('id') id: number, @QueryParam("force") force: boolean) {
|
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) {
|
if (!runnerOrganisation) {
|
||||||
throw new RunnerOrganisationNotFoundError();
|
throw new RunnerOrganisationNotFoundError();
|
||||||
|
@ -25,7 +25,7 @@ export class RunnerTeamController {
|
|||||||
@ResponseSchema(RunnerTeam, { isArray: true })
|
@ResponseSchema(RunnerTeam, { isArray: true })
|
||||||
@OpenAPI({ description: 'Lists all runnerTeams.' })
|
@OpenAPI({ description: 'Lists all runnerTeams.' })
|
||||||
getAll() {
|
getAll() {
|
||||||
return this.runnerTeamRepository.find();
|
return this.runnerTeamRepository.find({ relations: ['parentGroup', 'contact'] });
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('/:id')
|
@Get('/:id')
|
||||||
@ -34,7 +34,7 @@ export class RunnerTeamController {
|
|||||||
@OnUndefined(RunnerTeamNotFoundError)
|
@OnUndefined(RunnerTeamNotFoundError)
|
||||||
@OpenAPI({ description: 'Returns a runnerTeam of a specified id (if it exists)' })
|
@OpenAPI({ description: 'Returns a runnerTeam of a specified id (if it exists)' })
|
||||||
getOne(@Param('id') id: number) {
|
getOne(@Param('id') id: number) {
|
||||||
return this.runnerTeamRepository.findOne({ id: id });
|
return this.runnerTeamRepository.findOne({ id: id }, { relations: ['parentGroup', 'contact'] });
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ -57,7 +57,7 @@ export class RunnerTeamController {
|
|||||||
@ResponseSchema(RunnerTeamIdsNotMatchingError, { statusCode: 406 })
|
@ResponseSchema(RunnerTeamIdsNotMatchingError, { statusCode: 406 })
|
||||||
@OpenAPI({ description: "Update a runnerTeam object (id can't be changed)." })
|
@OpenAPI({ description: "Update a runnerTeam object (id can't be changed)." })
|
||||||
async put(@Param('id') id: number, @EntityFromBody() runnerTeam: RunnerTeam) {
|
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) {
|
if (!oldRunnerTeam) {
|
||||||
throw new RunnerTeamNotFoundError();
|
throw new RunnerTeamNotFoundError();
|
||||||
@ -77,7 +77,7 @@ export class RunnerTeamController {
|
|||||||
@ResponseSchema(RunnerTeamHasRunnersError, { statusCode: 406 })
|
@ResponseSchema(RunnerTeamHasRunnersError, { statusCode: 406 })
|
||||||
@OpenAPI({ description: 'Delete a specified runnerTeam (if it exists).' })
|
@OpenAPI({ description: 'Delete a specified runnerTeam (if it exists).' })
|
||||||
async remove(@Param('id') id: number, @QueryParam("force") force: boolean) {
|
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) {
|
if (!runnerTeam) {
|
||||||
throw new RunnerTeamNotFoundError();
|
throw new RunnerTeamNotFoundError();
|
||||||
|
@ -54,7 +54,7 @@ export class Runner extends Participant {
|
|||||||
* 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 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -72,7 +72,7 @@ export class ResponseRunner {
|
|||||||
this.lastname = runner.lastname;
|
this.lastname = runner.lastname;
|
||||||
this.phone = runner.phone;
|
this.phone = runner.phone;
|
||||||
this.email = runner.email;
|
this.email = runner.email;
|
||||||
this.distance = runner.distance;
|
this.distance = runner.scans.reduce((sum, current) => sum + current.distance, 0);
|
||||||
this.group = runner.group;
|
this.group = runner.group;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user