commit 287f7e2a3d71f901f4fdfe090105f0af5fbd52af Author: legonzaur Date: Tue May 6 12:42:05 2025 +0000 Initial commit diff --git a/concept.events.ts b/concept.events.ts new file mode 100644 index 0000000..dd1f7d8 --- /dev/null +++ b/concept.events.ts @@ -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) {} +} diff --git a/dto/conceptinturnresponse.dto.ts b/dto/conceptinturnresponse.dto.ts new file mode 100644 index 0000000..bdd464a --- /dev/null +++ b/dto/conceptinturnresponse.dto.ts @@ -0,0 +1,18 @@ +import { ConceptResponseDTO } from './conceptresponse.dto'; + +export class ConceptInTurnResponseDTO { + constructor(partial: Partial) { + 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; +} diff --git a/dto/conceptresponse.dto.ts b/dto/conceptresponse.dto.ts new file mode 100644 index 0000000..05d889f --- /dev/null +++ b/dto/conceptresponse.dto.ts @@ -0,0 +1,22 @@ +import { ApiRequestTimeoutResponse } from '@nestjs/swagger'; + +export class ConceptResponseDTO { + constructor(partial: Partial) { + 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) { + this.id = partial.id; + this.value = partial.value; + } + id: number; + value: string; +} diff --git a/dto/gameresponse.dto.ts b/dto/gameresponse.dto.ts new file mode 100644 index 0000000..626a3a2 --- /dev/null +++ b/dto/gameresponse.dto.ts @@ -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) { + 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[] = []; +} diff --git a/dto/messageresponse.dto.ts b/dto/messageresponse.dto.ts new file mode 100644 index 0000000..f71af0b --- /dev/null +++ b/dto/messageresponse.dto.ts @@ -0,0 +1,11 @@ +export class MessageResponseDTO { + constructor(partial: Partial) { + this.id = partial.id; + this.value = partial.value; + if (partial.authorId) this.authorId = partial.authorId; + } + + id: number; + value: string; + authorId?: string; +} diff --git a/dto/playerresponse.dto.ts b/dto/playerresponse.dto.ts new file mode 100644 index 0000000..709dfd0 --- /dev/null +++ b/dto/playerresponse.dto.ts @@ -0,0 +1,14 @@ +export class PlayerResponseDTO { + constructor(partial: Partial) { + 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; +} diff --git a/dto/userresponse.dto.ts b/dto/userresponse.dto.ts new file mode 100644 index 0000000..fed8c7b --- /dev/null +++ b/dto/userresponse.dto.ts @@ -0,0 +1,12 @@ +export class UserResponseDTO { + constructor(partial: Partial) { + this.id = partial.id; + this.username = partial.username; + this.avatar = partial.avatar; + } + id: string; + + username: string; + + avatar: string; +} diff --git a/dto/wordresponse.dto.ts b/dto/wordresponse.dto.ts new file mode 100644 index 0000000..7b283d1 --- /dev/null +++ b/dto/wordresponse.dto.ts @@ -0,0 +1,18 @@ +export class WordResponseDTO { + constructor(partial: Partial) { + 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; +} diff --git a/events.ts b/events.ts new file mode 100644 index 0000000..b160e66 --- /dev/null +++ b/events.ts @@ -0,0 +1,3 @@ +export interface ConceptEvent { + type: string; +} diff --git a/game.events.ts b/game.events.ts new file mode 100644 index 0000000..ad298f9 --- /dev/null +++ b/game.events.ts @@ -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); + } +} diff --git a/lobby.events.ts b/lobby.events.ts new file mode 100644 index 0000000..0c8ddce --- /dev/null +++ b/lobby.events.ts @@ -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); + } +} diff --git a/word.events.ts b/word.events.ts new file mode 100644 index 0000000..a567f4a --- /dev/null +++ b/word.events.ts @@ -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) {} +}