Added the enabled flag for scanstations

ref #67
This commit is contained in:
2021-01-07 19:37:15 +01:00
parent 09b37f0ff2
commit 4f01baaa23
6 changed files with 86 additions and 22 deletions

View File

@@ -1,9 +1,10 @@
import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post, QueryParam } from 'routing-controllers';
import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers';
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
import { getConnectionManager, Repository } from 'typeorm';
import { ScanStationHasScansError, ScanStationNotFoundError } from '../errors/ScanStationErrors';
import { ScanStationHasScansError, ScanStationIdsNotMatchingError, ScanStationNotFoundError } from '../errors/ScanStationErrors';
import { TrackNotFoundError } from '../errors/TrackErrors';
import { CreateScanStation } from '../models/actions/CreateScanStation';
import { UpdateScanStation } from '../models/actions/UpdateScanStation';
import { ScanStation } from '../models/entities/ScanStation';
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
import { ResponseScanStation } from '../models/responses/ResponseScanStation';
@@ -59,27 +60,26 @@ export class ScanStationController {
return responseStation;
}
// @Put('/:id')
// @Authorized("SCAN:UPDATE")
// @ResponseSchema(ResponseScan)
// @ResponseSchema(ScanNotFoundError, { statusCode: 404 })
// @ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
// @ResponseSchema(ScanIdsNotMatchingError, { statusCode: 406 })
// @OpenAPI({ description: "Update the runner whose id you provided. <br> Please remember that ids can't be changed." })
// async put(@Param('id') id: number, @Body({ validate: true }) scan: UpdateScan) {
// let oldScan = await this.scanRepository.findOne({ id: id });
@Put('/:id')
@Authorized("STATION:UPDATE")
@ResponseSchema(ResponseScanStation)
@ResponseSchema(ScanStationNotFoundError, { statusCode: 404 })
@ResponseSchema(ScanStationIdsNotMatchingError, { statusCode: 406 })
@OpenAPI({ description: "Update the station whose id you provided. <br> Please remember that only the description and enabled state can be changed." })
async put(@Param('id') id: number, @Body({ validate: true }) station: UpdateScanStation) {
let oldStation = await this.stationRepository.findOne({ id: id });
// if (!oldScan) {
// throw new ScanNotFoundError();
// }
if (!oldStation) {
throw new ScanStationNotFoundError();
}
// if (oldScan.id != scan.id) {
// throw new ScanIdsNotMatchingError();
// }
if (oldStation.id != station.id) {
throw new ScanStationNotFoundError();
}
// await this.scanRepository.save(await scan.updateScan(oldScan));
// return (await this.scanRepository.findOne({ id: id }, { relations: ['runner'] })).toResponse();
// }
await this.stationRepository.save(await station.updateStation(oldStation));
return (await this.stationRepository.findOne({ id: id }, { relations: ['track'] })).toResponse();
}
@Delete('/:id')
@Authorized("STATION:DELETE")