From e9d5d8d909e4ba952f6bed53ead08642466431d1 Mon Sep 17 00:00:00 2001 From: legonzaur Date: Sun, 29 Dec 2024 23:47:41 +0100 Subject: [PATCH] chore : remove class-transformer --- dto/conceptinturnresponse.dto.ts | 8 ++------ dto/conceptresponse.dto.ts | 4 ---- dto/gameresponse.dto.ts | 21 ++++++--------------- dto/playerresponse.dto.ts | 6 +----- dto/userresponse.dto.ts | 3 --- dto/wordresponse.dto.ts | 14 +++++--------- game.events.ts | 20 ++++++++++++++++++++ lobby.events.ts | 18 +++++++++--------- word.events.ts | 10 +++++----- 9 files changed, 48 insertions(+), 56 deletions(-) create mode 100644 game.events.ts diff --git a/dto/conceptinturnresponse.dto.ts b/dto/conceptinturnresponse.dto.ts index 0b82ac6..bfef872 100644 --- a/dto/conceptinturnresponse.dto.ts +++ b/dto/conceptinturnresponse.dto.ts @@ -1,20 +1,16 @@ -import { Expose, Type } from 'class-transformer'; import { ConceptResponseDTO } from './conceptresponse.dto'; export class ConceptInTurnResponseDTO { constructor(partial: Partial) { Object.assign(this, partial); + this.concept = new ConceptResponseDTO(partial.concept); } - @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 index ed508fb..b3cd7d6 100644 --- a/dto/conceptresponse.dto.ts +++ b/dto/conceptresponse.dto.ts @@ -1,13 +1,9 @@ -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 index b3f755c..19a44ed 100644 --- a/dto/gameresponse.dto.ts +++ b/dto/gameresponse.dto.ts @@ -1,4 +1,3 @@ -import { Expose, Type } from 'class-transformer'; import { UserResponseDTO } from './userresponse.dto'; import { PlayerResponseDTO } from './playerresponse.dto'; import { ConceptInTurnResponseDTO } from './conceptinturnresponse.dto'; @@ -6,31 +5,23 @@ 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; + this.owner = new UserResponseDTO(partial.owner); + this.players = partial.players.map((p) => new PlayerResponseDTO(p)); + this.currentPlayer = new PlayerResponseDTO(partial.currentPlayer); + this.currentConcepts = partial.currentConcepts.map( + (c) => new ConceptInTurnResponseDTO(c), + ); } - @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 index 4ac8a53..a67cf44 100644 --- a/dto/playerresponse.dto.ts +++ b/dto/playerresponse.dto.ts @@ -1,16 +1,12 @@ -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; + this.user = new UserResponseDTO(partial.user); } - @Type(() => UserResponseDTO) - @Expose() user: UserResponseDTO; - @Expose() score: number; } diff --git a/dto/userresponse.dto.ts b/dto/userresponse.dto.ts index 53bf811..a294a7b 100644 --- a/dto/userresponse.dto.ts +++ b/dto/userresponse.dto.ts @@ -1,9 +1,6 @@ - - export class UserResponseDTO { constructor(partial: Partial) { Object.assign(this, partial); - } id: string; diff --git a/dto/wordresponse.dto.ts b/dto/wordresponse.dto.ts index de51748..7b283d1 100644 --- a/dto/wordresponse.dto.ts +++ b/dto/wordresponse.dto.ts @@ -1,9 +1,9 @@ export class WordResponseDTO { constructor(partial: Partial) { - if (partial.id) this.id = partial.id - if (partial.value) this.value = partial.value - if (partial.ownerId) this.ownerId = partial.ownerId - if (partial.enabled) this.enabled = partial.enabled + if (partial.id) this.id = partial.id; + if (partial.value) this.value = partial.value; + if (partial.ownerId) this.ownerId = partial.ownerId; + if (partial.enabled) this.enabled = partial.enabled; } id: number; @@ -14,9 +14,5 @@ export class WordResponseDTO { enabled: boolean; - loading?: boolean = false - - toJSON() { - return { ...this } // here I make a POJO's copy of the class instance - } + loading?: boolean = false; } diff --git a/game.events.ts b/game.events.ts new file mode 100644 index 0000000..28d8c57 --- /dev/null +++ b/game.events.ts @@ -0,0 +1,20 @@ +import { PlayerResponseDTO } from './dto/playerresponse.dto'; + +export class GameStartEvent { + type = 'start'; +} + +export class GameDeleteEvent { + type = 'delete'; +} + +export class GameJoinEvent { + type = 'joingame'; + constructor(public player: PlayerResponseDTO) {} +} + +export class GameLeaveEvent { + type = 'leavegame'; + gameId?: number; + constructor(public player: PlayerResponseDTO) {} +} diff --git a/lobby.events.ts b/lobby.events.ts index 5ce440c..30af269 100644 --- a/lobby.events.ts +++ b/lobby.events.ts @@ -1,34 +1,34 @@ -import { GameResponseDTO } from "./dto/gameresponse.dto"; -import { PlayerResponseDTO } from "./dto/playerresponse.dto"; +import { GameResponseDTO } from './dto/gameresponse.dto'; +import { PlayerResponseDTO } from './dto/playerresponse.dto'; export class LobbyCreateEvent { - type = "create"; + type = 'create'; constructor(public game: GameResponseDTO) {} } export class LobbyStartEvent { - type = "start"; + type = 'start'; constructor(public game: GameResponseDTO) {} } export class LobbyDeleteEvent { - type = "delete"; + type = 'delete'; constructor(public id: number) {} } export class LobbyJoinEvent { - type = "joingame"; + type = 'joingame'; constructor( public player: PlayerResponseDTO, - public game: GameResponseDTO + public game: GameResponseDTO, ) {} } export class LobbyLeaveEvent { - type = "leavegame"; + type = 'leavegame'; gameId?: number; constructor( public player: PlayerResponseDTO, - public game: GameResponseDTO + public game: GameResponseDTO, ) {} } diff --git a/word.events.ts b/word.events.ts index 7521b8d..2c09cd7 100644 --- a/word.events.ts +++ b/word.events.ts @@ -2,25 +2,25 @@ import { WordResponseDTO } from './dto/wordresponse.dto'; export class WordCreateEvent { type = 'create'; - constructor(public word: WordResponseDTO) { } + constructor(public word: WordResponseDTO) {} } export class WordEditEvent { type = 'edit'; - constructor(public word: WordResponseDTO) { } + constructor(public word: WordResponseDTO) {} } export class WordDeleteEvent { type = 'delete'; - constructor(public id: number) { } + constructor(public id: number) {} } export class WordEnableEvent { type = 'enable'; - constructor(public id: number) { } + constructor(public id: number) {} } export class WordDisableEvent { type = 'disable'; - constructor(public id: number) { } + constructor(public id: number) {} }