Introduce statusLastChanged column to BeatenGames table
This commit is contained in:
parent
a4024d01b5
commit
5abb10f7c3
|
@ -29,7 +29,7 @@ module.exports = {
|
||||||
|
|
||||||
for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) {
|
for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) {
|
||||||
const game = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId);
|
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');
|
desc = desc.concat('**#', (i + 1), ' (', date, ')**: ', game.name, '\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ module.exports = {
|
||||||
|
|
||||||
for (let i = 0; i < databaseEntries.length; i++) {
|
for (let i = 0; i < databaseEntries.length; i++) {
|
||||||
const game = await checkGameStorageId(databaseEntries[i].gameId);
|
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');
|
desc = desc.concat('**#', (i + 1), ' (', date, ')**: ', game.name, '\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ module.exports = {
|
||||||
for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) {
|
for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) {
|
||||||
const game = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId);
|
const game = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId);
|
||||||
const userentry = await getUserFromId(beatenGamesDatabaseEntries[i].userId);
|
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');
|
desc = desc.concat('**', date, '**: \t', game.name, ' \t*(', userentry.username, ')*\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ module.exports = {
|
||||||
embed.addFields({ name: 'Estimated Finish Date', value: `${date}`, inline: true });
|
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] });
|
return interaction.editReply({ embeds: [embed] });
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,11 +9,10 @@ const { sequelize, LoggedGames } = require ('./dbObjects.js');
|
||||||
|
|
||||||
await sequelize.getQueryInterface().addColumn(
|
await sequelize.getQueryInterface().addColumn(
|
||||||
'BeatenGames',
|
'BeatenGames',
|
||||||
'status',
|
'statusLastChanged',
|
||||||
{
|
{
|
||||||
type: DataTypes.ENUM('planning', 'playing', 'beat'),
|
type: DataTypes.DATE,
|
||||||
allowNull: false,
|
allowNull: true,
|
||||||
defaultValue: 'beat',
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,10 @@ module.exports = (sequelize, DataTypes) => {
|
||||||
type: DataTypes.ENUM('planning', 'playing', 'beat'),
|
type: DataTypes.ENUM('planning', 'playing', 'beat'),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
},
|
},
|
||||||
|
statusLastChanged: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
}, {
|
}, {
|
||||||
timestamps: true,
|
timestamps: true,
|
||||||
});
|
});
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
})();
|
Loading…
Reference in New Issue