diff --git a/src/controllers/RunnerCardController.ts b/src/controllers/RunnerCardController.ts new file mode 100644 index 0000000..d01ab60 --- /dev/null +++ b/src/controllers/RunnerCardController.ts @@ -0,0 +1,99 @@ +import { JsonController } from 'routing-controllers'; +import { OpenAPI } from 'routing-controllers-openapi'; +import { getConnectionManager, Repository } from 'typeorm'; +import { RunnerCard } from '../models/entities/RunnerCard'; + +@JsonController('/cards') +@OpenAPI({ security: [{ "AuthToken": [] }, { "RefreshTokenCookie": [] }] }) +export class RunnerCardController { + private cardRepository: Repository; + + /** + * Gets the repository of this controller's model/entity. + */ + constructor() { + this.cardRepository = getConnectionManager().get().getRepository(RunnerCard); + } + + // @Get() + // @Authorized("CARD:GET") + // @ResponseSchema(ResponseTrack, { isArray: true }) + // @OpenAPI({ description: 'Lists all tracks.' }) + // async getAll() { + // let responseTracks: ResponseTrack[] = new Array(); + // const tracks = await this.trackRepository.find(); + // tracks.forEach(track => { + // responseTracks.push(new ResponseTrack(track)); + // }); + // return responseTracks; + // } + + // @Get('/:id') + // @Authorized("CARD:GET") + // @ResponseSchema(ResponseTrack) + // @ResponseSchema(TrackNotFoundError, { statusCode: 404 }) + // @OnUndefined(TrackNotFoundError) + // @OpenAPI({ description: "Lists all information about the track whose id got provided." }) + // async getOne(@Param('id') id: number) { + // let track = await this.trackRepository.findOne({ id: id }); + // if (!track) { throw new TrackNotFoundError(); } + // return new ResponseTrack(track); + // } + + // @Post() + // @Authorized("CARD:CREATE") + // @ResponseSchema(ResponseTrack) + // @ResponseSchema(TrackLapTimeCantBeNegativeError, { statusCode: 406 }) + // @OpenAPI({ description: "Create a new track.
Please remember that the track\'s distance must be greater than 0." }) + // async post( + // @Body({ validate: true }) + // track: CreateTrack + // ) { + // return new ResponseTrack(await this.trackRepository.save(track.toTrack())); + // } + + // @Put('/:id') + // @Authorized("CARD:UPDATE") + // @ResponseSchema(ResponseTrack) + // @ResponseSchema(TrackNotFoundError, { statusCode: 404 }) + // @ResponseSchema(TrackIdsNotMatchingError, { statusCode: 406 }) + // @ResponseSchema(TrackLapTimeCantBeNegativeError, { statusCode: 406 }) + // @OpenAPI({ description: "Update the track whose id you provided.
Please remember that ids can't be changed." }) + // async put(@Param('id') id: number, @Body({ validate: true }) updateTrack: UpdateTrack) { + // let oldTrack = await this.trackRepository.findOne({ id: id }); + + // if (!oldTrack) { + // throw new TrackNotFoundError(); + // } + + // if (oldTrack.id != updateTrack.id) { + // throw new TrackIdsNotMatchingError(); + // } + // await this.trackRepository.save(await updateTrack.updateTrack(oldTrack)); + + // return new ResponseTrack(await this.trackRepository.findOne({ id: id })); + // } + + // @Delete('/:id') + // @Authorized("CARD:DELETE") + // @ResponseSchema(ResponseTrack) + // @ResponseSchema(ResponseEmpty, { statusCode: 204 }) + // @OnUndefined(204) + // @OpenAPI({ description: "Delete the track whose id you provided.
If no track with this id exists it will just return 204(no content)." }) + // async remove(@Param("id") id: number, @QueryParam("force") force: boolean) { + // let track = await this.trackRepository.findOne({ id: id }); + // if (!track) { return null; } + + // const trackStations = (await this.trackRepository.findOne({ id: id }, { relations: ["stations"] })).stations; + // if (trackStations.length != 0 && !force) { + // throw new TrackHasScanStationsError(); + // } + // const scanController = new ScanStationController; + // for (let station of trackStations) { + // scanController.remove(station.id, force); + // } + + // await this.trackRepository.delete(track); + // return new ResponseTrack(track); + // } +} \ No newline at end of file