Skip to content

Commit

Permalink
gh-112: Merge isValidGameData and isGameData
Browse files Browse the repository at this point in the history
  • Loading branch information
littlewhywhat committed Mar 20, 2020
1 parent f657e38 commit a2f588b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
12 changes: 5 additions & 7 deletions backend/repositories/GameRepository.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
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(' ') &&
gameData.description.trim() == gameData.description
}

export const addGame = async (data: unknown): Promise<void> => {
if (!isGameData(data)) {
throw new InputError('Data is not valid!')
}
if (!isValidGameData(data)) {
throw new InputError('Game data is not valid!')
}
Expand Down
6 changes: 0 additions & 6 deletions backend/types/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit a2f588b

Please sign in to comment.