Database Helper Functions updates
This commit is contained in:
parent
72817556a6
commit
f2fb035859
|
@ -74,7 +74,9 @@ async function createPlanningGameEntry(user, game) {
|
||||||
|
|
||||||
if (entry.status == 'planning') return false;
|
if (entry.status == 'planning') return false;
|
||||||
|
|
||||||
entry.update({ status: 'planning' });
|
entry.status = 'planning';
|
||||||
|
|
||||||
|
await entry.save();
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
@ -86,7 +88,9 @@ async function createPlayingGameEntry(user, game) {
|
||||||
|
|
||||||
if (entry.status == 'playing') return false;
|
if (entry.status == 'playing') return false;
|
||||||
|
|
||||||
entry.save({ status: 'playing' });
|
entry.status = 'playing';
|
||||||
|
|
||||||
|
await entry.save();
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +102,9 @@ async function createBeatenGameEntry(user, game) {
|
||||||
|
|
||||||
if (entry.status == 'beat') return false;
|
if (entry.status == 'beat') return false;
|
||||||
|
|
||||||
entry.update({ status: 'beat' });
|
entry.status = 'beat';
|
||||||
|
|
||||||
|
await entry.save();
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
@ -246,7 +252,7 @@ async function getRecentBeatenGameEntry(userId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getRecentGameEntry(userId, status) {
|
async function getRecentGameEntry(userId, status) {
|
||||||
const beatenGameEntry = await LoggedGames.findOne({ where: { userId: userId, status: status }, order: [ [ 'createdAt', 'DESC' ]] })
|
const beatenGameEntry = await LoggedGames.findOne({ where: { userId: userId, status: status }, order: [ [ 'updatedAt', 'ASC' ]] })
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
@ -263,13 +269,25 @@ async function getRecentGameEntry(userId, status) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getGames(id) {
|
async function getPlanningGames(id) {
|
||||||
const beatenGameEntry = await LoggedGames.findAll({ where: { userId: id, status: 'beat' } })
|
return await getGames(id, 'planning');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getPlayingGames(id) {
|
||||||
|
return await getGames(id, 'playing');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getBeatenGames(id) {
|
||||||
|
return await getGames(id, 'beat');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getGames(id, status) {
|
||||||
|
const gameEntries = await LoggedGames.findAll({ where: { userId: id, status: status }, order: [ [ 'updatedAt', 'ASC' ]] })
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (beatenGameEntry) return beatenGameEntry;
|
if (gameEntries) return gameEntries;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -309,6 +327,9 @@ module.exports = {
|
||||||
getRecentPlayingGameEntry,
|
getRecentPlayingGameEntry,
|
||||||
getRecentBeatenGameEntry,
|
getRecentBeatenGameEntry,
|
||||||
getRecentGameEntry,
|
getRecentGameEntry,
|
||||||
|
getPlanningGames,
|
||||||
|
getPlayingGames,
|
||||||
|
getBeatenGames,
|
||||||
getGames,
|
getGames,
|
||||||
backupDatabase,
|
backupDatabase,
|
||||||
};
|
};
|
Loading…
Reference in New Issue