Compare commits
No commits in common. "8ba04b5735b2c0e39832dd773662cc085df3d50b" and "d2893d6d2e51566793675a5b7310867d79e57ebc" have entirely different histories.
8ba04b5735
...
d2893d6d2e
|
@ -3,4 +3,3 @@ node_modules
|
||||||
config.json
|
config.json
|
||||||
*.sqlite
|
*.sqlite
|
||||||
backups
|
backups
|
||||||
*.idea
|
|
|
@ -1,6 +1,6 @@
|
||||||
const { Sequelize, DataTypes } = require('sequelize');
|
const { Sequelize, DataTypes } = require('sequelize');
|
||||||
require('./dbObjects.js');
|
require('./dbObjects.js');
|
||||||
const { sequelize, LoggedGames } = require ('./dbObjects.js');
|
const { sequelize, BeatenGames } = require ('./dbObjects.js');
|
||||||
|
|
||||||
// Add a new column to the existing table
|
// Add a new column to the existing table
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const { Users, Games, LoggedGames } = require ('./dbObjects.js');
|
const { Users, Games, BeatenGames } = require ('./dbObjects.js');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
async function checkUserRegistration(user) {
|
async function checkUserRegistration(user) {
|
||||||
|
@ -68,14 +68,14 @@ async function checkGameStorageId(id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createBeatenGameEntry(user, game) {
|
async function createBeatenGameEntry(user, game) {
|
||||||
let bg = await LoggedGames.findOne({ where: { userId: user.id, gameId: game.id, status: 'beat' } })
|
let bg = await BeatenGames.findOne({ where: { userId: user.id, gameId: game.id } })
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (bg) return false;
|
if (bg) return false;
|
||||||
|
|
||||||
await LoggedGames.create({ userId: user.id, gameId: game.id })
|
await BeatenGames.create({ userId: user.id, gameId: game.id })
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
bg = data;
|
bg = data;
|
||||||
})
|
})
|
||||||
|
@ -102,7 +102,7 @@ async function getBeatenGameCount(user) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteBeatenGameId(id, user) {
|
async function deleteBeatenGameId(id, user) {
|
||||||
const bg = await LoggedGames.findOne({ where: { gameId: id, userId: user.id, status: 'beat' } })
|
const bg = await BeatenGames.findOne({ where: { gameId: id, userId: user.id } })
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
@ -116,7 +116,7 @@ async function deleteBeatenGameId(id, user) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteBeatenGameNum(num, user) {
|
async function deleteBeatenGameNum(num, user) {
|
||||||
const bg = await LoggedGames.findAll({ where: { userId: user.id, status: 'beat' } })
|
const bg = await BeatenGames.findAll({ where: { userId: user.id } })
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
@ -140,7 +140,7 @@ async function getLeaderboardEntries() {
|
||||||
const results = [];
|
const results = [];
|
||||||
|
|
||||||
for (let i = 0; i < users.length; i++) {
|
for (let i = 0; i < users.length; i++) {
|
||||||
const count = await LoggedGames.count({ where: { userId: users[i].id, status: 'beat' } });
|
const count = await BeatenGames.count({ where: { userId: users[i].id } });
|
||||||
|
|
||||||
const res = await Users.findOne({ where: { id: users[i].id } })
|
const res = await Users.findOne({ where: { id: users[i].id } })
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -156,7 +156,7 @@ async function getLeaderboardEntries() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getRecentGameEntry(userId) {
|
async function getRecentGameEntry(userId) {
|
||||||
const beatenGameEntry = await LoggedGames.findOne({ where: { userId: userId, status: 'beat' }, order: [ [ 'createdAt', 'DESC' ]] })
|
const beatenGameEntry = await BeatenGames.findOne({ where: { userId: userId }, order: [ [ 'createdAt', 'DESC' ]] })
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
@ -174,7 +174,7 @@ async function getRecentGameEntry(userId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getGames(id) {
|
async function getGames(id) {
|
||||||
const beatenGameEntry = await LoggedGames.findAll({ where: { userId: id, status: 'beat' } })
|
const beatenGameEntry = await BeatenGames.findAll({ where: { userId: id } })
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
|
12
dbObjects.js
12
dbObjects.js
|
@ -9,15 +9,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 BeatenGames = require('./models/beatenGames.js')(sequelize, Sequelize.DataTypes);
|
||||||
|
|
||||||
// Create userId foreignKey
|
// Create userId foreignKey
|
||||||
Users.hasMany(LoggedGames);
|
Users.hasMany(BeatenGames);
|
||||||
LoggedGames.belongsTo(Users);
|
BeatenGames.belongsTo(Users);
|
||||||
|
|
||||||
// Create gameId foreignKey
|
// Create gameId foreignKey
|
||||||
Games.hasMany(LoggedGames);
|
Games.hasMany(BeatenGames);
|
||||||
LoggedGames.belongsTo(Games);
|
BeatenGames.belongsTo(Games);
|
||||||
|
|
||||||
Reflect.defineProperty(Users.prototype, 'addUser', {
|
Reflect.defineProperty(Users.prototype, 'addUser', {
|
||||||
value: async function addUser(userData) {
|
value: async function addUser(userData) {
|
||||||
|
@ -44,4 +44,4 @@ sequelize.sync({ alter: true })
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = { sequelize, Users, Games, LoggedGames };
|
module.exports = { sequelize, Users, Games, BeatenGames };
|
Loading…
Reference in New Issue