Implemented scan station creation

ref #67
This commit is contained in:
Nicolai Ort 2021-01-07 18:39:38 +01:00
parent b9c0a32862
commit 2628f69651
2 changed files with 16 additions and 11 deletions

View File

@ -1,7 +1,9 @@
import { Authorized, Get, JsonController, OnUndefined, Param } from 'routing-controllers'; import { Authorized, Body, Get, JsonController, OnUndefined, Param, Post } 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 { ScanStationNotFoundError } from '../errors/ScanStationErrors';
import { TrackNotFoundError } from '../errors/TrackErrors';
import { CreateScanStation } from '../models/actions/CreateScanStation';
import { ScanStation } from '../models/entities/ScanStation'; import { ScanStation } from '../models/entities/ScanStation';
import { ResponseScanStation } from '../models/responses/ResponseScanStation'; import { ResponseScanStation } from '../models/responses/ResponseScanStation';
@ -42,15 +44,18 @@ export class ScanStationController {
return scan.toResponse(); return scan.toResponse();
} }
// @Post() @Post()
// @Authorized("SCAN:CREATE") @Authorized("STATION:CREATE")
// @ResponseSchema(ResponseScan) @ResponseSchema(ResponseScanStation)
// @OpenAPI({ description: 'Create a new runner. <br> Please remeber to provide the runner\'s group\'s id.' }) @ResponseSchema(TrackNotFoundError, { statusCode: 404 })
// async post(@Body({ validate: true }) createScan: CreateScan) { @OpenAPI({ description: 'Create a new runner. <br> Please remeber to provide the runner\'s group\'s id.' })
// let scan = await createScan.toScan(); async post(@Body({ validate: true }) createStation: CreateScanStation) {
// scan = await this.scanRepository.save(scan); let newStation = await createStation.toEntity();
// return (await this.scanRepository.findOne({ id: scan.id }, { relations: ['runner'] })).toResponse(); const station = await this.stationRepository.save(newStation);
// } let responseStation = (await this.stationRepository.findOne({ id: station.id }, { relations: ['track'] })).toResponse();
responseStation.key = newStation.cleartextkey;
return responseStation;
}
// @Put('/:id') // @Put('/:id')
// @Authorized("SCAN:UPDATE") // @Authorized("SCAN:UPDATE")

View File

@ -10,7 +10,7 @@ import { Track } from '../entities/Track';
/** /**
* This classed is used to create a new StatsClient entity from a json body (post request). * This classed is used to create a new StatsClient entity from a json body (post request).
*/ */
export class CreateStatsClient { export class CreateScanStation {
/** /**
* The new client's description. * The new client's description.
*/ */