Compare commits
No commits in common. "3cbeb7df68ecbfe3d63acf3d25fc9dafe8db09ea" and "ccfee4f8c0eba5c7910b659ade615e42ce2e4157" have entirely different histories.
3cbeb7df68
...
ccfee4f8c0
|
@ -1,4 +1,4 @@
|
||||||
const { Users, Games, LoggedGames, Changelog } = require ('./dbObjects.js');
|
const { Users, Games, LoggedGames } = require ('./dbObjects.js');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
async function checkUserRegistration(user) {
|
async function checkUserRegistration(user) {
|
||||||
|
@ -85,8 +85,6 @@ async function createPlanningGameEntry(user, game, date) {
|
||||||
|
|
||||||
if (entry.status == 'planning') return false;
|
if (entry.status == 'planning') return false;
|
||||||
|
|
||||||
await createChangelogEntry(user, game, entry.status, 'planning');
|
|
||||||
|
|
||||||
entry.status = 'planning';
|
entry.status = 'planning';
|
||||||
|
|
||||||
if (!date) {
|
if (!date) {
|
||||||
|
@ -108,8 +106,6 @@ async function createPlayingGameEntry(user, game, date) {
|
||||||
|
|
||||||
if (entry.status == 'playing') return false;
|
if (entry.status == 'playing') return false;
|
||||||
|
|
||||||
await createChangelogEntry(user, game, entry.status, 'playing');
|
|
||||||
|
|
||||||
entry.status = 'playing';
|
entry.status = 'playing';
|
||||||
|
|
||||||
if (!date) {
|
if (!date) {
|
||||||
|
@ -131,8 +127,6 @@ async function createBeatenGameEntry(user, game, date) {
|
||||||
|
|
||||||
if (entry.status == 'beat') return false;
|
if (entry.status == 'beat') return false;
|
||||||
|
|
||||||
await createChangelogEntry(user, game, entry.status, 'beat');
|
|
||||||
|
|
||||||
entry.status = 'beat';
|
entry.status = 'beat';
|
||||||
|
|
||||||
if (!date) {
|
if (!date) {
|
||||||
|
@ -147,13 +141,6 @@ async function createBeatenGameEntry(user, game, date) {
|
||||||
return entry;
|
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) {
|
async function checkLoggedGameEntry(user, game) {
|
||||||
const bg = await LoggedGames.findOne({ where: { userId: user.id, gameId: game.id } })
|
const bg = await LoggedGames.findOne({ where: { userId: user.id, gameId: game.id } })
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -176,14 +163,7 @@ async function createLoggedGameEntry(user, game, status, date) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (bg) {
|
if (bg) return true;
|
||||||
await Changelog.create({ userId: user.id, gameId: game.id, newStatus: status })
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -236,13 +216,6 @@ async function deleteLoggedGameId(id, user, status) {
|
||||||
const entry = bg;
|
const entry = bg;
|
||||||
await bg.destroy();
|
await bg.destroy();
|
||||||
|
|
||||||
if (bg) {
|
|
||||||
await Changelog.create({ userId: user.id, gameId: entry.gameId, oldStatus: status })
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,13 +244,6 @@ async function deleteLoggedGameNum(num, user, status) {
|
||||||
const entry = bg[num - 1];
|
const entry = bg[num - 1];
|
||||||
await bg[num - 1].destroy();
|
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;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ const sequelize = new Sequelize('database', 'username', 'password', {
|
||||||
const db = require('./models/games.js')(sequelize, Sequelize.DataTypes);
|
const db = require('./models/games.js')(sequelize, Sequelize.DataTypes);
|
||||||
require('./models/users.js')(sequelize, Sequelize.DataTypes);
|
require('./models/users.js')(sequelize, Sequelize.DataTypes);
|
||||||
require('./models/beatenGames.js')(sequelize, Sequelize.DataTypes);
|
require('./models/beatenGames.js')(sequelize, Sequelize.DataTypes);
|
||||||
require('./models/changelog.js')(sequelize, Sequelize.DataTypes);
|
|
||||||
|
|
||||||
const force = process.argv.includes('--force') || process.argv.includes('-f');
|
const force = process.argv.includes('--force') || process.argv.includes('-f');
|
||||||
|
|
||||||
|
|
15
dbObjects.js
15
dbObjects.js
|
@ -10,24 +10,15 @@ const sequelize = new Sequelize('database', 'username', 'password', {
|
||||||
const Users = require('./models/users.js')(sequelize, Sequelize.DataTypes);
|
const Users = require('./models/users.js')(sequelize, Sequelize.DataTypes);
|
||||||
const Games = require('./models/games.js')(sequelize, Sequelize.DataTypes);
|
const Games = require('./models/games.js')(sequelize, Sequelize.DataTypes);
|
||||||
const LoggedGames = require('./models/beatenGames.js')(sequelize, Sequelize.DataTypes);
|
const LoggedGames = require('./models/beatenGames.js')(sequelize, Sequelize.DataTypes);
|
||||||
const Changelog = require('./models/changelog.js')(sequelize, Sequelize.DataTypes);
|
|
||||||
|
|
||||||
// Create userId foreignKey in LoggedGames
|
// Create userId foreignKey
|
||||||
Users.hasMany(LoggedGames);
|
Users.hasMany(LoggedGames);
|
||||||
LoggedGames.belongsTo(Users);
|
LoggedGames.belongsTo(Users);
|
||||||
|
|
||||||
// Create gameId foreignKey in LoggedGames
|
// Create gameId foreignKey
|
||||||
Games.hasMany(LoggedGames);
|
Games.hasMany(LoggedGames);
|
||||||
LoggedGames.belongsTo(Games);
|
LoggedGames.belongsTo(Games);
|
||||||
|
|
||||||
// Create userId foreignKey in Changelog
|
|
||||||
Users.hasMany(Changelog);
|
|
||||||
Changelog.belongsTo(Users);
|
|
||||||
|
|
||||||
// Create gameId foreignKey in Changelog
|
|
||||||
Games.hasMany(Changelog);
|
|
||||||
Changelog.belongsTo(Games);
|
|
||||||
|
|
||||||
Reflect.defineProperty(Users.prototype, 'addUser', {
|
Reflect.defineProperty(Users.prototype, 'addUser', {
|
||||||
value: async function addUser(userData) {
|
value: async function addUser(userData) {
|
||||||
const user = await Users.findOne({
|
const user = await Users.findOne({
|
||||||
|
@ -53,4 +44,4 @@ sequelize.sync({ alter: true })
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = { sequelize, Users, Games, LoggedGames, Changelog };
|
module.exports = { sequelize, Users, Games, LoggedGames };
|
|
@ -1,15 +0,0 @@
|
||||||
module.exports = (sequelize, DataTypes) => {
|
|
||||||
return sequelize.define('changelog', {
|
|
||||||
oldStatus: {
|
|
||||||
type: DataTypes.ENUM('planning', 'playing', 'beat'),
|
|
||||||
allowNull: true,
|
|
||||||
},
|
|
||||||
newStatus: {
|
|
||||||
type: DataTypes.ENUM('planning', 'playing', 'beat'),
|
|
||||||
allowNull: true,
|
|
||||||
},
|
|
||||||
}, {
|
|
||||||
timestamps: true,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
Loading…
Reference in New Issue