Fixed number of dropped games count in Wrapped

This commit is contained in:
baz 2025-01-10 14:49:45 +00:00
parent 092a9dad6a
commit f1fb5a7113
2 changed files with 6 additions and 6 deletions

View File

@ -50,7 +50,7 @@ module.exports = {
const favouriteGameGenres = await GetFavouriteGenres(); const favouriteGameGenres = await GetFavouriteGenres();
const favouriteGameDevs = await GetFavouriteDevelopers(); const favouriteGameDevs = await GetFavouriteDevelopers();
const favouriteGamePublishers = await GetFavouritePublishers(); const favouriteGamePublishers = await GetFavouritePublishers();
const numberOfGamesDropped = await GetNumberOfDroppedGames(userDatabaseEntry); const numberOfGamesDropped = await GetNumberOfDroppedGames(userDatabaseEntry, year);
const yearLeaderboardPlace = await GetYearLeaderboardPosition(userDatabaseEntry, year); const yearLeaderboardPlace = await GetYearLeaderboardPosition(userDatabaseEntry, year);
const currentLeaderboardPlace = await GetLeaderboardPosition(userDatabaseEntry); const currentLeaderboardPlace = await GetLeaderboardPosition(userDatabaseEntry);
@ -361,11 +361,11 @@ async function GetFavouritePublishers() {
return string; return string;
} }
async function GetNumberOfDroppedGames(userDatabaseEntry) { async function GetNumberOfDroppedGames(userDatabaseEntry, year) {
const userChangelog = await getChangelog(userDatabaseEntry.id); const userChangelog = await getChangelog(userDatabaseEntry.id, `${year}-01-01`, `${year}-12-31`);
const droppedGames = userChangelog.filter(item => item.oldStatus === 'playing' && item.newStatus === null); const droppedGames = userChangelog.filter(item => item.oldStatus === 'playing' && item.newStatus === null);
if (droppedGames) { if (droppedGames.length > 0) {
return droppedGames.length.toString(); return droppedGames.length.toString();
} }

View File

@ -453,8 +453,8 @@ async function backupDatabase() {
} }
} }
async function getChangelog(id) { async function getChangelog(id, startDate, endDate) {
const changelogEntries = await Changelog.findAll({ where: { userId: id }, order: [ [ 'updatedAt', 'DESC' ]] }) const changelogEntries = await Changelog.findAll({ where: { userId: id, createdAt: { [ Op.between ]: [startDate, endDate] } }, order: [ [ 'updatedAt', 'DESC' ]] })
.catch((err) => { .catch((err) => {
console.log(err); console.log(err);
}); });