Skip to content

Commit

Permalink
updating for JSLint compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronhmiller committed Jan 1, 2023
1 parent a0276ea commit 7cf8c38
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions app/apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const getUsers = (req, res) => {
if (error) {
throw error
}
if (results.rows == 0) {
res.status(200).send(`No users exist.`)
if (results.rows.length < 1) {
res.status(404).send('No users exist.')
} else {
res.status(200).json(results.rows)
}
Expand All @@ -26,8 +26,8 @@ const getUserById = (req, res) => {
if (error) {
throw error
}
if (results.rows == 0) {
res.status(200).send(`User cannot be retrieved as that ID does not exist.`)
if (results.rows.length < 1) {
res.status(404).send('User cannot be retrieved as that ID does not exist.')
} else {
res.status(200).json(results.rows)
}
Expand Down Expand Up @@ -60,13 +60,13 @@ const updateUser = (req, res) => {
if (error) {
throw error
}
if (results.rows == 0) {
res.status(200).send(`User cannot be updated because that ID does not exist.`)
if (results.rows.length < 1) {
res.status(404).send('User cannot be updated because that ID does not exist.')
} else {
if (!name && !email) {
res.status(400).send(`Either name and/or email must be sent.`)
res.status(400).send('Either name and/or email must be sent.')
} else if (!name) {
pool.query('UPDATE users SET email = $1 WHERE id = $2',[email, id], (error) => {
pool.query('UPDATE users SET email = $1 WHERE id = $2', [email, id], (error) => {
if (error) {
throw error
}
Expand Down Expand Up @@ -98,8 +98,8 @@ const deleteUser = (req, res) => {
if (error) {
throw error
}
if (results.rows == 0) {
res.status(200).send(`User cannot be deleted because that ID does not exist.`)
if (results.rows.length < 1) {
res.status(404).send('User cannot be deleted because that ID does not exist.')
} else {
pool.query('DELETE FROM users WHERE id = $1', [id], (error) => {
if (error) {
Expand Down
2 changes: 1 addition & 1 deletion app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ app.get('/healthcheck', (req, res) => {
})

app.get('/uptime', (req, res) => {
res.json({ uptime: 'crud-app has been running for ' + Math.floor(Math.floor(Math.floor(process.uptime())/3600)/24) + ' days.' })
res.json({ uptime: 'crud-app has been running for ' + Math.floor(Math.floor(Math.floor(process.uptime()) / 3600) / 24) + ' days.' })
})

const exitHandlerHttp = terminate(httpServer, {
Expand Down
4 changes: 2 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"express": "^4.17.2",
"pg": "^8.7.1",
"express": "^4.18.2",
"pg": "^8.8.0",
"standard": "^16.0.4"
},
"name": "crud-app",
Expand Down
4 changes: 2 additions & 2 deletions app/terminate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ function terminate (server, options = { coredump: false, timeout: 500 }) {

return (code, reason) => (err, promise) => {
if (err && err instanceof Error) {
// Log error information, use a proper logging library here :)
console.log(err.message, err.stack)
// Log error information
console.log(err.message, err.stack)
}

// Attempt a graceful shutdown
Expand Down

0 comments on commit 7cf8c38

Please sign in to comment.