-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First merge if Backend branch vs v.2.x #22
Open
martacolombas
wants to merge
29
commits into
v.2.x
Choose a base branch
from
backend
base: v.2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
8dfee0f
feat: added routes and queries in be
martacolombas 1c6c27f
Merge branch 'master' of https://github.com/martacolombas/gitrank int…
martacolombas 08a679f
Merge branch 'master' of https://github.com/martacolombas/gitrank int…
martacolombas 051bc60
fix: server is connected to db
martacolombas 4d53feb
merge from master
martacolombas 43ad358
feat: added router in be
martacolombas b60baa7
feat: added queries with promise handling
martacolombas 60fc209
feat: added error handling in BE API
martacolombas 442731c
Merge branch 'master' of https://github.com/martacolombas/gitrank int…
martacolombas 2ae910a
feat: added routes folder in server
martacolombas b834e05
Merge branch 'master' of https://github.com/martacolombas/gitrank int…
martacolombas 26b0764
Merge branch 'master' of https://github.com/martacolombas/gitrank int…
martacolombas be9fdce
fix: sorted prs pinned and not pinned
martacolombas 657c5f7
chore: organized server files into new, well named, folders
martacolombas 43c044a
chore: removed unnecessary logs
martacolombas 89cf812
feat: connected to mongodb
martacolombas 71f9ce4
feat: Added React Router in frount end
martacolombas 3513793
feat: added oauth routes with redirection
martacolombas d760a02
feat: added PrivateRoute
martacolombas 5490e7e
feat: refreshes token after logout
martacolombas b0c97f5
feat: update temporary token
martacolombas 48e5911
chore: deleted unnecessary routes
martacolombas 8f2f509
fix: removed debugger ...
martacolombas b6e5e6e
Merge branch 'master' of https://github.com/martacolombas/gitrank int…
martacolombas 1cf184a
feat: added modifications required as per the review in PR First merg…
martacolombas f89f0ca
fix: mongoose methods updated to comply with upciming deprecations of…
martacolombas 071d978
chore: removed unnecessary endpoints
martacolombas cb8c7e8
feat: Added Redirect to Dashboard when homepage is accessed with cred…
martacolombas 5361434
chore: removed unnecessary dependencies
martacolombas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
chore: organized server files into new, well named, folders
- Loading branch information
commit 657c5f70110d6b1c5bef0d6e0986252990e73510
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,117 @@ | ||||||
const pool = require('../db'); | ||||||
pool.connect(); | ||||||
|
||||||
const getUsers = async (request, response) => { | ||||||
try { | ||||||
const { rows } = await pool.query('SELECT * FROM users ORDER BY id ASC'); | ||||||
response.status(200).send(rows); | ||||||
} catch (error) { | ||||||
response.status(500); | ||||||
console.error(`Error ${error} occurred`); | ||||||
} | ||||||
}; | ||||||
|
||||||
const getUserById = async (request, response) => { | ||||||
try { | ||||||
const id = parseInt(request.params.id); | ||||||
if (id) { | ||||||
const { rows } = await pool.query('SELECT * FROM users WHERE id=$1', [ | ||||||
id, | ||||||
]); | ||||||
response.status(200).send(rows[0]); | ||||||
} else { | ||||||
response.status(204); | ||||||
console.log(`Couldn't find ${id}`); | ||||||
} | ||||||
} catch (error) { | ||||||
response.status(500); | ||||||
console.error(`Error ${error} occurred`); | ||||||
} | ||||||
}; | ||||||
|
||||||
const createUser = async (request, response) => { | ||||||
try { | ||||||
const { username, password, token } = request.body; | ||||||
const { | ||||||
rows, | ||||||
} = await pool.query( | ||||||
'INSERT INTO users (username, password, token) VALUES ($1, $2, $3) RETURNING *', | ||||||
[username, password, token] | ||||||
); | ||||||
response.status(201).send(rows[0]); | ||||||
} catch (error) { | ||||||
response.status(500); | ||||||
console.error(`Error ${error} occurred`); | ||||||
} | ||||||
}; | ||||||
|
||||||
const updateUserToken = async (request, response) => { | ||||||
try { | ||||||
const id = parseInt(request.params.id); | ||||||
if (id) { | ||||||
const { token } = request.body; | ||||||
const { | ||||||
rows, | ||||||
} = await pool.query( | ||||||
'UPDATE users SET token=$1 WHERE id = $2 RETURNING *', | ||||||
[token, id] | ||||||
); | ||||||
response.status(201).send(rows); | ||||||
} else { | ||||||
response.status(204); | ||||||
console.log(`Couldn't find ${id}`); | ||||||
} | ||||||
} catch (error) { | ||||||
response.status(500); | ||||||
console.error(`Error ${error} occurred`); | ||||||
} | ||||||
}; | ||||||
|
||||||
const updateUserPassword = async (request, response) => { | ||||||
try { | ||||||
const id = parseInt(request.params.id); | ||||||
if (id) { | ||||||
const { password } = request.body; | ||||||
const { | ||||||
rows, | ||||||
} = await pool.query( | ||||||
'UPDATE users SET password=$1 WHERE id = $2 RETURNING *', | ||||||
[password, id] | ||||||
); | ||||||
response.status(201).send(rows); | ||||||
} else { | ||||||
response.status(204); | ||||||
console.log(`Couldn't find ${id}`); | ||||||
} | ||||||
} catch (error) { | ||||||
response.status(500); | ||||||
console.error(`Error ${error} occurred`); | ||||||
} | ||||||
}; | ||||||
|
||||||
const deleteUser = async (request, response) => { | ||||||
try { | ||||||
const id = parseInt(request.params.id); | ||||||
if (id) { | ||||||
const { rows } = await pool.query('DELETE FROM users WHERE id = $1', [ | ||||||
id, | ||||||
]); | ||||||
response.status(201).send(rows); | ||||||
} else { | ||||||
response.status(204); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
console.log(`Couldn't find ${id}`); | ||||||
} | ||||||
} catch (error) { | ||||||
response.status(500); | ||||||
console.error(`Error ${error} occurred`); | ||||||
} | ||||||
}; | ||||||
|
||||||
module.exports = { | ||||||
getUsers, | ||||||
getUserById, | ||||||
createUser, | ||||||
updateUserToken, | ||||||
updateUserPassword, | ||||||
deleteUser, | ||||||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's important to send the error message to the response in order to give context to the API client.