From a2f588b635e29cf438b77cbf2aded03a3c25fb59 Mon Sep 17 00:00:00 2001 From: Roman Vaivod Date: Fri, 20 Mar 2020 12:52:26 +0100 Subject: [PATCH] gh-112: Merge isValidGameData and isGameData --- backend/repositories/GameRepository.ts | 12 +++++------- backend/types/Game.ts | 6 ------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/backend/repositories/GameRepository.ts b/backend/repositories/GameRepository.ts index 0fbd2ce1..cda9cf01 100644 --- a/backend/repositories/GameRepository.ts +++ b/backend/repositories/GameRepository.ts @@ -1,10 +1,11 @@ -import { GameData, isGameData } from '../types/Game' +import { GameData } from '../types/Game' import { InputError } from '../errors/InputError' import * as storage from '../storage/Storage' -const isValidGameData = (gameData: GameData): boolean => { - return gameData.name !== '' && - gameData.description !== '' && +const isValidGameData = (data: unknown): data is GameData => { + const gameData = data as GameData + return gameData.name && + gameData.description && gameData.name.trim() == gameData.name && gameData.name.toLowerCase() == gameData.name && !gameData.name.includes(' ') && @@ -12,9 +13,6 @@ const isValidGameData = (gameData: GameData): boolean => { } export const addGame = async (data: unknown): Promise => { - if (!isGameData(data)) { - throw new InputError('Data is not valid!') - } if (!isValidGameData(data)) { throw new InputError('Game data is not valid!') } diff --git a/backend/types/Game.ts b/backend/types/Game.ts index 9b2027bf..b30b3ff8 100644 --- a/backend/types/Game.ts +++ b/backend/types/Game.ts @@ -3,12 +3,6 @@ export interface GameData { readonly description: string; } -export const isGameData = (data: unknown): data is GameData => { - const test = data as GameData - return test.name !== undefined && test.name !== null && - test.description !== null && test.description !== null -} - export interface Game extends GameData { readonly id: number; }