Skip to content

Commit

Permalink
linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fcaps committed Dec 1, 2023
1 parent 02f8cdd commit 8c497fa
Show file tree
Hide file tree
Showing 24 changed files with 89 additions and 124 deletions.
9 changes: 8 additions & 1 deletion src/backend/routes/views/account/get/connectSteam.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ exports = module.exports = function (req, res) {
headers: { Authorization: 'Bearer ' + req.services.userService.getUser()?.oAuthPassport.token },
form: { callbackUrl: req.protocol + '://' + req.get('host') + '/account/link?done' }
}, function (err, res, body) {

Check warning on line 14 in src/backend/routes/views/account/get/connectSteam.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/get/connectSteam.js#L14

Added line #L14 was not covered by tests
// Must not be valid, check to see if errors, otherwise return generic error.
if (err) {
flash.class = 'alert-danger'
flash.messages = [{ msg: 'Your steam account was not successfully linked! Please verify you logged into the website correctly.' }]
flash.type = 'Error!'

Check warning on line 18 in src/backend/routes/views/account/get/connectSteam.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/get/connectSteam.js#L16-L18

Added lines #L16 - L18 were not covered by tests

return overallRes.render('account/linkSteam', { flash })

Check warning on line 20 in src/backend/routes/views/account/get/connectSteam.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/get/connectSteam.js#L20

Added line #L20 was not covered by tests
}
// Must not be valid, check to see if errors, otherwise return generic error.
try {
body = JSON.parse(body)

Check warning on line 24 in src/backend/routes/views/account/get/connectSteam.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/get/connectSteam.js#L23-L24

Added lines #L23 - L24 were not covered by tests

Expand Down
2 changes: 1 addition & 1 deletion src/backend/routes/views/account/get/linkGog.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ exports = module.exports = function (req, res) {
form: {}
}, function (err, res, body) {
locals.gogToken = 'unable to obtain token'

Check warning on line 33 in src/backend/routes/views/account/get/linkGog.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/get/linkGog.js#L32-L33

Added lines #L32 - L33 were not covered by tests
if (res === undefined || res.statusCode !== 200) {
if (err || res.statusCode !== 200) {
flash = {}
error.parseApiErrors(body, flash)
return overallRes.render('account/linkGog', { flash })

Check warning on line 37 in src/backend/routes/views/account/get/linkGog.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/get/linkGog.js#L35-L37

Added lines #L35 - L37 were not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ exports = module.exports = async function (req, res) {
recaptchaSiteKey: appConfig.recaptchaKey
})
}).catch(error => {
console.error(error.toString())
res.render('account/requestPasswordReset', {
section: 'account',
flash: {
Expand Down
2 changes: 1 addition & 1 deletion src/backend/routes/views/account/get/resync.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports = module.exports = function (req, res) {
url: process.env.API_URL + '/users/resyncAccount',
headers: { Authorization: 'Bearer ' + req.services.userService.getUser()?.oAuthPassport.token }
}, function (err, res, body) {

Check warning on line 19 in src/backend/routes/views/account/get/resync.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/get/resync.js#L19

Added line #L19 was not covered by tests
if (res.statusCode !== 200) {
if (err || res.statusCode !== 200) {
error.parseApiErrors(body, flash)

Check warning on line 21 in src/backend/routes/views/account/get/resync.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/get/resync.js#L21

Added line #L21 was not covered by tests
} else {
// Successfully account resync
Expand Down
2 changes: 1 addition & 1 deletion src/backend/routes/views/account/post/activate.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ exports = module.exports = function (req, res) {
url: process.env.API_URL + '/users/activate',
form: { password, token }
}, function (err, res, body) {

Check warning on line 38 in src/backend/routes/views/account/post/activate.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/post/activate.js#L38

Added line #L38 was not covered by tests
if (res.statusCode !== 200) {
if (err || res.statusCode !== 200) {
error.parseApiErrors(body, flash)
return overallRes.render('account/activate', { flash })

Check warning on line 41 in src/backend/routes/views/account/post/activate.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/post/activate.js#L40-L41

Added lines #L40 - L41 were not covered by tests
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/routes/views/account/post/changeEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ exports = module.exports = function (req, res) {
headers: { Authorization: `Bearer ${req.services.userService.getUser()?.oAuthPassport.token}` },
form: { newEmail: email, currentPassword: password }
}, function (err, res, body) {

Check warning on line 38 in src/backend/routes/views/account/post/changeEmail.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/post/changeEmail.js#L38

Added line #L38 was not covered by tests
if (res.statusCode !== 200) {
if (err || res.statusCode !== 200) {
error.parseApiErrors(body, flash)
return overallRes.render('account/changeEmail', { flash })

Check warning on line 41 in src/backend/routes/views/account/post/changeEmail.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/post/changeEmail.js#L40-L41

Added lines #L40 - L41 were not covered by tests
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/routes/views/account/post/changePassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports = module.exports = function (req, res) {
headers: { Authorization: 'Bearer ' + req.services.userService.getUser()?.oAuthPassport.token },
form: { name: username, currentPassword: oldPassword, newPassword }
}, function (err, res, body) {

Check warning on line 44 in src/backend/routes/views/account/post/changePassword.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/post/changePassword.js#L44

Added line #L44 was not covered by tests
if (res.statusCode !== 200) {
if (err || res.statusCode !== 200) {
error.parseApiErrors(body, flash)
return overallRes.render('account/changePassword', { flash })

Check warning on line 47 in src/backend/routes/views/account/post/changePassword.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/post/changePassword.js#L46-L47

Added lines #L46 - L47 were not covered by tests
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/routes/views/account/post/changeUsername.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ exports = module.exports = function (req, res) {
headers: { Authorization: 'Bearer ' + req.services.userService.getUser()?.oAuthPassport.token },
form: { newUsername: username }
}, function (err, res, body) {

Check warning on line 36 in src/backend/routes/views/account/post/changeUsername.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/post/changeUsername.js#L36

Added line #L36 was not covered by tests
if (res.statusCode !== 200) {
if (err || res.statusCode !== 200) {
error.parseApiErrors(body, flash)
return overallRes.render('account/changeUsername', { flash })

Check warning on line 39 in src/backend/routes/views/account/post/changeUsername.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/post/changeUsername.js#L38-L39

Added lines #L38 - L39 were not covered by tests
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ exports = module.exports = function (req, res) {
url: process.env.API_URL + '/users/performPasswordReset',
form: { newPassword, token }
}, function (err, res, body) {

Check warning on line 38 in src/backend/routes/views/account/post/confirmPasswordReset.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/post/confirmPasswordReset.js#L38

Added line #L38 was not covered by tests
if (res.statusCode !== 200) {
if (err || res.statusCode !== 200) {
error.parseApiErrors(body, flash)
return overallRes.render('account/confirmPasswordReset', { flash })

Check warning on line 41 in src/backend/routes/views/account/post/confirmPasswordReset.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/post/confirmPasswordReset.js#L40-L41

Added lines #L40 - L41 were not covered by tests
}
Expand Down
4 changes: 2 additions & 2 deletions src/backend/routes/views/account/post/linkGog.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ exports = module.exports = function (req, res) {
headers: { Authorization: 'Bearer ' + req.services.userService.getUser()?.oAuthPassport.token },
form: { gogUsername }
}, function (err, res, body) {

Check warning on line 36 in src/backend/routes/views/account/post/linkGog.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/post/linkGog.js#L36

Added line #L36 was not covered by tests
if (res !== undefined && res.statusCode === 200) {
if (!err && res.statusCode === 200) {
flash.class = 'alert-success'
flash.messages = [{ msg: 'Your accounts were linked successfully.' }]
flash.type = 'Success!'

Check warning on line 40 in src/backend/routes/views/account/post/linkGog.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/post/linkGog.js#L38-L40

Added lines #L38 - L40 were not covered by tests
Expand All @@ -53,7 +53,7 @@ exports = module.exports = function (req, res) {
form: {}
}, function (err, res, body) {
locals.gogToken = 'unable to obtain token'

Check warning on line 55 in src/backend/routes/views/account/post/linkGog.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/post/linkGog.js#L54-L55

Added lines #L54 - L55 were not covered by tests
if (res === undefined || res.statusCode !== 200) {
if (err || res.statusCode !== 200) {
flash = {}
error.parseApiErrors(body, flash)
return overallRes.render('account/linkGog', { flash })

Check warning on line 59 in src/backend/routes/views/account/post/linkGog.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/post/linkGog.js#L57-L59

Added lines #L57 - L59 were not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion src/backend/routes/views/account/post/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exports = module.exports = function (req, res) {
let resp
const errorMessages = []

Check warning on line 41 in src/backend/routes/views/account/post/register.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/post/register.js#L41

Added line #L41 was not covered by tests

if (res.statusCode !== 200) {
if (err || res.statusCode !== 200) {
try {
resp = JSON.parse(body)

Check warning on line 45 in src/backend/routes/views/account/post/register.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/post/register.js#L44-L45

Added lines #L44 - L45 were not covered by tests
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ exports = module.exports = function (req, res) {
url: process.env.API_URL + '/users/requestPasswordReset',
form: { identifier, recaptchaResponse }
}, function (err, res, body) {

Check warning on line 34 in src/backend/routes/views/account/post/requestPasswordReset.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/post/requestPasswordReset.js#L34

Added line #L34 was not covered by tests
if (res.statusCode !== 200) {
if (err || res.statusCode !== 200) {
error.parseApiErrors(body, flash)
return overallRes.render('account/requestPasswordReset', {

Check warning on line 37 in src/backend/routes/views/account/post/requestPasswordReset.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/account/post/requestPasswordReset.js#L36-L37

Added lines #L36 - L37 were not covered by tests
flash,
Expand Down
7 changes: 4 additions & 3 deletions src/backend/routes/views/clans/get/accept_invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ exports = module.exports = function (req, res) {
locals.clanName = clan.data.attributes.name
locals.clanLeaderName = '<unknown>'

for (k in clan.included) {
for (const k in clan.included) {
let player = null
switch (clan.included[k].type) {
case 'player':
const player = clan.included[k]
player = clan.included[k]

// Getting the leader name
if (player.id == clan.data.relationships.leader.data.id) {
if (player.id === clan.data.relationships.leader.data.id) {
locals.clanLeaderName = player.attributes.login
}

Expand Down
6 changes: 5 additions & 1 deletion src/backend/routes/views/clans/get/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ exports = module.exports = function (req, res) {
}
},
function (err, childRes, body) {
if (err) {
return res.redirect('/clans/manage')
}

const clanInfo = JSON.parse(body)
if (clanInfo.clan != null) {
res.redirect('/clans/manage')
Expand All @@ -38,7 +42,7 @@ exports = module.exports = function (req, res) {
} catch (e) {
console.error('Parsing error while trying to decode a flash error: ' + text)
console.error(e)
flasg = [{ msg: 'Unknown error' }]
flash = [{ msg: 'Unknown error' }]
}
}

Expand Down
17 changes: 10 additions & 7 deletions src/backend/routes/views/clans/get/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ exports = module.exports = function (req, res) {
return res.redirect('/clans?flash=' + data)
}

if (clan.data.relationships.leader.data.id != req.user.data.id) {
if (clan.data.relationships.leader.data.id !== req.user.data.id) {
// Not the leader! Shouldn't be able to manage stuff
res.redirect(`/clans/${req.user.data.attributes.clan.tag}?member=true`)
return
Expand All @@ -75,23 +75,26 @@ exports = module.exports = function (req, res) {
locals.clan_link = process.env.HOST + '/clans/see?id=' + clan.data.id

const members = {}
let player = null
let membership = null
let member = null

for (k in clan.included) {
for (const k in clan.included) {
switch (clan.included[k].type) {
case 'player':
const player = clan.included[k]
player = clan.included[k]
if (!members[player.id]) members[player.id] = {}
members[player.id].id = player.id
members[player.id].name = player.attributes.login

if (clan.data.relationships.founder.data.id == player.id) {
if (clan.data.relationships.founder.data.id === player.id) {
locals.founder_name = player.attributes.login
}
break

case 'clanMembership':
const membership = clan.included[k]
const member = membership.relationships.player.data
membership = clan.included[k]
member = membership.relationships.player.data
if (!members[member.id]) members[member.id] = {}
members[member.id].id = member.id
members[member.id].membershipId = membership.id
Expand All @@ -102,7 +105,7 @@ exports = module.exports = function (req, res) {

locals.clan_members = members

if (req.originalUrl == '/clan_created') {
if (req.originalUrl === '/clan_created') {
flash = {}
flash.class = 'alert-success'
flash.messages = [{ msg: 'You have successfully created your clan' }]
Expand Down
38 changes: 6 additions & 32 deletions src/backend/routes/views/clans/post/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@ const flash = {}
const request = require('request')
const { check, validationResult } = require('express-validator')

function promiseRequest (url) {
return new Promise(function (resolve, reject) {
request(url, function (error, res, body) {
if (!error && res.statusCode < 300) {
resolve(body)
} else {
reject(error)
}
})
})
}

exports = module.exports = async function (req, res) {
const locals = res.locals

Expand Down Expand Up @@ -43,24 +31,6 @@ exports = module.exports = async function (req, res) {
const clanName = req.body.clan_name
const clanTag = req.body.clan_tag
const clanDescription = req.body.clan_description
const userId = req.body.user_id

// Let's check first that the name or tag are not taken
const clanFetchRoute = process.env.API_URL + '/data/clan?filter=name=="' + clanName + '",tag=="' + clanTag + '"'
let exists = true
try {
const httpData = await promiseRequest(clanFetchRoute)
exists = JSON.parse(httpData).data.length > 0
} catch (e) {
flash.class = 'alert-danger'
flash.messages = [{ msg: 'Error while creating the clan ' + e }]
flash.type = 'Error!'

const buff = Buffer.from(JSON.stringify(flash))
const data = buff.toString('base64')

return overallRes.redirect('create?flash=' + data + '&clan_name=' + clanName + '&clan_tag=' + clanTag + '&clan_description=' + clanDescription + '')
}

const queryUrl =
process.env.API_URL +
Expand All @@ -77,10 +47,9 @@ exports = module.exports = async function (req, res) {
Authorization: 'Bearer ' + req.user.data.attributes.token
}
}, function (err, res, body) {
let resp
const errorMessages = []

if (res.statusCode !== 200) {
if (err || res.statusCode !== 200) {
let msg = 'Error while creating the clan'
try {
msg += ': ' + JSON.stringify(JSON.parse(res.body).errors[0].detail)
Expand All @@ -105,6 +74,11 @@ exports = module.exports = async function (req, res) {
}
},
function (err, res, body) {
if (err) {
console.error('There was an error updating a session after a clan creation')

return
}
try {
const user = JSON.parse(body)
user.data.attributes.token = req.user.data.attributes.token
Expand Down
20 changes: 6 additions & 14 deletions src/backend/routes/views/clans/post/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@ let flash = {}
const request = require('request')
const { check, validationResult } = require('express-validator')

function promiseRequest (url) {
return new Promise(function (resolve, reject) {
request(url, function (error, res, body) {
if (!error && res.statusCode < 300) {
resolve(body)
} else {
reject(error)
}
})
})
}

exports = module.exports = async function (req, res) {
const locals = res.locals

Expand Down Expand Up @@ -51,10 +39,9 @@ exports = module.exports = async function (req, res) {
Authorization: 'Bearer ' + req.user.data.attributes.token
}
}, function (err, res, body) {
let resp
const errorMessages = []

if (res.statusCode != 204) {
if (err || res.statusCode !== 204) {
let msg = 'Error while destroying the clan'
try {
msg += ': ' + JSON.stringify(JSON.parse(res.body).errors[0].detail)
Expand Down Expand Up @@ -87,6 +74,11 @@ exports = module.exports = async function (req, res) {
},

function (err, res, body) {
if (err) {
console.error('There was an error updating a session after a clan destruction')

return
}
try {
const user = JSON.parse(body)
user.data.id = user.data.attributes.userId
Expand Down
4 changes: 1 addition & 3 deletions src/backend/routes/views/clans/post/invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ exports = module.exports = async function (req, res) {
// Let's check first that the player exists
const fetchRoute = process.env.API_URL + '/data/player?filter=login=="' + userName + '"&fields[player]='

let exists = true
let playerData = null
let playerId = null
try {
const httpData = await promiseRequest(fetchRoute)
playerData = JSON.parse(httpData).data
exists = playerData.length > 0
playerId = playerData[0].id
} catch (e) {
flash.class = 'alert-danger'
Expand All @@ -93,7 +91,7 @@ exports = module.exports = async function (req, res) {
Authorization: 'Bearer ' + req.user.data.attributes.token
}
}, function (err, res, body) {
if (res.statusCode !== 200) {
if (err || res.statusCode !== 200) {
const errorMessages = []
let msg = 'Error while generating the invite link'
try {
Expand Down
14 changes: 12 additions & 2 deletions src/backend/routes/views/clans/post/join.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ exports = module.exports = function (req, res) {
}

const token = req.query.token
const clanId = req.query.clan_id

request.post(
{
Expand All @@ -32,8 +31,14 @@ exports = module.exports = function (req, res) {
}
},
function (err, childRes, body) {
if (err) {
console.error('There was an error at join')

return
}

let flashData
if (childRes.statusCode == 200 || childRes.statusCode == 201) {
if (childRes.statusCode === 200 || childRes.statusCode === 201) {
flash.class = 'alert-success'
flash.messages = [
{ msg: 'Welcome to your new clan!' }
Expand All @@ -51,6 +56,11 @@ exports = module.exports = function (req, res) {
},

function (err, res, body) {
if (err) {
console.error('There was an error updating a session after an user left a clan')

return
}
try {
const user = JSON.parse(body)
user.data.id = user.data.attributes.userId
Expand Down
Loading

0 comments on commit 8c497fa

Please sign in to comment.