Added a "onlyValid" query param

ref #113
This commit is contained in:
Nicolai Ort 2021-01-21 15:57:56 +01:00
parent a82fc0fb9e
commit b5f3dec93b
1 changed files with 11 additions and 4 deletions

View File

@ -56,14 +56,21 @@ export class RunnerController {
@ResponseSchema(ResponseScan, { isArray: true })
@ResponseSchema(ResponseTrackScan, { isArray: true })
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
@OpenAPI({ description: 'Lists all scans of the runner whose id got provided.' })
async getScans(@Param('id') id: number) {
@OpenAPI({ description: 'Lists all scans of the runner whose id got provided. <br> If you only want the valid scans just add the ?onlyValid=true query param.' })
async getScans(@Param('id') id: number, onlyValid?: boolean) {
let responseScans: ResponseScan[] = new Array<ResponseScan>();
let runner = await this.runnerRepository.findOne({ id: id }, { relations: ['scans', 'scans.track', 'scans.station', 'scans.runner'] })
if (!runner) { throw new RunnerNotFoundError(); }
for (let scan of runner.scans) {
responseScans.push(scan.toResponse());
if (!onlyValid) {
for (let scan of runner.scans) {
responseScans.push(scan.toResponse());
}
}
else {
for (let scan of runner.validScans) {
responseScans.push(scan.toResponse());
}
}
return responseScans;