chore : remove class-transformer

This commit is contained in:
2024-12-29 23:47:41 +01:00
parent 49adbdec5b
commit e9d5d8d909
9 changed files with 48 additions and 56 deletions
+2 -6
View File
@@ -1,20 +1,16 @@
import { Expose, Type } from 'class-transformer';
import { ConceptResponseDTO } from './conceptresponse.dto';
export class ConceptInTurnResponseDTO {
constructor(partial: Partial<ConceptInTurnResponseDTO>) {
Object.assign(this, partial);
this.concept = new ConceptResponseDTO(partial.concept);
}
@Type(() => ConceptResponseDTO)
@Expose()
concept: ConceptResponseDTO;
@Expose()
order: number;
@Expose()
subconcept: number;
@Expose()
markers: number;
}
-4
View File
@@ -1,13 +1,9 @@
import { Expose } from 'class-transformer';
export class ConceptResponseDTO {
constructor(partial: Partial<ConceptResponseDTO>) {
Object.assign(this, partial);
}
@Expose()
id: number;
@Expose()
value: string;
}
+6 -15
View File
@@ -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<GameResponseDTO>) {
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[];
}
+1 -5
View File
@@ -1,16 +1,12 @@
import { Expose, Type } from 'class-transformer';
import { UserResponseDTO } from './userresponse.dto';
export class PlayerResponseDTO {
constructor(partial: Partial<PlayerResponseDTO>) {
Object.assign(this, partial);
this.user = partial.user;
this.user = new UserResponseDTO(partial.user);
}
@Type(() => UserResponseDTO)
@Expose()
user: UserResponseDTO;
@Expose()
score: number;
}
-3
View File
@@ -1,9 +1,6 @@
export class UserResponseDTO {
constructor(partial: Partial<UserResponseDTO>) {
Object.assign(this, partial);
}
id: string;
+5 -9
View File
@@ -1,9 +1,9 @@
export class WordResponseDTO {
constructor(partial: Partial<WordResponseDTO>) {
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;
}
+20
View File
@@ -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) {}
}
+9 -9
View File
@@ -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,
) {}
}