Introduce statusLastChanged column to BeatenGames table

This commit is contained in:
baz 2024-07-13 16:38:37 +01:00
parent a4024d01b5
commit 5abb10f7c3
7 changed files with 28 additions and 8 deletions

View File

@ -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');
}
}

View File

@ -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');
}
}

View File

@ -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');
}
}

View File

@ -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] });
},

View File

@ -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,
},
);

View File

@ -4,6 +4,10 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.ENUM('planning', 'playing', 'beat'),
allowNull: true,
},
statusLastChanged: {
type: DataTypes.DATE,
allowNull: true,
},
}, {
timestamps: true,
});

17
populateColumn.js Normal file
View File

@ -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);
}
})();