backend/src/models/actions/CreateStatsClient.ts
2020-12-29 20:05:35 +01:00

35 lines
961 B
TypeScript

import { IsBoolean, IsOptional, IsString } from 'class-validator';
import crypto from "crypto";
import { StatsClient } from '../entities/StatsClient';
/**
* This classed is used to create a new StatsClient entity from a json body (post request).
*/
export class CreateStatsClient {
/**
* The new client's description.
*/
@IsString()
@IsOptional()
description?: string;
/**
* Is the new client enabled.
*/
@IsBoolean()
@IsOptional()
enabled?: boolean;
/**
* Converts this to a StatsClient entity.
*/
public toStatsClient(): StatsClient {
let newClient: StatsClient = new StatsClient();
newClient.description = this.description;
newClient.key = crypto.randomBytes(20).toString('hex');
if (this.enabled === undefined || this.enabled === null) { newClient.enabled = true; }
else { newClient.enabled = this.enabled }
return newClient;
}
}