From f1fb5a711328d90d29cc6ff4449384cf021b39fb Mon Sep 17 00:00:00 2001 From: baz Date: Fri, 10 Jan 2025 14:49:45 +0000 Subject: [PATCH] Fixed number of dropped games count in Wrapped --- commands/100-games/wrapped.js | 8 ++++---- databaseHelperFunctions.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/commands/100-games/wrapped.js b/commands/100-games/wrapped.js index 3fead11..37c4b6e 100644 --- a/commands/100-games/wrapped.js +++ b/commands/100-games/wrapped.js @@ -50,7 +50,7 @@ module.exports = { const favouriteGameGenres = await GetFavouriteGenres(); const favouriteGameDevs = await GetFavouriteDevelopers(); const favouriteGamePublishers = await GetFavouritePublishers(); - const numberOfGamesDropped = await GetNumberOfDroppedGames(userDatabaseEntry); + const numberOfGamesDropped = await GetNumberOfDroppedGames(userDatabaseEntry, year); const yearLeaderboardPlace = await GetYearLeaderboardPosition(userDatabaseEntry, year); const currentLeaderboardPlace = await GetLeaderboardPosition(userDatabaseEntry); @@ -361,11 +361,11 @@ async function GetFavouritePublishers() { return string; } -async function GetNumberOfDroppedGames(userDatabaseEntry) { - const userChangelog = await getChangelog(userDatabaseEntry.id); +async function GetNumberOfDroppedGames(userDatabaseEntry, year) { + const userChangelog = await getChangelog(userDatabaseEntry.id, `${year}-01-01`, `${year}-12-31`); const droppedGames = userChangelog.filter(item => item.oldStatus === 'playing' && item.newStatus === null); - if (droppedGames) { + if (droppedGames.length > 0) { return droppedGames.length.toString(); } diff --git a/databaseHelperFunctions.js b/databaseHelperFunctions.js index 9263b38..1925eb8 100644 --- a/databaseHelperFunctions.js +++ b/databaseHelperFunctions.js @@ -453,8 +453,8 @@ async function backupDatabase() { } } -async function getChangelog(id) { - const changelogEntries = await Changelog.findAll({ where: { userId: id }, order: [ [ 'updatedAt', 'DESC' ]] }) +async function getChangelog(id, startDate, endDate) { + const changelogEntries = await Changelog.findAll({ where: { userId: id, createdAt: { [ Op.between ]: [startDate, endDate] } }, order: [ [ 'updatedAt', 'DESC' ]] }) .catch((err) => { console.log(err); });