From 570c34bed04e359f389a8f427486bf92891f1dcb Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 26 Jan 2021 20:06:54 +0100 Subject: [PATCH] Created the organizations/runners endpoint ref #125 --- .../RunnerOrganizationController.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/controllers/RunnerOrganizationController.ts b/src/controllers/RunnerOrganizationController.ts index b39e3cc..a74c103 100644 --- a/src/controllers/RunnerOrganizationController.ts +++ b/src/controllers/RunnerOrganizationController.ts @@ -4,8 +4,10 @@ import { getConnectionManager, Repository } from 'typeorm'; import { RunnerOrganizationHasRunnersError, RunnerOrganizationHasTeamsError, RunnerOrganizationIdsNotMatchingError, RunnerOrganizationNotFoundError } from '../errors/RunnerOrganizationErrors'; import { CreateRunnerOrganization } from '../models/actions/create/CreateRunnerOrganization'; import { UpdateRunnerOrganization } from '../models/actions/update/UpdateRunnerOrganization'; +import { Runner } from '../models/entities/Runner'; import { RunnerOrganization } from '../models/entities/RunnerOrganization'; import { ResponseEmpty } from '../models/responses/ResponseEmpty'; +import { ResponseRunner } from '../models/responses/ResponseRunner'; import { ResponseRunnerOrganization } from '../models/responses/ResponseRunnerOrganization'; import { RunnerController } from './RunnerController'; import { RunnerTeamController } from './RunnerTeamController'; @@ -48,6 +50,22 @@ export class RunnerOrganizationController { return new ResponseRunnerOrganization(runnerOrg); } + @Get('/:id/runners') + @Authorized(["RUNNER:GET", "SCAN:GET"]) + @ResponseSchema(ResponseRunner, { isArray: true }) + @ResponseSchema(RunnerOrganizationNotFoundError, { statusCode: 404 }) + @OpenAPI({ description: 'Lists all runners from this org and it\'s teams (if you don\'t provide the ?onlyDirect=true param).
This includes the runner\'s group and distance ran.' }) + async getRunners(@Param('id') id: number, @QueryParam('onlyDirect') onlyDirect: boolean) { + let responseRunners: ResponseRunner[] = new Array(); + let runners: Runner[]; + if (!onlyDirect) { runners = (await this.runnerOrganizationRepository.findOne({ id: id }, { relations: ['runners', 'runners.group', 'runners.scans', 'runners.scans.track', 'teams', 'teams.runners', 'teams.runners.group', 'teams.runners.scans', 'teams.runners.scans.track'] })).allRunners; } + else { runners = (await this.runnerOrganizationRepository.findOne({ id: id }, { relations: ['runners', 'runners.group', 'runners.scans', 'runners.scans.track'] })).runners; } + runners.forEach(runner => { + responseRunners.push(new ResponseRunner(runner)); + }); + return responseRunners; + } + @Post() @Authorized("ORGANIZATION:CREATE") @ResponseSchema(ResponseRunnerOrganization)