Compare commits

..
17 Commits
Author SHA1 Message Date
legonzaur ccd11f29a1 chore: formatting 2025-05-06 14:36:52 +02:00
legonzaur 913c82994a chore: remove concept 2025-05-06 14:23:53 +02:00
legonzaur 24c39d23d6 chore : eslint 2025-01-13 22:33:38 +01:00
legonzaur a99853f417 feat: add concept type 2025-01-13 22:14:45 +01:00
legonzaur 1473c5c132 feat: concept events 2024-12-31 14:15:38 +01:00
legonzaur fc3f0e1677 add GameEndTurnEvent 2024-12-30 19:08:23 +01:00
legonzaur c1a22098f7 add player hasGuessed 2024-12-30 18:36:56 +01:00
legonzaur 22656ba608 add delete message 2024-12-30 18:13:12 +01:00
legonzaur 924806e4c8 fix : set message event to use MessageResponseDTO 2024-12-30 17:54:13 +01:00
legonzaur 47ed1ba851 fix : set message event to use messageResponseDTO 2024-12-30 17:53:31 +01:00
legonzaur 27b1044832 update messageResponse author id 2024-12-30 17:45:05 +01:00
legonzaur 813d942638 Feat : add messages 2024-12-30 17:41:17 +01:00
legonzaur 63f8cd45af set userid to strng 2024-12-30 12:06:49 +01:00
legonzaur e872eeea91 feat : send only user ids 2024-12-30 12:04:53 +01:00
legonzaur 735e47cdbe feat: add gameStartEvent 2024-12-30 11:14:47 +01:00
legonzaur cdddb9a073 fix : unify dto conversion 2024-12-30 00:39:06 +01:00
legonzaur e9d5d8d909 chore : remove class-transformer 2024-12-29 23:47:41 +01:00
11 changed files with 140 additions and 106 deletions
-20
View File
@@ -1,20 +0,0 @@
import { Expose, Type } from 'class-transformer';
import { ConceptResponseDTO } from './conceptresponse.dto';
export class ConceptInTurnResponseDTO {
constructor(partial: Partial<ConceptInTurnResponseDTO>) {
Object.assign(this, partial);
}
@Type(() => ConceptResponseDTO)
@Expose()
concept: ConceptResponseDTO;
@Expose()
order: number;
@Expose()
subconcept: number;
@Expose()
markers: number;
}
-13
View File
@@ -1,13 +0,0 @@
import { Expose } from 'class-transformer';
export class ConceptResponseDTO {
constructor(partial: Partial<ConceptResponseDTO>) {
Object.assign(this, partial);
}
@Expose()
id: number;
@Expose()
value: string;
}
+18 -22
View File
@@ -1,36 +1,32 @@
import { Expose, Type } from 'class-transformer';
import { UserResponseDTO } from './userresponse.dto';
import { PlayerResponseDTO } from './playerresponse.dto';
import { ConceptInTurnResponseDTO } from './conceptinturnresponse.dto';
import { MessageResponseDTO } from './messageresponse.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.id = partial.id;
this.started = partial.started;
this.ownerId = partial.ownerId;
if (partial.messages) {
this.messages = partial.messages.map((m) => new MessageResponseDTO(m));
}
if (partial.players) {
this.players = partial.players.map((p) => new PlayerResponseDTO(p));
}
if (partial.currentPlayer) {
this.currentPlayer = new PlayerResponseDTO(partial.currentPlayer);
}
}
@Expose()
id: number;
@Type(() => UserResponseDTO)
@Expose()
owner: UserResponseDTO;
ownerId: string;
@Type(() => PlayerResponseDTO)
@Expose()
players: PlayerResponseDTO[];
players: PlayerResponseDTO[] = [];
@Type(() => PlayerResponseDTO)
@Expose()
currentPlayer: PlayerResponseDTO;
currentPlayer?: PlayerResponseDTO;
@Expose()
started: boolean;
@Type(() => ConceptInTurnResponseDTO)
@Expose()
currentConcepts: ConceptInTurnResponseDTO[];
messages: MessageResponseDTO[] = [];
}
+11
View File
@@ -0,0 +1,11 @@
export class MessageResponseDTO {
constructor(partial: Partial<MessageResponseDTO>) {
this.id = partial.id;
this.value = partial.value;
if (partial.authorId) this.authorId = partial.authorId;
}
id: number;
value: string;
authorId?: string;
}
+8 -10
View File
@@ -1,16 +1,14 @@
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.score = partial.score;
this.userId = partial.userId;
this.id = partial.id;
this.hasGuessed = partial.hasGuessed;
// this.user = new UserResponseDTO(partial.user);
}
@Type(() => UserResponseDTO)
@Expose()
user: UserResponseDTO;
@Expose()
id: number;
userId: string;
score: number;
hasGuessed: boolean;
}
+4 -5
View File
@@ -1,9 +1,8 @@
export class UserResponseDTO {
constructor(partial: Partial<UserResponseDTO>) {
Object.assign(this, partial);
constructor(partial: UserResponseDTO) {
this.id = partial.id;
this.username = partial.username;
this.avatar = partial.avatar;
}
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;
}
+3
View File
@@ -0,0 +1,3 @@
export interface ConceptEvent {
type: string;
}
+47
View File
@@ -0,0 +1,47 @@
import { MessageResponseDTO } from "./dto/messageresponse.dto";
import { PlayerResponseDTO } from "./dto/playerresponse.dto";
import type { ConceptEvent } from "./events";
export class GameStartEvent implements ConceptEvent {
type = "start";
constructor(public currentPlayer: PlayerResponseDTO) {
this.currentPlayer = new PlayerResponseDTO(currentPlayer);
}
}
export class GameDeleteEvent implements ConceptEvent {
type = "delete";
}
export class GameJoinEvent implements ConceptEvent {
type = "joingame";
constructor(public player: PlayerResponseDTO) {
this.player = new PlayerResponseDTO(player);
}
}
export class GameLeaveEvent implements ConceptEvent {
type = "leavegame";
constructor(public player: PlayerResponseDTO) {
this.player = new PlayerResponseDTO(player);
}
}
export class GameMessageEvent implements ConceptEvent {
type = "message";
constructor(public message: MessageResponseDTO) {
this.message = new MessageResponseDTO(message);
}
}
export class GameMessageDeleteEvent implements ConceptEvent {
type = "deleteMessage";
constructor(public messageId: number) {}
}
export class GameEndTurnEvent implements ConceptEvent {
type = "endTurn";
constructor(public currentPlayer: PlayerResponseDTO) {
this.currentPlayer = new PlayerResponseDTO(currentPlayer);
}
}
+23 -11
View File
@@ -1,34 +1,46 @@
import { GameResponseDTO } from "./dto/gameresponse.dto";
import { PlayerResponseDTO } from "./dto/playerresponse.dto";
import type { ConceptEvent } from "./events";
export class LobbyCreateEvent {
export class LobbyCreateEvent implements ConceptEvent {
type = "create";
constructor(public game: GameResponseDTO) {}
game: GameResponseDTO;
constructor(game: GameResponseDTO) {
this.game = new GameResponseDTO(game);
}
}
export class LobbyStartEvent {
export class LobbyStartEvent implements ConceptEvent {
type = "start";
constructor(public game: GameResponseDTO) {}
constructor(public game: GameResponseDTO) {
this.game = new GameResponseDTO(game);
}
}
export class LobbyDeleteEvent {
export class LobbyDeleteEvent implements ConceptEvent {
type = "delete";
constructor(public id: number) {}
}
export class LobbyJoinEvent {
export class LobbyJoinEvent implements ConceptEvent {
type = "joingame";
constructor(
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 implements ConceptEvent {
type = "leavegame";
gameId?: number;
constructor(
public player: PlayerResponseDTO,
public game: GameResponseDTO
) {}
public game: GameResponseDTO,
) {
this.player = new PlayerResponseDTO(player);
this.game = new GameResponseDTO(game);
}
}
+21 -16
View File
@@ -1,26 +1,31 @@
import { WordResponseDTO } from './dto/wordresponse.dto';
import { WordResponseDTO } from "./dto/wordresponse.dto";
import type { ConceptEvent } from "./events";
export class WordCreateEvent {
type = 'create';
constructor(public word: WordResponseDTO) { }
export class WordCreateEvent implements ConceptEvent {
type = "create";
constructor(public word: WordResponseDTO) {
this.word = new WordResponseDTO(word);
}
}
export class WordEditEvent {
type = 'edit';
constructor(public word: WordResponseDTO) { }
export class WordEditEvent implements ConceptEvent {
type = "edit";
constructor(public word: WordResponseDTO) {
this.word = new WordResponseDTO(word);
}
}
export class WordDeleteEvent {
type = 'delete';
constructor(public id: number) { }
export class WordDeleteEvent implements ConceptEvent {
type = "delete";
constructor(public id: number) {}
}
export class WordEnableEvent {
type = 'enable';
constructor(public id: number) { }
export class WordEnableEvent implements ConceptEvent {
type = "enable";
constructor(public id: number) {}
}
export class WordDisableEvent {
type = 'disable';
constructor(public id: number) { }
export class WordDisableEvent implements ConceptEvent {
type = "disable";
constructor(public id: number) {}
}