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);
for (const team of game.teams) {
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);
} else {
await this.gamesService.drawToHand(5, player, game, session);
@@ -187,8 +187,8 @@ export class LobbyService {
}
}
const currentTeam = game.teams.find(
(t) => t._id.toHexString() == game.currentTurn.currentTeam,
const currentTeam = game.teams.find((t) =>
t._id.equals(game.currentTurn.currentTeam),
);
for (const player of currentTeam.players) {
+1 -1
View File
@@ -24,7 +24,7 @@ export class TurnService {
cardId: string,
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) {
throw new HttpException(
'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) {
return game.teams.find(
(t) => t._id.toHexString() == game.currentTurn.currentTeam,
);
return game.teams.find((t) => t._id.equals(game.currentTurn.currentTeam));
}
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 player of team.players) {
if (player.user._id.toHexString() == user._id) {
if (player.user._id.equals(user._id)) {
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) {
if (
team.players.some((p) => p._id.toHexString() == player._id.toHexString())
) {
if (team.players.some((p) => p._id.equals(player._id))) {
return true;
}
return false;