Implmented getting all scan stations

ref #67
This commit is contained in:
Nicolai Ort 2021-01-07 18:05:54 +01:00
parent 3d2c93b5ac
commit 82644a2ff4
2 changed files with 18 additions and 17 deletions

View File

@ -1,7 +1,8 @@
import { JsonController } from 'routing-controllers';
import { OpenAPI } from 'routing-controllers-openapi';
import { Authorized, Get, JsonController } from 'routing-controllers';
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
import { getConnectionManager, Repository } from 'typeorm';
import { ScanStation } from '../models/entities/ScanStation';
import { ResponseScanStation } from '../models/responses/ResponseScanStation';
@JsonController('/stations')
@OpenAPI({ security: [{ "AuthToken": [] }, { "RefreshTokenCookie": [] }] })
@ -15,19 +16,18 @@ export class ScanStationController {
this.stationRepository = getConnectionManager().get().getRepository(ScanStation);
}
// @Get()
// @Authorized("SCAN:GET")
// @ResponseSchema(ResponseScan, { isArray: true })
// @ResponseSchema(ResponseTrackScan, { isArray: true })
// @OpenAPI({ description: 'Lists all scans (normal or track) from all runners. <br> This includes the runner\'s group and distance ran.' })
// async getAll() {
// let responseScans: ResponseScan[] = new Array<ResponseScan>();
// const scans = await this.scanRepository.find({ relations: ['runner'] });
// scans.forEach(scan => {
// responseScans.push(scan.toResponse());
// });
// return responseScans;
// }
@Get()
@Authorized("STATION:GET")
@ResponseSchema(ResponseScanStation, { isArray: true })
@OpenAPI({ description: 'Lists all scans (normal or track) from all runners. <br> This includes the runner\'s group and distance ran.' })
async getAll() {
let responseStations: ResponseScanStation[] = new Array<ResponseScanStation>();
const stations = await this.stationRepository.find({ relations: ['track'] });
stations.forEach(station => {
responseStations.push(station.toResponse());
});
return responseStations;
}
// @Get('/:id')
// @Authorized("SCAN:GET")

View File

@ -5,6 +5,7 @@ import {
IsString
} from "class-validator";
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { ResponseScanStation } from '../responses/ResponseScanStation';
import { Track } from "./Track";
import { TrackScan } from "./TrackScan";
@ -72,7 +73,7 @@ export class ScanStation {
/**
* Turns this entity into it's response class.
*/
public toResponse() {
return new Error("NotImplemented");
public toResponse(): ResponseScanStation {
return new ResponseScanStation(this);
}
}