From 4d22905ef95ae31a49916d249672557a3e92aa05 Mon Sep 17 00:00:00 2001 From: legonzaur Date: Sun, 29 Dec 2024 12:04:19 +0100 Subject: [PATCH] working on words --- dto/conceptinturnresponse.dto.ts | 20 ++++++++++++++++++ dto/conceptresponse.dto.ts | 13 ++++++++++++ dto/gameresponse.dto.ts | 36 ++++++++++++++++++++++++++++++++ dto/playerresponse.dto.ts | 16 ++++++++++++++ dto/userresponse.dto.ts | 16 ++++++++++++++ dto/wordresponse.dto.ts | 18 ++++++++++++++++ lobby.events.ts | 21 +++++++++++++++++++ word.events.ts | 26 +++++++++++++++++++++++ 8 files changed, 166 insertions(+) create mode 100644 dto/conceptinturnresponse.dto.ts create mode 100644 dto/conceptresponse.dto.ts create mode 100644 dto/gameresponse.dto.ts create mode 100644 dto/playerresponse.dto.ts create mode 100644 dto/userresponse.dto.ts create mode 100644 dto/wordresponse.dto.ts create mode 100644 lobby.events.ts create mode 100644 word.events.ts diff --git a/dto/conceptinturnresponse.dto.ts b/dto/conceptinturnresponse.dto.ts new file mode 100644 index 0000000..0b82ac6 --- /dev/null +++ b/dto/conceptinturnresponse.dto.ts @@ -0,0 +1,20 @@ +import { Expose, Type } from 'class-transformer'; +import { ConceptResponseDTO } from './conceptresponse.dto'; + +export class ConceptInTurnResponseDTO { + constructor(partial: Partial) { + Object.assign(this, partial); + } + @Type(() => ConceptResponseDTO) + @Expose() + concept: ConceptResponseDTO; + + @Expose() + order: number; + + @Expose() + subconcept: number; + + @Expose() + markers: number; +} diff --git a/dto/conceptresponse.dto.ts b/dto/conceptresponse.dto.ts new file mode 100644 index 0000000..ed508fb --- /dev/null +++ b/dto/conceptresponse.dto.ts @@ -0,0 +1,13 @@ +import { Expose } from 'class-transformer'; + +export class ConceptResponseDTO { + constructor(partial: Partial) { + Object.assign(this, partial); + } + + @Expose() + id: number; + + @Expose() + value: string; +} diff --git a/dto/gameresponse.dto.ts b/dto/gameresponse.dto.ts new file mode 100644 index 0000000..b3f755c --- /dev/null +++ b/dto/gameresponse.dto.ts @@ -0,0 +1,36 @@ +import { Expose, Type } from 'class-transformer'; +import { UserResponseDTO } from './userresponse.dto'; +import { PlayerResponseDTO } from './playerresponse.dto'; +import { ConceptInTurnResponseDTO } from './conceptinturnresponse.dto'; + +export class GameResponseDTO { + constructor(partial: Partial) { + Object.assign(this, partial); + this.owner = partial.owner; + this.players = partial.players; + this.currentPlayer = partial.currentPlayer; + this.currentConcepts = partial.currentConcepts; + } + + @Expose() + id: number; + + @Type(() => UserResponseDTO) + @Expose() + owner: UserResponseDTO; + + @Type(() => PlayerResponseDTO) + @Expose() + players: PlayerResponseDTO[]; + + @Type(() => PlayerResponseDTO) + @Expose() + currentPlayer: PlayerResponseDTO; + + @Expose() + started: boolean; + + @Type(() => ConceptInTurnResponseDTO) + @Expose() + currentConcepts: ConceptInTurnResponseDTO[]; +} diff --git a/dto/playerresponse.dto.ts b/dto/playerresponse.dto.ts new file mode 100644 index 0000000..4ac8a53 --- /dev/null +++ b/dto/playerresponse.dto.ts @@ -0,0 +1,16 @@ +import { Expose, Type } from 'class-transformer'; +import { UserResponseDTO } from './userresponse.dto'; + +export class PlayerResponseDTO { + constructor(partial: Partial) { + Object.assign(this, partial); + this.user = partial.user; + } + + @Type(() => UserResponseDTO) + @Expose() + user: UserResponseDTO; + + @Expose() + score: number; +} diff --git a/dto/userresponse.dto.ts b/dto/userresponse.dto.ts new file mode 100644 index 0000000..5825d8b --- /dev/null +++ b/dto/userresponse.dto.ts @@ -0,0 +1,16 @@ +import { Expose } from 'class-transformer'; + +export class UserResponseDTO { + constructor(partial: Partial) { + Object.assign(this, partial); + this.id = partial.id; + } + @Expose() + id: string; + + @Expose() + username: string; + + @Expose() + avatar: string; +} diff --git a/dto/wordresponse.dto.ts b/dto/wordresponse.dto.ts new file mode 100644 index 0000000..2d84c37 --- /dev/null +++ b/dto/wordresponse.dto.ts @@ -0,0 +1,18 @@ +import { Expose } from 'class-transformer'; + +export class WordResponseDTO { + constructor(partial: Partial) { + Object.assign(this, partial); + } + @Expose() + id: number; + + @Expose() + value: string; + + @Expose() + ownerId: string; + + @Expose() + enabled: boolean; +} diff --git a/lobby.events.ts b/lobby.events.ts new file mode 100644 index 0000000..3a98aa2 --- /dev/null +++ b/lobby.events.ts @@ -0,0 +1,21 @@ +import { GameResponseDTO } from './dto/gameresponse.dto'; +import { PlayerResponseDTO } from './dto/playerresponse.dto'; + +export class GameCreateEvent extends GameResponseDTO { + type: 'create'; +} + +export class GameDeleteEvent { + type: 'delete'; + constructor(public id?: number) {} +} +export class GameJoinEvent { + type: 'joingame'; + gameId: number; + constructor( + public player: PlayerResponseDTO, + game?: Partial, + ) { + this.gameId = game.id; + } +} diff --git a/word.events.ts b/word.events.ts new file mode 100644 index 0000000..7a901c1 --- /dev/null +++ b/word.events.ts @@ -0,0 +1,26 @@ +import { WordResponseDTO } from './dto/wordresponse.dto'; + +export class WordCreateEvent { + type: 'create'; + constructor(public word: WordResponseDTO) {} +} + +export class WordEditEvent { + type: 'edit'; + constructor(public word: WordResponseDTO) {} +} + +export class WordDeleteEvent { + type: 'delete'; + constructor(public id: number) {} +} + +export class WordEnableEvent { + type: 'enable'; + constructor(public id: number) {} +} + +export class WordDisableEvent { + type: 'disable'; + constructor(public id: number) {} +}