Skip to content
Permalink
Browse files
Fix some eslint errors
  • Loading branch information
drumevp committed Nov 27, 2019
1 parent 6f3086c commit e79d1b750b6a0a630c6874f5b7c83bca682c0d30
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 98 deletions.
1 app.js
@@ -73,5 +73,6 @@ app.use(game.routes())
app.use(adding.routes())
app.use(homepage.routes())
app.use(signup.routes())
app.use(home.routes())

module.exports = app
@@ -19,7 +19,8 @@ request('https://api.steampowered.com/ISteamApps/GetAppList/v2/', (error, respon
// eslint-disable-next-line max-lines-per-function
request(`https://store.steampowered.com/api/appdetails/?appids=${gameid}` , (error, response, body) => {
//console.log(gameid)
if (response.statusCode !== 200) {
const statusInt = 200
if (response.statusCode !== statusInt) {
//if the api doesn't load the page, skip
return
}
@@ -27,9 +27,9 @@ CREATE TABLE IF NOT EXISTS `reviews`
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`user` TEXT,
`game` INTEGER,
`review_score` INT,
`review_text` TEXT,
`review_date` DATE,
`reviewScore` INT,
`reviewText` TEXT,
`reviewDate` DATE,
`approved` TEXT
);

@@ -153,5 +153,5 @@ INSERT INTO 'platforms' VALUES (41, 'Google Stadia');
INSERT INTO 'platforms' VALUES (42, 'Linux');

INSERT INTO `users` (`username`, `hash`, `isAdmin`) VALUES ('admin', '$2b$12$niVK8DnXKSyYzAIOUun2C.PZ51waVc2NU/e7DQ9cYM6zxNwUiiOCG', 'yes');
INSERT INTO `users` (`username`, `hash`, `isAdmin`) VALUES ('user', '$2b$12$niVK8DnXKSyYAIOUun2C.PZ51waVc2NU/e7DQ9cYM6zxNwUiiOCG', 'no');
INSERT INTO `users` (`username`, `hash`, `isAdmin`) VALUES ('user', '$2b$12$niVK8DnXKSyYzAIOUun2C.PZ51waVc2NU/e7DQ9cYM6zxNwUiiOCG', 'no');

@@ -8,7 +8,8 @@ adding.get('/game', async ctx => {
const a = ctx.session.userID
const user = await ctx.db.getUser(Number(a))
const platformnames = await ctx.db.getAllPlatforms()
await ctx.render('addingGames.hbs', {platforms: platformnames, user: ctx.session.authorised, admin: await ctx.db.isUserAdmin(ctx.session.userID)})
await ctx.render('addingGames.hbs', {platforms: platformnames, user: ctx.session.authorised,
admin: await ctx.db.isUserAdmin(ctx.session.userID)})

if(!user) {
console.log('you are not allowed to add any games')
@@ -25,7 +25,8 @@ approval.get('/games', authenticateUser, async ctx => {
}
}

await ctx.render('approvalGames', {games: unapproved, user: ctx.session.authorised, admin: await ctx.db.isUserAdmin(ctx.session.userID)})
await ctx.render('approvalGames', {games: unapproved, user: ctx.session.authorised,
admin: await ctx.db.isUserAdmin(ctx.session.userID)})
} catch(err) {
await ctx.render('error', {message: err.message})
}
@@ -60,7 +61,8 @@ approval.get('/reviews', authenticateUser, async ctx => {
return await ctx.render('error', {message: 'Session not authorised'})
}
const unapproved = await ctx.db.approvalReviewList(false)
await ctx.render('approvalReviews', {review: unapproved, user: ctx.session.authorised, admin: await ctx.db.isUserAdmin(ctx.session.userID)})
await ctx.render('approvalReviews', {review: unapproved, user: ctx.session.authorised,
admin: await ctx.db.isUserAdmin(ctx.session.userID)})
} catch(err) {
await ctx.render('error', {message: err.message})
}
@@ -9,26 +9,28 @@ const Review = require('../models/review')
game.get('/game:id', async ctx => {
try {
const gamedata = await ctx.db.getGame(Number(ctx.params.id))
const reviews = (await ctx.db.getReviewsForGame(Number(gamedata.gameID))).reverse();
const reviewCount = reviews.length;
const platformsIds = gamedata.platforms.split(',');
const platforms = await ctx.db.getPlatforms(platformsIds);
const reviews = (await ctx.db.getReviewsForGame(Number(gamedata.gameID))).reverse()
const reviewCount = reviews.length
const platformsIds = gamedata.platforms.split(',')
const platforms = await ctx.db.getPlatforms(platformsIds)
const user = await ctx.db.getUser(ctx.session.userID)
let avgScore = 0;
let avgScore = 0
if (reviewCount > 0) {
avgScore = await ctx.db.getAvgScore(gamedata.gameID);
}
else {
avgScore = 0;
avgScore = await ctx.db.getAvgScore(gamedata.gameID)
} else {
avgScore = 0
}
if(gamedata.poster.startsWith('http')) {
gamedata.url = true
}
if (gamedata.approved === 'yes' || user.isAdmin === 'yes') { //so the game page can be opened by an admin during the approval process
await ctx.render('game', {review: reviews.slice(0,3), expandedReview: reviews, thisgame: gamedata, reviewNo: reviewCount, platforms: platforms, avgScore: avgScore, user: ctx.session.authorised, admin: await ctx.db.isUserAdmin(ctx.session.userID)})
}
else {
ctx.redirect(`/list`)
if (gamedata.approved === 'yes' || user.isAdmin === 'yes') {
//so the game page can be opened by an admin during the approval process
const sliceInt = 0.3
await ctx.render('game', {review: reviews.slice(sliceInt), expandedReview: reviews, thisgame: gamedata,
reviewNo: reviewCount, platforms: platforms, avgScore: avgScore, user: ctx.session.authorised,
admin: await ctx.db.isUserAdmin(ctx.session.userID)})
} else {
ctx.redirect('/list')
}
} catch(err) {
ctx.body = err.message
@@ -38,18 +40,16 @@ game.get('/game:id', async ctx => {
game.get('/allReviews:id', async ctx => {
try {
const gamedata = await ctx.db.getGame(Number(ctx.params.id))
const reviews = (await ctx.db.getReviewsForGame(Number(gamedata.gameID))).reverse();
const reviewCount = reviews.length;
let avgScore = 0;
if (reviewCount > 0)
{
avgScore = await ctx.db.getAvgScore(gamedata.gameID);
}
else
{
avgScore = 0;
const reviews = (await ctx.db.getReviewsForGame(Number(gamedata.gameID))).reverse()
const reviewCount = reviews.length
let avgScore = 0
if (reviewCount > 0) {
avgScore = await ctx.db.getAvgScore(gamedata.gameID)
} else {
avgScore = 0
}
await ctx.render('allReviews', {review: reviews, thisgame: gamedata, reviewNo: reviewCount, avgScore: avgScore, user: ctx.session.authorised, admin: await ctx.db.isUserAdmin(ctx.session.userID)})
await ctx.render('allReviews', {review: reviews, thisgame: gamedata, reviewNo: reviewCount,
avgScore: avgScore, user: ctx.session.authorised, admin: await ctx.db.isUserAdmin(ctx.session.userID)})
} catch(err) {
ctx.body = err.message
}
@@ -58,10 +58,10 @@ game.get('/allReviews:id', async ctx => {
game.post('/add', async ctx => {
try {
const body = ctx.request.body
let reviewText = body.rvtext;
const reviewText = body.rvtext
const user = await ctx.db.getUser(ctx.session.userID)
const review = new Review(user.username, body.gameID, body.starRating, reviewText, "DD/MM/YYYY", "no");
await ctx.db.createReview(review);
const review = new Review(user.username, body.gameID, body.starRating, reviewText, 'DD/MM/YYYY', 'no')
await ctx.db.createReview(review)
ctx.redirect(`/game${body.gameID}`)
} catch(err) {
ctx.redirect(`/?msg=ERROR: ${err.message}`)
@@ -5,7 +5,7 @@ const Router = require('koa-router')
const homepage = new Router({ prefix: '/homepage' })

homepage.get('/', async ctx => {
await ctx.render('homepage.hbs', {user: ctx.session.authorised, admin: await ctx.db.isUserAdmin(ctx.session.userID)})
await ctx.render('homepage.hbs',{user: ctx.session.authorised, admin: await ctx.db.isUserAdmin(ctx.session.userID)})
})

module.exports = homepage
@@ -27,7 +27,8 @@ list.get('/', async ctx => {
game.url = true
}
}
await ctx.render('listpage.hbs', {games: approved, user: ctx.session.authorised, admin: await ctx.db.isUserAdmin(ctx.session.userID)})
await ctx.render('listpage.hbs', {games: approved, user: ctx.session.authorised,
admin: await ctx.db.isUserAdmin(ctx.session.userID)})
} catch(err) {
await ctx.render('error', {message: err.message})
}
@@ -12,15 +12,17 @@ login.post('/', async ctx => {

const user = await ctx.db.getUser(username)
if (!user) {
return ctx.render('login.hbs', { errorMsg: 'User does not exist', user: ctx.session.authorised, admin: await ctx.db.isUserAdmin(ctx.session.userID)})
return ctx.render('login.hbs', { errorMsg: 'User does not exist',
user: ctx.session.authorised, admin: await ctx.db.isUserAdmin(ctx.session.userID)})
}

if (await bcrypt.compare(password, user.hash)) {
ctx.session.authorised = true
ctx.session.userID = user.id
return ctx.redirect('homepage')
} else {
return ctx.render('login.hbs', { errorMsg: 'Password incorrect', user: ctx.session.authorised, admin: await ctx.db.isUserAdmin(ctx.session.userID)})
return ctx.render('login.hbs', { errorMsg: 'Password incorrect', user: ctx.session.authorised,
admin: await ctx.db.isUserAdmin(ctx.session.userID)})
}
})

0 comments on commit e79d1b7

Please sign in to comment.