From 4c3d2643c111dece23a38a565cd4cb156e55a917 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 29 Dec 2020 19:37:55 +0100 Subject: [PATCH] Added enabled flag for the stats clients ref #56 --- src/models/actions/CreateStatsClient.ts | 11 ++++++++++- src/models/entities/StatsClient.ts | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/models/actions/CreateStatsClient.ts b/src/models/actions/CreateStatsClient.ts index 83fa199..436264c 100644 --- a/src/models/actions/CreateStatsClient.ts +++ b/src/models/actions/CreateStatsClient.ts @@ -6,12 +6,19 @@ import { StatsClient } from '../entities/StatsClient'; */ export class CreateStatsClient { /** - * The new clients's description. + * The new client's description. */ @IsString() @IsOptional() description?: string; + /** + * Is the new client enabled. + */ + @IsString() + @IsOptional() + enabled?: boolean; + /** * Converts this to a StatsClient entity. */ @@ -20,6 +27,8 @@ export class CreateStatsClient { 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; } diff --git a/src/models/entities/StatsClient.ts b/src/models/entities/StatsClient.ts index cbc9e9e..5b32249 100644 --- a/src/models/entities/StatsClient.ts +++ b/src/models/entities/StatsClient.ts @@ -1,4 +1,4 @@ -import { IsInt, IsOptional, IsString } from "class-validator"; +import { IsBoolean, IsInt, IsOptional, IsString } from "class-validator"; import { Column, Entity, PrimaryGeneratedColumn } from "typeorm"; /** * Defines the StatsClient entity. @@ -22,6 +22,14 @@ export class StatsClient { @IsString() description?: string; + /** + * Is the client enabled (for fraud and setup reasons)? + * Default: true + */ + @Column() + @IsBoolean() + enabled: boolean = true; + /** * The client's api key. * This is used to authorize a statsClient against the api.