Skip to content
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

Merged
merged 1 commit into from
Jun 21, 2019

Conversation

UhiriweAudace
Copy link
Contributor

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?

  • clone the repository
  • go to your terminal and then write the following command
    cd tesla-ah
  • after that try to install all dependencies that are required for this project, simply by running the following command:
    yarn install or yarn
  • Then running the server, by running the below commands:
    1. sequelize db:migrate for this command make sure that the sequelize-cli package is installed globally
    2. yarn dev
    3. After running the server, Open your postman, and then try to send a request of getting user profiles
  • for running the tests, write the below command in your terminal
    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


const userRouter = Router();
const { updateProfile } = ProfilesController;
const { verifyToken } = Auth;

userRouter.put('/', verifyToken, validateBody('updateUser'), updateProfile);
userRouter.put('/', verifyToken, check.profileOwner, validateBody('updateUser'), updateProfile);
Copy link
Contributor

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.

*/
static async profileOwner(req, res, next) {
const { id, username } = req.user;
const userFound = await User.findOne({ where: { id, username } });
Copy link
Contributor

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.

@UhiriweAudace UhiriweAudace force-pushed the ft-listing-user-profiles-166241006 branch 3 times, most recently from 5e78c20 to bc647fa Compare June 19, 2019 14:49
eliemugenzi
eliemugenzi previously approved these changes Jun 19, 2019
@UhiriweAudace UhiriweAudace force-pushed the ft-listing-user-profiles-166241006 branch 2 times, most recently from 99c4189 to 7c659fc Compare June 19, 2019 18:39
*/
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!' });
Copy link
Contributor

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.

Copy link
Contributor Author

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

@eliemugenzi eliemugenzi dismissed their stale review June 20, 2019 05:41

Changes requested

@UhiriweAudace UhiriweAudace force-pushed the ft-listing-user-profiles-166241006 branch 5 times, most recently from 96ee92d to 70ea267 Compare June 20, 2019 11:53
@UhiriweAudace UhiriweAudace force-pushed the ft-listing-user-profiles-166241006 branch from 70ea267 to 115b74f Compare June 21, 2019 08:24
@UhiriweAudace UhiriweAudace force-pushed the ft-listing-user-profiles-166241006 branch from 115b74f to de26f34 Compare June 21, 2019 08:39
@Quantum-35 Quantum-35 merged commit 81eb968 into develop Jun 21, 2019
@UhiriweAudace UhiriweAudace added Needs Merge Needs To merge Merged this is for the merged branch and removed Needs Review Needs Merge Needs To merge labels Jun 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Merged this is for the merged branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants