refactor: move queries logic to the repository layer#50
Conversation
illiakroshka
commented
Oct 13, 2025
- created repository v2
- move data logic to the repository
…k it's connection data
- created repository v2 - move data logic to the repository
| } catch (error) { | ||
| this.logger.error('Failed to fetch visible games', error); | ||
| throw new Error('Failed to fetch visible games'); |
There was a problem hiding this comment.
This try catch makes no sense because it's just rethrowing error which anyway needs to WsException since it's used in gateway, so i would recommend to move error handling in service with the right type of error it should throw.
| players: { | ||
| create: { | ||
| userId, | ||
| color: '#000000', |
There was a problem hiding this comment.
color should be just a string as it was before from object COLORS, it needs just a string for a frontend
| })) as unknown as GameWithRelations; | ||
|
|
||
| if (!game) { | ||
| throw new NotFoundException(`Game with ID ${gameId} not found`); |
There was a problem hiding this comment.
same here throws NotFoundException when it will be used in Gateway where needs to be thrown WsException
| const gameWithPlayers = await tx.game.findUnique({ | ||
| where: { id: gameId }, | ||
| include: { | ||
| players: { | ||
| orderBy: { createdAt: 'asc' }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| if (!gameWithPlayers) { | ||
| throw new NotFoundException(`Game with ID ${gameId} not found`); | ||
| } | ||
|
|
||
| if (gameWithPlayers.players.length < 2) { | ||
| throw new Error('At least 2 players are required to start the game'); | ||
| } |
There was a problem hiding this comment.
Here we need to validate game before to check whether the status is "LOBBY" and maybe player already in game or in other game, all this logic should be in service and then game should be passed for starting(actually just updating it's status) but then in transaction it will retrieve it again so it's unnecessary
| user: Pick<User, 'id' | 'nickname'>; | ||
| })[]; | ||
| currentPlayer: Player | null; | ||
| winner: User | null; |
There was a problem hiding this comment.
this property doesn't exist
| export type CreateGameData = { | ||
| playersCapacity: number; | ||
| players: { | ||
| create: { | ||
| userId: string; | ||
| color: string; | ||
| }; | ||
| }; | ||
| turnEnds: string; | ||
| }; | ||
|
|
||
| export type StartGameData = { | ||
| status: GameStatus; | ||
| turnOfUserId: string; | ||
| turnEnds: string; | ||
| chat: { | ||
| create: { | ||
| type: ChatType; | ||
| participants: { | ||
| createMany: { | ||
| data: Array<{ userId: string }>; | ||
| }; | ||
| }; | ||
| }; | ||
| }; | ||
| }; |
There was a problem hiding this comment.
those types are should infer automatically
839adfb to
345c6e1
Compare
2ba25b6 to
52a2ba8
Compare