-
Notifications
You must be signed in to change notification settings - Fork 8
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
#166241006 - Listing the Users profile #40
Conversation
src/api/routes/userRouter.js
Outdated
|
||
const userRouter = Router(); | ||
const { updateProfile } = ProfilesController; | ||
const { verifyToken } = Auth; | ||
|
||
userRouter.put('/', verifyToken, validateBody('updateUser'), updateProfile); | ||
userRouter.put('/', verifyToken, check.profileOwner, validateBody('updateUser'), updateProfile); |
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.
This middleware is not necessary as token verification ensures the user exists. What can be done is to update the 404
status code in the controller to 403
.
src/middleware/checkOwner.js
Outdated
*/ | ||
static async profileOwner(req, res, next) { | ||
const { id, username } = req.user; | ||
const userFound = await User.findOne({ where: { id, username } }); |
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.
How does this verify profile ownership? It is just repeating what token verification does. You should remove it.
5e78c20
to
bc647fa
Compare
99c4189
to
7c659fc
Compare
src/api/controllers/profiles.js
Outdated
*/ | ||
static async getAllProfile(req, res) { | ||
const fetchedProfile = await User.findAll({ attributes: ['username', 'firstName', 'lastName', 'bio', 'image'] }); | ||
if (!fetchedProfile[0]) return res.status(404).send({ error: 'No Users Profiles found!' }); |
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.
This is not a client error, it should not be 404.
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.
@eliemugenzi Thanks! i'm going to fix it
96ee92d
to
70ea267
Compare
70ea267
to
115b74f
Compare
115b74f
to
de26f34
Compare
What does this PR do?
In this PR, I implemented the endpoints that help any user/client to be able to view a list of all user's profile
Description of Task to be completed?
Having the following Endpoints working:
GET /api/profiles
How should this be manually tested?
cd tesla-ah
yarn install
oryarn
sequelize db:migrate
for this command make sure that thesequelize-cli
package is installed globallyyarn dev
yarn test:local
Any background context you want to provide?
N/A
What are the relevant pivotal tracker stories?
#166241006
Screenshots (if appropriate)
N/A
Questions:
Before Code - Audace Uhiriwe
https://docs.google.com/document/d/1bWYaHMgb3SyKN9QfmD9KbeX-WeDGHjplg66l8wOdYso/edit?usp=sharing