Initial commit

This commit is contained in:
2025-05-06 12:42:05 +00:00
commit 287f7e2a3d
12 changed files with 294 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
import { ConceptResponseDTO } from "./dto/conceptresponse.dto";
import type { ConceptEvent } from "./events";
export class ConceptCreateEvent implements ConceptEvent {
type = "create";
constructor(public concept: ConceptResponseDTO) {
this.concept = new ConceptResponseDTO(concept);
}
}
export class ConceptEditEvent implements ConceptEvent {
type = "edit";
constructor(public concept: ConceptResponseDTO) {
this.concept = new ConceptResponseDTO(concept);
}
}
export class ConceptDeleteEvent implements ConceptEvent {
type = "delete";
constructor(public id: number) {}
}
export class ConceptEnableEvent implements ConceptEvent {
type = "enable";
constructor(public id: number) {}
}
export class ConceptDisableEvent implements ConceptEvent {
type = "disable";
constructor(public id: number) {}
}
+18
View File
@@ -0,0 +1,18 @@
import { ConceptResponseDTO } from './conceptresponse.dto';
export class ConceptInTurnResponseDTO {
constructor(partial: Partial<ConceptInTurnResponseDTO>) {
this.order = partial.order;
this.subconcept = partial.subconcept;
this.markers = partial.markers;
this.concept = new ConceptResponseDTO(partial.concept);
}
concept: ConceptResponseDTO;
order: number;
subconcept: number;
markers: number;
}
+22
View File
@@ -0,0 +1,22 @@
import { ApiRequestTimeoutResponse } from '@nestjs/swagger';
export class ConceptResponseDTO {
constructor(partial: Partial<ConceptResponseDTO>) {
this.id = partial.id;
this.value = partial.value;
this.type = new ConceptTypeResponseDTO(partial.type);
}
id: number;
value: string;
type: ConceptTypeResponseDTO;
}
export class ConceptTypeResponseDTO {
constructor(partial: Partial<ConceptTypeResponseDTO>) {
this.id = partial.id;
this.value = partial.value;
}
id: number;
value: string;
}
+42
View File
@@ -0,0 +1,42 @@
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>) {
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.currentConcepts) {
this.currentConcepts = partial.currentConcepts.map(
(c) => new ConceptInTurnResponseDTO(c),
);
}
if (partial.currentPlayer) {
this.currentPlayer = new PlayerResponseDTO(partial.currentPlayer);
}
}
id: number;
ownerId: string;
players: PlayerResponseDTO[] = [];
currentPlayer?: PlayerResponseDTO;
started: boolean;
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;
}
+14
View File
@@ -0,0 +1,14 @@
export class PlayerResponseDTO {
constructor(partial: Partial<PlayerResponseDTO>) {
this.score = partial.score;
this.userId = partial.userId;
this.id = partial.id;
this.hasGuessed = partial.hasGuessed;
// this.user = new UserResponseDTO(partial.user);
}
id: number;
userId: string;
score: number;
hasGuessed: boolean;
}
+12
View File
@@ -0,0 +1,12 @@
export class UserResponseDTO {
constructor(partial: Partial<UserResponseDTO>) {
this.id = partial.id;
this.username = partial.username;
this.avatar = partial.avatar;
}
id: string;
username: string;
avatar: string;
}
+18
View File
@@ -0,0 +1,18 @@
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;
}
id: number;
value: string;
ownerId: string;
enabled: boolean;
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);
}
}
+46
View File
@@ -0,0 +1,46 @@
import { GameResponseDTO } from "./dto/gameresponse.dto";
import { PlayerResponseDTO } from "./dto/playerresponse.dto";
import type { ConceptEvent } from "./events";
export class LobbyCreateEvent implements ConceptEvent {
type = "create";
game: GameResponseDTO;
constructor(game: GameResponseDTO) {
this.game = new GameResponseDTO(game);
}
}
export class LobbyStartEvent implements ConceptEvent {
type = "start";
constructor(public game: GameResponseDTO) {
this.game = new GameResponseDTO(game);
}
}
export class LobbyDeleteEvent implements ConceptEvent {
type = "delete";
constructor(public id: number) {}
}
export class LobbyJoinEvent implements ConceptEvent {
type = "joingame";
constructor(
public player: PlayerResponseDTO,
public game: GameResponseDTO,
) {
this.player = new PlayerResponseDTO(player);
this.game = new GameResponseDTO(game);
}
}
export class LobbyLeaveEvent implements ConceptEvent {
type = "leavegame";
gameId?: number;
constructor(
public player: PlayerResponseDTO,
public game: GameResponseDTO,
) {
this.player = new PlayerResponseDTO(player);
this.game = new GameResponseDTO(game);
}
}
+31
View File
@@ -0,0 +1,31 @@
import { WordResponseDTO } from "./dto/wordresponse.dto";
import type { ConceptEvent } from "./events";
export class WordCreateEvent implements ConceptEvent {
type = "create";
constructor(public word: WordResponseDTO) {
this.word = new WordResponseDTO(word);
}
}
export class WordEditEvent implements ConceptEvent {
type = "edit";
constructor(public word: WordResponseDTO) {
this.word = new WordResponseDTO(word);
}
}
export class WordDeleteEvent implements ConceptEvent {
type = "delete";
constructor(public id: number) {}
}
export class WordEnableEvent implements ConceptEvent {
type = "enable";
constructor(public id: number) {}
}
export class WordDisableEvent implements ConceptEvent {
type = "disable";
constructor(public id: number) {}
}