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,5 +1,5 @@
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 { getConnection } from 'typeorm';
import * as uuid from 'uuid';
@@ -26,6 +26,13 @@ export class CreateScanStation {
@IsPositive()
track: number;
/**
* Is this station enabled?
*/
@IsBoolean()
@IsOptional()
enabled?: boolean = true;
/**
* Converts this to a ScanStation entity.
*/
@@ -33,6 +40,7 @@ export class CreateScanStation {
let newStation: ScanStation = new ScanStation();
newStation.description = this.description;
newStation.enabled = this.enabled;
newStation.track = await this.getTrack();
let newUUID = uuid.v4().toUpperCase();

View 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;
}
}