From 37d86b7a7d11a2a6113cbc25824a22474a7c155a Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 30 Oct 2023 15:49:06 +0000 Subject: [PATCH] add comments and fix score deletion --- src/services/updateData.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/services/updateData.ts b/src/services/updateData.ts index 61cffd3..89316aa 100644 --- a/src/services/updateData.ts +++ b/src/services/updateData.ts @@ -70,7 +70,7 @@ async function connectWebsocket() { pp, } = score; const { maxScore, stars, id: leaderboardId } = leaderboard; - await Score.findByIdAndDelete(id).exec(); // Remove any existing score with the same id + await Score.deleteOne({ _id: id }); // Delete the score if it already exists const data: any = { _id: id, @@ -94,11 +94,12 @@ async function connectWebsocket() { data.stars = stars; } - Score.create(data); + Score.create(data); // Create the score const countryId = normalizedRegionName(player.country?.toLowerCase()) || "unknown"; totalCountries[countryId] = (totalCountries[countryId] || 0) + 1; totalHeadsets[hmd] = (totalHeadsets[hmd] || 0) + 1; + // Update the leaderboard data in the database await LeaderboardSchema.updateOne( { _id: "scoresaber" }, { @@ -110,6 +111,7 @@ async function connectWebsocket() { } ).exec(); + // Write the metrics data to influx InfluxWriteAPI.writePoint( new Point("scoresaber") .tag("type", "score_count")