parent
09b37f0ff2
commit
4f01baaa23
@ -4,6 +4,7 @@ import { getConnectionManager, Repository } from 'typeorm';
|
|||||||
import { RunnerNotFoundError } from '../errors/RunnerErrors';
|
import { RunnerNotFoundError } from '../errors/RunnerErrors';
|
||||||
import { ScanIdsNotMatchingError, ScanNotFoundError } from '../errors/ScanErrors';
|
import { ScanIdsNotMatchingError, ScanNotFoundError } from '../errors/ScanErrors';
|
||||||
import { CreateScan } from '../models/actions/CreateScan';
|
import { CreateScan } from '../models/actions/CreateScan';
|
||||||
|
import { CreateTrackScan } from '../models/actions/CreateTrackScan';
|
||||||
import { UpdateScan } from '../models/actions/UpdateScan';
|
import { UpdateScan } from '../models/actions/UpdateScan';
|
||||||
import { Scan } from '../models/entities/Scan';
|
import { Scan } from '../models/entities/Scan';
|
||||||
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
|
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
|
||||||
@ -53,7 +54,7 @@ export class ScanController {
|
|||||||
@Authorized("SCAN:CREATE")
|
@Authorized("SCAN:CREATE")
|
||||||
@ResponseSchema(ResponseScan)
|
@ResponseSchema(ResponseScan)
|
||||||
@OpenAPI({ description: 'Create a new runner. <br> Please remeber to provide the runner\'s group\'s id.' })
|
@OpenAPI({ description: 'Create a new runner. <br> Please remeber to provide the runner\'s group\'s id.' })
|
||||||
async post(@Body({ validate: true }) createScan: CreateScan) {
|
async post(@Body({ validate: true }) createScan: CreateScan | CreateTrackScan) {
|
||||||
let scan = await createScan.toScan();
|
let scan = await createScan.toScan();
|
||||||
scan = await this.scanRepository.save(scan);
|
scan = await this.scanRepository.save(scan);
|
||||||
return (await this.scanRepository.findOne({ id: scan.id }, { relations: ['runner'] })).toResponse();
|
return (await this.scanRepository.findOne({ id: scan.id }, { relations: ['runner'] })).toResponse();
|
||||||
|
@ -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 { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||||
import { getConnectionManager, Repository } from 'typeorm';
|
import { getConnectionManager, Repository } from 'typeorm';
|
||||||
import { ScanStationHasScansError, ScanStationNotFoundError } from '../errors/ScanStationErrors';
|
import { ScanStationHasScansError, ScanStationIdsNotMatchingError, ScanStationNotFoundError } from '../errors/ScanStationErrors';
|
||||||
import { TrackNotFoundError } from '../errors/TrackErrors';
|
import { TrackNotFoundError } from '../errors/TrackErrors';
|
||||||
import { CreateScanStation } from '../models/actions/CreateScanStation';
|
import { CreateScanStation } from '../models/actions/CreateScanStation';
|
||||||
|
import { UpdateScanStation } from '../models/actions/UpdateScanStation';
|
||||||
import { ScanStation } from '../models/entities/ScanStation';
|
import { ScanStation } from '../models/entities/ScanStation';
|
||||||
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
|
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
|
||||||
import { ResponseScanStation } from '../models/responses/ResponseScanStation';
|
import { ResponseScanStation } from '../models/responses/ResponseScanStation';
|
||||||
@ -59,27 +60,26 @@ export class ScanStationController {
|
|||||||
return responseStation;
|
return responseStation;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Put('/:id')
|
@Put('/:id')
|
||||||
// @Authorized("SCAN:UPDATE")
|
@Authorized("STATION:UPDATE")
|
||||||
// @ResponseSchema(ResponseScan)
|
@ResponseSchema(ResponseScanStation)
|
||||||
// @ResponseSchema(ScanNotFoundError, { statusCode: 404 })
|
@ResponseSchema(ScanStationNotFoundError, { statusCode: 404 })
|
||||||
// @ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
@ResponseSchema(ScanStationIdsNotMatchingError, { statusCode: 406 })
|
||||||
// @ResponseSchema(ScanIdsNotMatchingError, { statusCode: 406 })
|
@OpenAPI({ description: "Update the station whose id you provided. <br> Please remember that only the description and enabled state can be changed." })
|
||||||
// @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 }) station: UpdateScanStation) {
|
||||||
// async put(@Param('id') id: number, @Body({ validate: true }) scan: UpdateScan) {
|
let oldStation = await this.stationRepository.findOne({ id: id });
|
||||||
// let oldScan = await this.scanRepository.findOne({ id: id });
|
|
||||||
|
|
||||||
// if (!oldScan) {
|
if (!oldStation) {
|
||||||
// throw new ScanNotFoundError();
|
throw new ScanStationNotFoundError();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (oldScan.id != scan.id) {
|
if (oldStation.id != station.id) {
|
||||||
// throw new ScanIdsNotMatchingError();
|
throw new ScanStationNotFoundError();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// await this.scanRepository.save(await scan.updateScan(oldScan));
|
await this.stationRepository.save(await station.updateStation(oldStation));
|
||||||
// return (await this.scanRepository.findOne({ id: id }, { relations: ['runner'] })).toResponse();
|
return (await this.stationRepository.findOne({ id: id }, { relations: ['track'] })).toResponse();
|
||||||
// }
|
}
|
||||||
|
|
||||||
@Delete('/:id')
|
@Delete('/:id')
|
||||||
@Authorized("STATION:DELETE")
|
@Authorized("STATION:DELETE")
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as argon2 from "argon2";
|
import * as argon2 from "argon2";
|
||||||
import { IsInt, IsOptional, IsPositive, IsString } from 'class-validator';
|
import { IsBoolean, IsInt, IsOptional, IsPositive, IsString } from 'class-validator';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import { getConnection } from 'typeorm';
|
import { getConnection } from 'typeorm';
|
||||||
import * as uuid from 'uuid';
|
import * as uuid from 'uuid';
|
||||||
@ -26,6 +26,13 @@ export class CreateScanStation {
|
|||||||
@IsPositive()
|
@IsPositive()
|
||||||
track: number;
|
track: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this station enabled?
|
||||||
|
*/
|
||||||
|
@IsBoolean()
|
||||||
|
@IsOptional()
|
||||||
|
enabled?: boolean = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts this to a ScanStation entity.
|
* Converts this to a ScanStation entity.
|
||||||
*/
|
*/
|
||||||
@ -33,6 +40,7 @@ export class CreateScanStation {
|
|||||||
let newStation: ScanStation = new ScanStation();
|
let newStation: ScanStation = new ScanStation();
|
||||||
|
|
||||||
newStation.description = this.description;
|
newStation.description = this.description;
|
||||||
|
newStation.enabled = this.enabled;
|
||||||
newStation.track = await this.getTrack();
|
newStation.track = await this.getTrack();
|
||||||
|
|
||||||
let newUUID = uuid.v4().toUpperCase();
|
let newUUID = uuid.v4().toUpperCase();
|
||||||
|
39
src/models/actions/UpdateScanStation.ts
Normal file
39
src/models/actions/UpdateScanStation.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { IsBoolean, IsInt, IsOptional, IsString } from 'class-validator';
|
||||||
|
import { ScanStation } from '../entities/ScanStation';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This classed is used to create a new StatsClient entity from a json body (post request).
|
||||||
|
*/
|
||||||
|
export class UpdateScanStation {
|
||||||
|
/**
|
||||||
|
* The updated station's id.
|
||||||
|
* This shouldn't have changed but it is here in case anyone ever wants to enable id changes (whyever they would want to).
|
||||||
|
*/
|
||||||
|
@IsInt()
|
||||||
|
id: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The updated station's description.
|
||||||
|
*/
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
description?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this station enabled?
|
||||||
|
*/
|
||||||
|
@IsBoolean()
|
||||||
|
@IsOptional()
|
||||||
|
enabled?: boolean = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts this to a ScanStation entity.
|
||||||
|
* TODO:
|
||||||
|
*/
|
||||||
|
public async updateStation(station: ScanStation): Promise<ScanStation> {
|
||||||
|
station.description = this.description;
|
||||||
|
station.enabled = this.enabled;
|
||||||
|
|
||||||
|
return station;
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
IsBoolean,
|
||||||
IsInt,
|
IsInt,
|
||||||
IsNotEmpty,
|
IsNotEmpty,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
@ -70,6 +71,13 @@ export class ScanStation {
|
|||||||
@OneToMany(() => TrackScan, scan => scan.track, { nullable: true })
|
@OneToMany(() => TrackScan, scan => scan.track, { nullable: true })
|
||||||
scans: TrackScan[];
|
scans: TrackScan[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this station enabled?
|
||||||
|
*/
|
||||||
|
@Column({ nullable: true })
|
||||||
|
@IsBoolean()
|
||||||
|
enabled?: boolean = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turns this entity into it's response class.
|
* Turns this entity into it's response class.
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
|
|
||||||
|
IsBoolean,
|
||||||
IsInt,
|
IsInt,
|
||||||
|
|
||||||
IsNotEmpty,
|
IsNotEmpty,
|
||||||
@ -48,6 +49,12 @@ export class ResponseScanStation {
|
|||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
track: ResponseTrack;
|
track: ResponseTrack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this station enabled?
|
||||||
|
*/
|
||||||
|
@IsBoolean()
|
||||||
|
enabled?: boolean = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a ResponseStatsClient object from a statsClient.
|
* Creates a ResponseStatsClient object from a statsClient.
|
||||||
* @param client The statsClient the response shall be build for.
|
* @param client The statsClient the response shall be build for.
|
||||||
@ -58,5 +65,6 @@ export class ResponseScanStation {
|
|||||||
this.prefix = station.prefix;
|
this.prefix = station.prefix;
|
||||||
this.key = "Only visible on creation.";
|
this.key = "Only visible on creation.";
|
||||||
this.track = station.track;
|
this.track = station.track;
|
||||||
|
this.enabled = station.enabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user