@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user