backend/src/models/responses/ResponseScanStation.ts
Nicolai Ort ff7406e71a
All checks were successful
continuous-integration/drone/pr Build is passing
Cleaned up realations regarding response classes
ref #132
2021-01-30 16:19:42 +01:00

79 lines
1.6 KiB
TypeScript

import {
IsBoolean,
IsInt,
IsNotEmpty,
IsObject,
IsOptional,
IsString
} from "class-validator";
import { ScanStation } from '../entities/ScanStation';
import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse';
import { ResponseTrack } from './ResponseTrack';
/**
* Defines the statsClient response.
*/
export class ResponseScanStation implements IResponse {
/**
* The responseType.
* This contains the type of class/entity this response contains.
*/
responseType: ResponseObjectType = ResponseObjectType.SCANSTATION;
/**
* The client's id.
*/
@IsInt()
id: number;
/**
* The client's description.
*/
@IsString()
@IsOptional()
description?: string;
/**
* The client's api key.
* Only visible on creation or regeneration.
*/
@IsString()
@IsOptional()
key: string;
/**
* The client's api key prefix.
*/
@IsString()
@IsNotEmpty()
prefix: string;
@IsObject()
@IsNotEmpty()
track: ResponseTrack;
/**
* Is this station enabled?
*/
@IsBoolean()
enabled?: boolean = true;
/**
* Creates a ResponseStatsClient object from a statsClient.
* @param client The statsClient the response shall be build for.
*/
public constructor(station: ScanStation) {
this.id = station.id;
this.description = station.description;
this.prefix = station.prefix;
this.key = "Only visible on creation.";
if (station.track) { this.track = station.track.toResponse(); }
this.enabled = station.enabled;
}
}