Fix : opti : use equals instead of toHexString comparisons

This commit is contained in:
2024-07-05 09:57:43 +02:00
parent 3b5701bbc2
commit d56abe3693
3 changed files with 7 additions and 11 deletions
+3 -3
View File
@@ -179,7 +179,7 @@ export class LobbyService {
await this.gamesService.fillMarket(game, session); await this.gamesService.fillMarket(game, session);
for (const team of game.teams) { for (const team of game.teams) {
for (const player of team.players) { for (const player of team.players) {
if (team._id.toHexString() == game.currentTurn.currentTeam) { if (team._id.equals(game.currentTurn.currentTeam)) {
await this.gamesService.drawToHand(3, player, game, session); await this.gamesService.drawToHand(3, player, game, session);
} else { } else {
await this.gamesService.drawToHand(5, player, game, session); await this.gamesService.drawToHand(5, player, game, session);
@@ -187,8 +187,8 @@ export class LobbyService {
} }
} }
const currentTeam = game.teams.find( const currentTeam = game.teams.find((t) =>
(t) => t._id.toHexString() == game.currentTurn.currentTeam, t._id.equals(game.currentTurn.currentTeam),
); );
for (const player of currentTeam.players) { for (const player of currentTeam.players) {
+1 -1
View File
@@ -24,7 +24,7 @@ export class TurnService {
cardId: string, cardId: string,
session?: mongoose.mongo.ClientSession, session?: mongoose.mongo.ClientSession,
) { ) {
const card = player.board.cards.find((c) => c._id.toHexString() == cardId); const card = player.board.cards.find((c) => c._id.equals(cardId));
if (!card) { if (!card) {
throw new HttpException( throw new HttpException(
'Card not found in player board', 'Card not found in player board',
+3 -7
View File
@@ -16,9 +16,7 @@ export function shuffle(a) {
} }
export function getCurrentTeam(game: Document<Game> & Game) { export function getCurrentTeam(game: Document<Game> & Game) {
return game.teams.find( return game.teams.find((t) => t._id.equals(game.currentTurn.currentTeam));
(t) => t._id.toHexString() == game.currentTurn.currentTeam,
);
} }
export function getPlayer(session: Record<string, any>, game: Game) { export function getPlayer(session: Record<string, any>, game: Game) {
@@ -28,7 +26,7 @@ export function getPlayer(session: Record<string, any>, game: Game) {
} }
for (const team of game.teams) { for (const team of game.teams) {
for (const player of team.players) { for (const player of team.players) {
if (player.user._id.toHexString() == user._id) { if (player.user._id.equals(user._id)) {
return player as Document<Player> & Player; return player as Document<Player> & Player;
} }
} }
@@ -40,9 +38,7 @@ export function getPlayer(session: Record<string, any>, game: Game) {
} }
export function isInTeam(team: Team, player: Player) { export function isInTeam(team: Team, player: Player) {
if ( if (team.players.some((p) => p._id.equals(player._id))) {
team.players.some((p) => p._id.toHexString() == player._id.toHexString())
) {
return true; return true;
} }
return false; return false;