Skip to content

refactor: move queries logic to the repository layer#50

Open
illiakroshka wants to merge 27 commits into
mainfrom
refactor/move-queries-logic-to-the-repository-layer
Open

refactor: move queries logic to the repository layer#50
illiakroshka wants to merge 27 commits into
mainfrom
refactor/move-queries-logic-to-the-repository-layer

Conversation

@illiakroshka
Copy link
Copy Markdown
Contributor

  • created repository v2
  • move data logic to the repository

Comment on lines +47 to +49
} catch (error) {
this.logger.error('Failed to fetch visible games', error);
throw new Error('Failed to fetch visible games');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here throws NotFoundException when it will be used in Gateway where needs to be thrown WsException

Comment on lines +104 to +119
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');
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this property doesn't exist

Comment on lines +19 to +44
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 }>;
};
};
};
};
};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those types are should infer automatically

@illiakroshka illiakroshka force-pushed the main branch 2 times, most recently from 839adfb to 345c6e1 Compare November 26, 2025 17:29
@illiakroshka illiakroshka force-pushed the main branch 5 times, most recently from 2ba25b6 to 52a2ba8 Compare November 26, 2025 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants