Added Create action for the statsclients

ref #56
This commit is contained in:
Nicolai Ort 2020-12-29 19:34:14 +01:00
parent ce55dce011
commit e2cc0c0b80
1 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,26 @@
import { 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 clients's description.
*/
@IsString()
@IsOptional()
description?: string;
/**
* Converts this to a StatsClient entity.
*/
public async toStatsClient(): Promise<StatsClient> {
let newClient: StatsClient = new StatsClient();
newClient.description = this.description;
newClient.key = crypto.randomBytes(20).toString('hex');
return newClient;
}
}