fix : unify dto conversion

This commit is contained in:
2024-12-30 00:39:06 +01:00
parent e9d5d8d909
commit cdddb9a073
8 changed files with 54 additions and 21 deletions
+18 -9
View File
@@ -4,24 +4,33 @@ import { ConceptInTurnResponseDTO } from './conceptinturnresponse.dto';
export class GameResponseDTO {
constructor(partial: Partial<GameResponseDTO>) {
Object.assign(this, partial);
this.id = partial.id;
this.started = partial.started;
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),
);
if (partial.players) {
this.players = partial.players.map((p) => new PlayerResponseDTO(p));
}
if (partial.currentConcepts) {
this.currentConcepts = partial.currentConcepts.map(
(c) => new ConceptInTurnResponseDTO(c),
);
}
if (partial.currentPlayer) {
this.currentPlayer = new PlayerResponseDTO(partial.currentPlayer);
}
}
id: number;
owner: UserResponseDTO;
players: PlayerResponseDTO[];
players: PlayerResponseDTO[] = [];
currentPlayer: PlayerResponseDTO;
currentPlayer?: PlayerResponseDTO;
started: boolean;
currentConcepts: ConceptInTurnResponseDTO[];
currentConcepts: ConceptInTurnResponseDTO[] = [];
}