parent
82644a2ff4
commit
b9c0a32862
|
@ -1,6 +1,7 @@
|
|||
import { Authorized, Get, JsonController } from 'routing-controllers';
|
||||
import { Authorized, Get, JsonController, OnUndefined, Param } from 'routing-controllers';
|
||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { getConnectionManager, Repository } from 'typeorm';
|
||||
import { ScanStationNotFoundError } from '../errors/ScanStationErrors';
|
||||
import { ScanStation } from '../models/entities/ScanStation';
|
||||
import { ResponseScanStation } from '../models/responses/ResponseScanStation';
|
||||
|
||||
|
@ -29,18 +30,17 @@ export class ScanStationController {
|
|||
return responseStations;
|
||||
}
|
||||
|
||||
// @Get('/:id')
|
||||
// @Authorized("SCAN:GET")
|
||||
// @ResponseSchema(ResponseScan)
|
||||
// @ResponseSchema(ResponseTrackScan)
|
||||
// @ResponseSchema(ScanNotFoundError, { statusCode: 404 })
|
||||
// @OnUndefined(ScanNotFoundError)
|
||||
// @OpenAPI({ description: 'Lists all information about the runner whose id got provided.' })
|
||||
// async getOne(@Param('id') id: number) {
|
||||
// let scan = await this.scanRepository.findOne({ id: id }, { relations: ['runner'] })
|
||||
// if (!scan) { throw new ScanNotFoundError(); }
|
||||
// return scan.toResponse();
|
||||
// }
|
||||
@Get('/:id')
|
||||
@Authorized("STATION:GET")
|
||||
@ResponseSchema(ResponseScanStation)
|
||||
@ResponseSchema(ScanStationNotFoundError, { statusCode: 404 })
|
||||
@OnUndefined(ScanStationNotFoundError)
|
||||
@OpenAPI({ description: 'Lists all information about the runner whose id got provided.' })
|
||||
async getOne(@Param('id') id: number) {
|
||||
let scan = await this.stationRepository.findOne({ id: id }, { relations: ['track'] })
|
||||
if (!scan) { throw new ScanStationNotFoundError(); }
|
||||
return scan.toResponse();
|
||||
}
|
||||
|
||||
// @Post()
|
||||
// @Authorized("SCAN:CREATE")
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
import { IsString } from 'class-validator';
|
||||
import { NotAcceptableError, NotFoundError } from 'routing-controllers';
|
||||
|
||||
/**
|
||||
* Error to throw, when a non-existant scan station get's loaded.
|
||||
*/
|
||||
export class ScanStationNotFoundError extends NotFoundError {
|
||||
@IsString()
|
||||
name = "ScanStationNotFoundError"
|
||||
|
||||
@IsString()
|
||||
message = "The scan station you provided couldn't be located in the system. \n Please check your request."
|
||||
}
|
||||
|
||||
/**
|
||||
* Error to throw when two scan stations' ids don't match.
|
||||
* Usually occurs when a user tries to change a scan station's id.
|
||||
*/
|
||||
export class ScanStationIdsNotMatchingError extends NotAcceptableError {
|
||||
@IsString()
|
||||
name = "ScanStationIdsNotMatchingError"
|
||||
|
||||
@IsString()
|
||||
message = "The ids don't match! \n And if you wanted to change a scan station's id: This isn't allowed!"
|
||||
}
|
Loading…
Reference in New Issue