Compare commits

..
1 Commits
Author SHA1 Message Date
legonzaur cdddb9a073 fix : unify dto conversion 2024-12-30 00:39:06 +01:00
8 changed files with 54 additions and 21 deletions
+3 -1
View File
@@ -2,7 +2,9 @@ import { ConceptResponseDTO } from './conceptresponse.dto';
export class ConceptInTurnResponseDTO { export class ConceptInTurnResponseDTO {
constructor(partial: Partial<ConceptInTurnResponseDTO>) { constructor(partial: Partial<ConceptInTurnResponseDTO>) {
Object.assign(this, partial); this.order = partial.order;
this.subconcept = partial.subconcept;
this.markers = partial.markers;
this.concept = new ConceptResponseDTO(partial.concept); this.concept = new ConceptResponseDTO(partial.concept);
} }
+2 -1
View File
@@ -1,6 +1,7 @@
export class ConceptResponseDTO { export class ConceptResponseDTO {
constructor(partial: Partial<ConceptResponseDTO>) { constructor(partial: Partial<ConceptResponseDTO>) {
Object.assign(this, partial); this.id = partial.id;
this.value = partial.value;
} }
id: number; id: number;
+18 -9
View File
@@ -4,24 +4,33 @@ import { ConceptInTurnResponseDTO } from './conceptinturnresponse.dto';
export class GameResponseDTO { export class GameResponseDTO {
constructor(partial: Partial<GameResponseDTO>) { constructor(partial: Partial<GameResponseDTO>) {
Object.assign(this, partial); this.id = partial.id;
this.started = partial.started;
this.owner = new UserResponseDTO(partial.owner); this.owner = new UserResponseDTO(partial.owner);
this.players = partial.players.map((p) => new PlayerResponseDTO(p)); if (partial.players) {
this.currentPlayer = new PlayerResponseDTO(partial.currentPlayer); this.players = partial.players.map((p) => new PlayerResponseDTO(p));
this.currentConcepts = partial.currentConcepts.map( }
(c) => new ConceptInTurnResponseDTO(c),
); if (partial.currentConcepts) {
this.currentConcepts = partial.currentConcepts.map(
(c) => new ConceptInTurnResponseDTO(c),
);
}
if (partial.currentPlayer) {
this.currentPlayer = new PlayerResponseDTO(partial.currentPlayer);
}
} }
id: number; id: number;
owner: UserResponseDTO; owner: UserResponseDTO;
players: PlayerResponseDTO[]; players: PlayerResponseDTO[] = [];
currentPlayer: PlayerResponseDTO; currentPlayer?: PlayerResponseDTO;
started: boolean; started: boolean;
currentConcepts: ConceptInTurnResponseDTO[]; currentConcepts: ConceptInTurnResponseDTO[] = [];
} }
+1 -1
View File
@@ -2,7 +2,7 @@ import { UserResponseDTO } from './userresponse.dto';
export class PlayerResponseDTO { export class PlayerResponseDTO {
constructor(partial: Partial<PlayerResponseDTO>) { constructor(partial: Partial<PlayerResponseDTO>) {
Object.assign(this, partial); this.score = partial.score;
this.user = new UserResponseDTO(partial.user); this.user = new UserResponseDTO(partial.user);
} }
+3 -1
View File
@@ -1,6 +1,8 @@
export class UserResponseDTO { export class UserResponseDTO {
constructor(partial: Partial<UserResponseDTO>) { constructor(partial: Partial<UserResponseDTO>) {
Object.assign(this, partial); this.id = partial.id;
this.username = partial.username;
this.avatar = partial.avatar;
} }
id: string; id: string;
+6 -2
View File
@@ -10,11 +10,15 @@ export class GameDeleteEvent {
export class GameJoinEvent { export class GameJoinEvent {
type = 'joingame'; type = 'joingame';
constructor(public player: PlayerResponseDTO) {} constructor(public player: PlayerResponseDTO) {
this.player = new PlayerResponseDTO(player);
}
} }
export class GameLeaveEvent { export class GameLeaveEvent {
type = 'leavegame'; type = 'leavegame';
gameId?: number; gameId?: number;
constructor(public player: PlayerResponseDTO) {} constructor(public player: PlayerResponseDTO) {
this.player = new PlayerResponseDTO(player);
}
} }
+15 -4
View File
@@ -3,12 +3,17 @@ import { PlayerResponseDTO } from './dto/playerresponse.dto';
export class LobbyCreateEvent { export class LobbyCreateEvent {
type = 'create'; type = 'create';
constructor(public game: GameResponseDTO) {} game: GameResponseDTO;
constructor(game: GameResponseDTO) {
this.game = new GameResponseDTO(game);
}
} }
export class LobbyStartEvent { export class LobbyStartEvent {
type = 'start'; type = 'start';
constructor(public game: GameResponseDTO) {} constructor(public game: GameResponseDTO) {
this.game = new GameResponseDTO(game);
}
} }
export class LobbyDeleteEvent { export class LobbyDeleteEvent {
@@ -21,7 +26,10 @@ export class LobbyJoinEvent {
constructor( constructor(
public player: PlayerResponseDTO, public player: PlayerResponseDTO,
public game: GameResponseDTO, public game: GameResponseDTO,
) {} ) {
this.player = new PlayerResponseDTO(player);
this.game = new GameResponseDTO(game);
}
} }
export class LobbyLeaveEvent { export class LobbyLeaveEvent {
@@ -30,5 +38,8 @@ export class LobbyLeaveEvent {
constructor( constructor(
public player: PlayerResponseDTO, public player: PlayerResponseDTO,
public game: GameResponseDTO, public game: GameResponseDTO,
) {} ) {
this.player = new PlayerResponseDTO(player);
this.game = new GameResponseDTO(game);
}
} }
+6 -2
View File
@@ -2,12 +2,16 @@ import { WordResponseDTO } from './dto/wordresponse.dto';
export class WordCreateEvent { export class WordCreateEvent {
type = 'create'; type = 'create';
constructor(public word: WordResponseDTO) {} constructor(public word: WordResponseDTO) {
this.word = new WordResponseDTO(word);
}
} }
export class WordEditEvent { export class WordEditEvent {
type = 'edit'; type = 'edit';
constructor(public word: WordResponseDTO) {} constructor(public word: WordResponseDTO) {
this.word = new WordResponseDTO(word);
}
} }
export class WordDeleteEvent { export class WordDeleteEvent {