Create changelog entries when creating new entries

This commit is contained in:
baz 2024-07-13 21:27:51 +01:00
parent 5fb39b28b3
commit 3cbeb7df68
1 changed files with 35 additions and 1 deletions

View File

@ -85,6 +85,8 @@ async function createPlanningGameEntry(user, game, date) {
if (entry.status == 'planning') return false;
await createChangelogEntry(user, game, entry.status, 'planning');
entry.status = 'planning';
if (!date) {
@ -106,6 +108,8 @@ async function createPlayingGameEntry(user, game, date) {
if (entry.status == 'playing') return false;
await createChangelogEntry(user, game, entry.status, 'playing');
entry.status = 'playing';
if (!date) {
@ -127,6 +131,8 @@ async function createBeatenGameEntry(user, game, date) {
if (entry.status == 'beat') return false;
await createChangelogEntry(user, game, entry.status, 'beat');
entry.status = 'beat';
if (!date) {
@ -141,6 +147,13 @@ async function createBeatenGameEntry(user, game, date) {
return entry;
}
async function createChangelogEntry(user, game, oldStatus, newStatus) {
return await Changelog.create({ userId: user.id, gameId: game.id, newStatus: newStatus, oldStatus: oldStatus })
.catch((err) => {
console.log(err);
});
}
async function checkLoggedGameEntry(user, game) {
const bg = await LoggedGames.findOne({ where: { userId: user.id, gameId: game.id } })
.catch((err) => {
@ -163,7 +176,14 @@ async function createLoggedGameEntry(user, game, status, date) {
console.log(err);
});
if (bg) return true;
if (bg) {
await Changelog.create({ userId: user.id, gameId: game.id, newStatus: status })
.catch((err) => {
console.log(err);
});
return true;
}
return false;
}
@ -216,6 +236,13 @@ async function deleteLoggedGameId(id, user, status) {
const entry = bg;
await bg.destroy();
if (bg) {
await Changelog.create({ userId: user.id, gameId: entry.gameId, oldStatus: status })
.catch((err) => {
console.log(err);
});
}
return entry;
}
@ -244,6 +271,13 @@ async function deleteLoggedGameNum(num, user, status) {
const entry = bg[num - 1];
await bg[num - 1].destroy();
if (bg) {
await Changelog.create({ userId: user.id, gameId: entry.gameId, oldStatus: status })
.catch((err) => {
console.log(err);
});
}
return entry;
}