diff --git a/commands/100-games/beatlist.js b/commands/100-games/beatlist.js index 847cf43..197d5bb 100644 --- a/commands/100-games/beatlist.js +++ b/commands/100-games/beatlist.js @@ -29,7 +29,7 @@ module.exports = { for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) { const game = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId); - const date = beatenGamesDatabaseEntries[i].updatedAt.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/'); + const date = beatenGamesDatabaseEntries[i].statusLastChanged.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/'); desc = desc.concat('**#', (i + 1), ' (', date, ')**: ', game.name, '\n'); } } diff --git a/commands/100-games/currentlyplaying.js b/commands/100-games/currentlyplaying.js index 08459e0..81b2252 100644 --- a/commands/100-games/currentlyplaying.js +++ b/commands/100-games/currentlyplaying.js @@ -29,7 +29,7 @@ module.exports = { for (let i = 0; i < databaseEntries.length; i++) { const game = await checkGameStorageId(databaseEntries[i].gameId); - const date = databaseEntries[i].updatedAt.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/'); + const date = databaseEntries[i].statusLastChanged.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/'); desc = desc.concat('**#', (i + 1), ' (', date, ')**: ', game.name, '\n'); } } diff --git a/commands/100-games/globalbeatlist.js b/commands/100-games/globalbeatlist.js index 0d33b3a..e775deb 100644 --- a/commands/100-games/globalbeatlist.js +++ b/commands/100-games/globalbeatlist.js @@ -20,7 +20,7 @@ module.exports = { for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) { const game = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId); const userentry = await getUserFromId(beatenGamesDatabaseEntries[i].userId); - const date = beatenGamesDatabaseEntries[i].updatedAt.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/'); + const date = beatenGamesDatabaseEntries[i].statusLastChanged.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/'); desc = desc.concat('**', date, '**: \t', game.name, ' \t*(', userentry.username, ')*\n'); } } diff --git a/commands/100-games/user.js b/commands/100-games/user.js index 268097b..8bb7474 100644 --- a/commands/100-games/user.js +++ b/commands/100-games/user.js @@ -49,7 +49,7 @@ module.exports = { embed.addFields({ name: 'Estimated Finish Date', value: `${date}`, inline: true }); } - if (recentEntry) embed.addFields({ name: 'Last Updated', value: `${recentEntry.updatedAt.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/')}`, inline: true }); + if (recentEntry) embed.addFields({ name: 'Last Updated', value: `${recentEntry.statusLastChanged.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/')}`, inline: true }); return interaction.editReply({ embeds: [embed] }); }, diff --git a/convertDatabase.js b/convertDatabase.js index ff4dd66..327ee1b 100644 --- a/convertDatabase.js +++ b/convertDatabase.js @@ -9,11 +9,10 @@ const { sequelize, LoggedGames } = require ('./dbObjects.js'); await sequelize.getQueryInterface().addColumn( 'BeatenGames', - 'status', + 'statusLastChanged', { - type: DataTypes.ENUM('planning', 'playing', 'beat'), - allowNull: false, - defaultValue: 'beat', + type: DataTypes.DATE, + allowNull: true, }, ); diff --git a/models/beatenGames.js b/models/beatenGames.js index c528737..f6729bb 100644 --- a/models/beatenGames.js +++ b/models/beatenGames.js @@ -4,6 +4,10 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.ENUM('planning', 'playing', 'beat'), allowNull: true, }, + statusLastChanged: { + type: DataTypes.DATE, + allowNull: true, + }, }, { timestamps: true, }); diff --git a/populateColumn.js b/populateColumn.js new file mode 100644 index 0000000..36a8861 --- /dev/null +++ b/populateColumn.js @@ -0,0 +1,17 @@ +const { LoggedGames } = require ('./dbObjects.js'); + +(async () => { + try { + const loggedGames = await LoggedGames.findAll(); + + for (const loggedGame of loggedGames) { + // Define your logic to populate newColumn based on existing data + loggedGame.statusLastChanged = loggedGame.updatedAt; + await loggedGame.save(); + } + + console.log('New column populated successfully'); + } catch (error) { + console.error('Error populating new column:', error); + } +})(); \ No newline at end of file