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 { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||||
import { getConnectionManager, Repository } from 'typeorm';
|
import { getConnectionManager, Repository } from 'typeorm';
|
||||||
|
import { ScanStationNotFoundError } from '../errors/ScanStationErrors';
|
||||||
import { ScanStation } from '../models/entities/ScanStation';
|
import { ScanStation } from '../models/entities/ScanStation';
|
||||||
import { ResponseScanStation } from '../models/responses/ResponseScanStation';
|
import { ResponseScanStation } from '../models/responses/ResponseScanStation';
|
||||||
|
|
||||||
@ -29,18 +30,17 @@ export class ScanStationController {
|
|||||||
return responseStations;
|
return responseStations;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Get('/:id')
|
@Get('/:id')
|
||||||
// @Authorized("SCAN:GET")
|
@Authorized("STATION:GET")
|
||||||
// @ResponseSchema(ResponseScan)
|
@ResponseSchema(ResponseScanStation)
|
||||||
// @ResponseSchema(ResponseTrackScan)
|
@ResponseSchema(ScanStationNotFoundError, { statusCode: 404 })
|
||||||
// @ResponseSchema(ScanNotFoundError, { statusCode: 404 })
|
@OnUndefined(ScanStationNotFoundError)
|
||||||
// @OnUndefined(ScanNotFoundError)
|
@OpenAPI({ description: 'Lists all information about the runner whose id got provided.' })
|
||||||
// @OpenAPI({ description: 'Lists all information about the runner whose id got provided.' })
|
async getOne(@Param('id') id: number) {
|
||||||
// async getOne(@Param('id') id: number) {
|
let scan = await this.stationRepository.findOne({ id: id }, { relations: ['track'] })
|
||||||
// let scan = await this.scanRepository.findOne({ id: id }, { relations: ['runner'] })
|
if (!scan) { throw new ScanStationNotFoundError(); }
|
||||||
// if (!scan) { throw new ScanNotFoundError(); }
|
return scan.toResponse();
|
||||||
// return scan.toResponse();
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// @Post()
|
// @Post()
|
||||||
// @Authorized("SCAN:CREATE")
|
// @Authorized("SCAN:CREATE")
|
||||||
|
25
src/errors/ScanStationErrors.ts
Normal file
25
src/errors/ScanStationErrors.ts
Normal file
@ -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…
x
Reference in New Issue
Block a user