From 8c497fa0da8692cbada6a5ec28312a60f5c9548a Mon Sep 17 00:00:00 2001 From: fcaps Date: Fri, 1 Dec 2023 17:24:24 +0100 Subject: [PATCH] linter fixes --- .../routes/views/account/get/connectSteam.js | 9 ++++- .../routes/views/account/get/linkGog.js | 2 +- .../views/account/get/requestPasswordReset.js | 1 + .../routes/views/account/get/resync.js | 2 +- .../routes/views/account/post/activate.js | 2 +- .../routes/views/account/post/changeEmail.js | 2 +- .../views/account/post/changePassword.js | 2 +- .../views/account/post/changeUsername.js | 2 +- .../account/post/confirmPasswordReset.js | 2 +- .../routes/views/account/post/linkGog.js | 4 +- .../routes/views/account/post/register.js | 2 +- .../account/post/requestPasswordReset.js | 2 +- .../routes/views/clans/get/accept_invite.js | 7 ++-- src/backend/routes/views/clans/get/create.js | 6 ++- src/backend/routes/views/clans/get/manage.js | 17 +++++---- src/backend/routes/views/clans/post/create.js | 38 +++---------------- .../routes/views/clans/post/destroy.js | 20 +++------- src/backend/routes/views/clans/post/invite.js | 4 +- src/backend/routes/views/clans/post/join.js | 14 ++++++- src/backend/routes/views/clans/post/kick.js | 17 +-------- src/backend/routes/views/clans/post/leave.js | 25 ++++-------- .../routes/views/clans/post/transfer.js | 15 +++++--- src/backend/routes/views/clans/post/update.js | 10 ++--- src/backend/routes/views/news.js | 8 +--- 24 files changed, 89 insertions(+), 124 deletions(-) diff --git a/src/backend/routes/views/account/get/connectSteam.js b/src/backend/routes/views/account/get/connectSteam.js index fdffb869..4d1e2353 100644 --- a/src/backend/routes/views/account/get/connectSteam.js +++ b/src/backend/routes/views/account/get/connectSteam.js @@ -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) { - // 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!' + + return overallRes.render('account/linkSteam', { flash }) + } + // Must not be valid, check to see if errors, otherwise return generic error. try { body = JSON.parse(body) diff --git a/src/backend/routes/views/account/get/linkGog.js b/src/backend/routes/views/account/get/linkGog.js index 0d571c5f..05ab5363 100644 --- a/src/backend/routes/views/account/get/linkGog.js +++ b/src/backend/routes/views/account/get/linkGog.js @@ -31,7 +31,7 @@ exports = module.exports = function (req, res) { form: {} }, function (err, res, body) { locals.gogToken = 'unable to obtain token' - if (res === undefined || res.statusCode !== 200) { + if (err || res.statusCode !== 200) { flash = {} error.parseApiErrors(body, flash) return overallRes.render('account/linkGog', { flash }) diff --git a/src/backend/routes/views/account/get/requestPasswordReset.js b/src/backend/routes/views/account/get/requestPasswordReset.js index 10e9cc9a..fc1b9a07 100644 --- a/src/backend/routes/views/account/get/requestPasswordReset.js +++ b/src/backend/routes/views/account/get/requestPasswordReset.js @@ -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: { diff --git a/src/backend/routes/views/account/get/resync.js b/src/backend/routes/views/account/get/resync.js index 9ff2c952..a89fb287 100644 --- a/src/backend/routes/views/account/get/resync.js +++ b/src/backend/routes/views/account/get/resync.js @@ -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) { - if (res.statusCode !== 200) { + if (err || res.statusCode !== 200) { error.parseApiErrors(body, flash) } else { // Successfully account resync diff --git a/src/backend/routes/views/account/post/activate.js b/src/backend/routes/views/account/post/activate.js index f1150492..7e311276 100644 --- a/src/backend/routes/views/account/post/activate.js +++ b/src/backend/routes/views/account/post/activate.js @@ -36,7 +36,7 @@ exports = module.exports = function (req, res) { url: process.env.API_URL + '/users/activate', form: { password, token } }, function (err, res, body) { - if (res.statusCode !== 200) { + if (err || res.statusCode !== 200) { error.parseApiErrors(body, flash) return overallRes.render('account/activate', { flash }) } diff --git a/src/backend/routes/views/account/post/changeEmail.js b/src/backend/routes/views/account/post/changeEmail.js index b21cd879..2f327f37 100644 --- a/src/backend/routes/views/account/post/changeEmail.js +++ b/src/backend/routes/views/account/post/changeEmail.js @@ -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) { - if (res.statusCode !== 200) { + if (err || res.statusCode !== 200) { error.parseApiErrors(body, flash) return overallRes.render('account/changeEmail', { flash }) } diff --git a/src/backend/routes/views/account/post/changePassword.js b/src/backend/routes/views/account/post/changePassword.js index 69519864..dab8c169 100644 --- a/src/backend/routes/views/account/post/changePassword.js +++ b/src/backend/routes/views/account/post/changePassword.js @@ -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) { - if (res.statusCode !== 200) { + if (err || res.statusCode !== 200) { error.parseApiErrors(body, flash) return overallRes.render('account/changePassword', { flash }) } diff --git a/src/backend/routes/views/account/post/changeUsername.js b/src/backend/routes/views/account/post/changeUsername.js index 4b416c0a..d66db6b8 100644 --- a/src/backend/routes/views/account/post/changeUsername.js +++ b/src/backend/routes/views/account/post/changeUsername.js @@ -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) { - if (res.statusCode !== 200) { + if (err || res.statusCode !== 200) { error.parseApiErrors(body, flash) return overallRes.render('account/changeUsername', { flash }) } diff --git a/src/backend/routes/views/account/post/confirmPasswordReset.js b/src/backend/routes/views/account/post/confirmPasswordReset.js index 40649d00..52e42c94 100644 --- a/src/backend/routes/views/account/post/confirmPasswordReset.js +++ b/src/backend/routes/views/account/post/confirmPasswordReset.js @@ -36,7 +36,7 @@ exports = module.exports = function (req, res) { url: process.env.API_URL + '/users/performPasswordReset', form: { newPassword, token } }, function (err, res, body) { - if (res.statusCode !== 200) { + if (err || res.statusCode !== 200) { error.parseApiErrors(body, flash) return overallRes.render('account/confirmPasswordReset', { flash }) } diff --git a/src/backend/routes/views/account/post/linkGog.js b/src/backend/routes/views/account/post/linkGog.js index 3be8c135..31fc1c82 100644 --- a/src/backend/routes/views/account/post/linkGog.js +++ b/src/backend/routes/views/account/post/linkGog.js @@ -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) { - 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!' @@ -53,7 +53,7 @@ exports = module.exports = function (req, res) { form: {} }, function (err, res, body) { locals.gogToken = 'unable to obtain token' - if (res === undefined || res.statusCode !== 200) { + if (err || res.statusCode !== 200) { flash = {} error.parseApiErrors(body, flash) return overallRes.render('account/linkGog', { flash }) diff --git a/src/backend/routes/views/account/post/register.js b/src/backend/routes/views/account/post/register.js index 24222a41..54f337b8 100644 --- a/src/backend/routes/views/account/post/register.js +++ b/src/backend/routes/views/account/post/register.js @@ -40,7 +40,7 @@ exports = module.exports = function (req, res) { let resp const errorMessages = [] - if (res.statusCode !== 200) { + if (err || res.statusCode !== 200) { try { resp = JSON.parse(body) } catch (e) { diff --git a/src/backend/routes/views/account/post/requestPasswordReset.js b/src/backend/routes/views/account/post/requestPasswordReset.js index 4afc7f76..7ce18670 100644 --- a/src/backend/routes/views/account/post/requestPasswordReset.js +++ b/src/backend/routes/views/account/post/requestPasswordReset.js @@ -32,7 +32,7 @@ exports = module.exports = function (req, res) { url: process.env.API_URL + '/users/requestPasswordReset', form: { identifier, recaptchaResponse } }, function (err, res, body) { - if (res.statusCode !== 200) { + if (err || res.statusCode !== 200) { error.parseApiErrors(body, flash) return overallRes.render('account/requestPasswordReset', { flash, diff --git a/src/backend/routes/views/clans/get/accept_invite.js b/src/backend/routes/views/clans/get/accept_invite.js index 75d42e60..9b11368b 100644 --- a/src/backend/routes/views/clans/get/accept_invite.js +++ b/src/backend/routes/views/clans/get/accept_invite.js @@ -67,13 +67,14 @@ exports = module.exports = function (req, res) { locals.clanName = clan.data.attributes.name locals.clanLeaderName = '' - 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 } diff --git a/src/backend/routes/views/clans/get/create.js b/src/backend/routes/views/clans/get/create.js index 0a4bd43f..0b2367f1 100644 --- a/src/backend/routes/views/clans/get/create.js +++ b/src/backend/routes/views/clans/get/create.js @@ -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') @@ -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' }] } } diff --git a/src/backend/routes/views/clans/get/manage.js b/src/backend/routes/views/clans/get/manage.js index 1ba05c0f..2af57b70 100755 --- a/src/backend/routes/views/clans/get/manage.js +++ b/src/backend/routes/views/clans/get/manage.js @@ -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 @@ -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 @@ -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' }] diff --git a/src/backend/routes/views/clans/post/create.js b/src/backend/routes/views/clans/post/create.js index 9285893d..7b352590 100755 --- a/src/backend/routes/views/clans/post/create.js +++ b/src/backend/routes/views/clans/post/create.js @@ -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 @@ -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 + @@ -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) @@ -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 diff --git a/src/backend/routes/views/clans/post/destroy.js b/src/backend/routes/views/clans/post/destroy.js index 8d3fba6c..786c878c 100755 --- a/src/backend/routes/views/clans/post/destroy.js +++ b/src/backend/routes/views/clans/post/destroy.js @@ -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 @@ -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) @@ -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 diff --git a/src/backend/routes/views/clans/post/invite.js b/src/backend/routes/views/clans/post/invite.js index 24e0796e..bc6bbe5b 100644 --- a/src/backend/routes/views/clans/post/invite.js +++ b/src/backend/routes/views/clans/post/invite.js @@ -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' @@ -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 { diff --git a/src/backend/routes/views/clans/post/join.js b/src/backend/routes/views/clans/post/join.js index 7b6c4a98..936d0490 100644 --- a/src/backend/routes/views/clans/post/join.js +++ b/src/backend/routes/views/clans/post/join.js @@ -22,7 +22,6 @@ exports = module.exports = function (req, res) { } const token = req.query.token - const clanId = req.query.clan_id request.post( { @@ -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!' } @@ -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 diff --git a/src/backend/routes/views/clans/post/kick.js b/src/backend/routes/views/clans/post/kick.js index bcb0ee0f..2969228a 100755 --- a/src/backend/routes/views/clans/post/kick.js +++ b/src/backend/routes/views/clans/post/kick.js @@ -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 @@ -29,7 +17,7 @@ exports = module.exports = async function (req, res) { let errors = validationResult(req) // Should not happen normally, but you never know - if (req.body.membership_id == req.user.data.attributes.clan.membershipId) errors = [{ msg: 'You cannot kick yourself' }] + if (req.body.membership_id === req.user.clan.membershipId) errors = [{ msg: 'You cannot kick yourself' }] // Must have client side errors to fix if (!errors.isEmpty()) { @@ -56,10 +44,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 removing the member' try { msg += ': ' + JSON.stringify(JSON.parse(res.body).errors[0].detail) diff --git a/src/backend/routes/views/clans/post/leave.js b/src/backend/routes/views/clans/post/leave.js index d5cf343d..ec8fff2a 100755 --- a/src/backend/routes/views/clans/post/leave.js +++ b/src/backend/routes/views/clans/post/leave.js @@ -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 @@ -40,20 +28,16 @@ exports = module.exports = async function (req, res) { return overallRes.redirect('/clans?flash=' + data) } else { // Building update query - const membershipId = req.body.membership_id - const queryUrl = `${process.env.API_URL}/data/clanMembership/${membershipId}` - // Run post to endpoint request.delete({ - url: `${process.env.API_URL}/data/clanMembership/${req.user.data.attributes.clan.membershipId}`, + url: `${process.env.API_URL}/data/clanMembership/${req.user.clan.membershipId}`, headers: { 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 leaving the clan' try { msg += ': ' + JSON.stringify(JSON.parse(res.body).errors[0].detail) @@ -87,6 +71,11 @@ exports = module.exports = async 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 diff --git a/src/backend/routes/views/clans/post/transfer.js b/src/backend/routes/views/clans/post/transfer.js index f723ca93..9d12aa35 100755 --- a/src/backend/routes/views/clans/post/transfer.js +++ b/src/backend/routes/views/clans/post/transfer.js @@ -48,20 +48,20 @@ exports = module.exports = async function (req, res) { let playerId = null try { - if (userName === req.user.data.attributes.userName) throw 'You cannot transfer your own clan to yourself' + if (userName === req.user.data.attributes.userName) throw new Error('You cannot transfer your own clan to yourself') const httpData = await promiseRequest(fetchRoute) - clanData = JSON.parse(httpData) + const clanData = JSON.parse(httpData) const members = {} - for (k in clanData.included) { + for (const k in clanData.included) { const record = clanData.included[k] if (record.type !== 'player') continue members[record.attributes.login] = record.id } - if (!members[userName]) throw 'User does not exist or is not part of the clan' + if (!members[userName]) throw new Error('User does not exist or is not part of the clan') playerId = members[userName] } catch (e) { flash.class = 'alert-danger' @@ -104,7 +104,7 @@ exports = module.exports = async function (req, res) { 'Content-Type': 'application/vnd.api+json' } }, function (err, res, body) { - if (res.statusCode != 204) { + if (err || res.statusCode !== 204) { const errorMessages = [] let msg = 'Error during the ownership transfer' try { @@ -130,6 +130,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 transfer:', err) + + return + } try { const user = JSON.parse(body) user.data.id = user.data.attributes.userId diff --git a/src/backend/routes/views/clans/post/update.js b/src/backend/routes/views/clans/post/update.js index c99568f3..7563b64f 100644 --- a/src/backend/routes/views/clans/post/update.js +++ b/src/backend/routes/views/clans/post/update.js @@ -46,7 +46,6 @@ exports = module.exports = async function (req, res) { const oldName = req.body.original_clan_name const oldTag = req.body.original_clan_tag const clanDescription = req.body.clan_description - const userId = req.body.user_id // Is the name taken ? try { @@ -55,14 +54,14 @@ exports = module.exports = async function (req, res) { flash.class = 'alert-danger' flash.type = 'Error!' - if (oldName != newName) { + if (oldName !== newName) { const fetchRoute = process.env.API_URL + '/data/clan?filter=name=="' + encodeURIComponent(newName) + '"' const data = await promiseRequest(fetchRoute) const exists = JSON.parse(data).data.length > 0 if (exists) msg = 'This name is already taken: ' + encodeURIComponent(newName) } - if (oldTag != newTag) { + if (oldTag !== newTag) { const fetchRoute = process.env.API_URL + '/data/clan?filter=tag=="' + encodeURIComponent(newTag) + '"' const data = await promiseRequest(fetchRoute) const exists = JSON.parse(data).data.length > 0 @@ -113,11 +112,10 @@ exports = module.exports = async function (req, res) { 'Content-Type': 'application/vnd.api+json', Accept: 'application/vnd.api+json' } - }, function (err, res, body) { - let resp + }, function (err, res) { const errorMessages = [] - if (res.statusCode != 204) { + if (err || res.statusCode !== 204) { let msg = 'Error while updating the clan' try { msg += ': ' + JSON.stringify(JSON.parse(res.body).errors[0].detail) diff --git a/src/backend/routes/views/news.js b/src/backend/routes/views/news.js index 53892651..8cc2f26d 100644 --- a/src/backend/routes/views/news.js +++ b/src/backend/routes/views/news.js @@ -3,9 +3,7 @@ const router = express.Router() function getNewsArticleBySlug (articles, slug) { const [newsArticle] = articles.filter((entry) => { - if (entry.slug === slug) { - return entry - } + return entry.slug === slug }) ?? [] return newsArticle ?? null @@ -13,9 +11,7 @@ function getNewsArticleBySlug (articles, slug) { function getNewsArticleByDeprecatedSlug (articles, slug) { const [newsArticle] = articles.filter((entry) => { - if (entry.bcSlug === slug) { - return entry - } + return entry.bcSlug === slug }) ?? [] return newsArticle ?? null