From e2cc0c0b800a66a8696525dd7a8f7e4b3d456c7c Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 29 Dec 2020 19:34:14 +0100 Subject: [PATCH] Added Create action for the statsclients ref #56 --- src/models/actions/CreateStatsClient.ts | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/models/actions/CreateStatsClient.ts diff --git a/src/models/actions/CreateStatsClient.ts b/src/models/actions/CreateStatsClient.ts new file mode 100644 index 0000000..83fa199 --- /dev/null +++ b/src/models/actions/CreateStatsClient.ts @@ -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 { + let newClient: StatsClient = new StatsClient(); + + newClient.description = this.description; + newClient.key = crypto.randomBytes(20).toString('hex'); + + return newClient; + } +} \ No newline at end of file