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

#165412925 #165412925 #165412938 Users follow and unfollow each other. #53

Merged
merged 2 commits into from
Jun 10, 2019

Conversation

sengayire
Copy link
Contributor

@sengayire sengayire commented May 27, 2019

What does this PR do?

  • Allow Authors to follow and unfollow each other
  • Allow admin to register a new user
  • allow admin to update users access level
  • create CRUD endpoints for admin
  • send activation email after a successful registration

Description of Task to be completed?

creating the following endpoints:
POST /api/v1/users/follow
POST /api/v1/users/unfollow
GET /api/v1/users/followers
GET /api/v1/users/following

POST /api/v1/users/ to register new user
DELETE /api/v1/users/:id to delete a user
UPDATE /api/v1/users/:id to update a user information
GET /api/v1/users/ to fetch all users
GET /api/v1/users/:id to fetch a single user

1. Send activation link to the provided email to confirm registration
2. when user click to the activation link then account activated

How should this be manually tested?

clone the repo locally and user postman to test endpoints

Any background context you want to provide?

  • test endpoints with Mocha and Chai

What are the relevant pivotal tracker stories?

  • #165412925 # 165412938 #165412911

@sengayire sengayire changed the title Merge pull request #36 from andela/feature/paginating-articles-165412928 #165412925 Users follow and unfollow each other May 27, 2019
@sengayire sengayire force-pushed the ft-Users-follow-unfollow-165412925 branch 12 times, most recently from 8d90064 to 51c68f9 Compare May 29, 2019 14:05
@sengayire sengayire changed the title #165412925 Users follow and unfollow each other #165412925 #165412925 #165412938 Users follow and unfollow each other. May 29, 2019
* @returns {object} it return true if account verified otherwise it return false
*/
static async reset(req, res) {
return res.status(status.OK).send({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought the reset link is sent via email

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes the reset link sent via email, I added this controller to return the message when user click on link

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

if (checkUser.isActive) {
return true;
}
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this return

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean to remove return false or all of them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

@sengayire sengayire force-pushed the ft-Users-follow-unfollow-165412925 branch 13 times, most recently from 40216c9 to e374415 Compare June 6, 2019 11:14
@sengayire sengayire force-pushed the ft-Users-follow-unfollow-165412925 branch 2 times, most recently from 69f3b28 to 6f46aa0 Compare June 6, 2019 12:24
@sengayire sengayire force-pushed the ft-Users-follow-unfollow-165412925 branch 6 times, most recently from de51da0 to 30b2b35 Compare June 6, 2019 16:19
package.json Outdated
"scss": "npm-sass templates/sass/style.scss templates/css/style.css",
"db:migrate": "./node_modules/.bin/sequelize db:migrate",
"db:migrate:seed": "./node_modules/.bin/sequelize db:seed:all",
"db:seed": "./node_modules/.bin/sequelize db:seed --seed 20190605075225-permissions",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the seeding done form one file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only thing that we need to seed for now is permissions, but we can still add other seed when they are needed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's just have it as seed all and remove other seeder files.

@@ -7,11 +7,11 @@
"test": "NODE_ENV=test sequelize db:migrate:undo:all && npm run db:migrate:test && npm run db:migrate:seed:test && NODE_ENV=test nyc mocha --require @babel/register --timeout 30000 src/tests/index.js",
"cover": "npm test && nyc report --reporter=text-lcov | coveralls",
"coveralls": "cat coverage/lcov.info | coveralls",
"start": "npm run db:migrate && babel-node src/index.js",
"dev": "nodemon src/index.js --exec babel-node --presets @babel/preset-env",
"start": "concurrently \"npm run db:migrate && npm run db:seed\" \"babel-node src/index.js\"",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Copy link
Contributor Author

@sengayire sengayire Jun 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we need these because we need to run multiple commands concurrently and skip other when failing

* @param {object} res
* @returns {object} it return true if account verified otherwise it return false
*/
static async reset(req, res) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the token should be sent to user email

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes the token sent to the user email however, I added this function to return it on the body I can remove it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't be returned. Just send email.

* @param {object} res server response
* @returns {object} true
*/
static async follow(req, res) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the follow functionality under auth controller.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I am going to migrate it to user controller

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved, know the follow's functionality is located to the user file

followers: followers.map(follower => delete follower.get().followedUser && follower)
})
: res.status(status.NOT_FOUND).json({
errors: { follows: 'You do not have followers for know' }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeo. Just have it as you don't have followers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

return followers.length
? res.status(status.OK).json({
message: 'Followers',
followers: followers.map(follower => delete follower.get().followedUser && follower)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we deleting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remove the followed user here because I wont to display only the user that follows me in this controller and in the model I get both followers and following

const role = 'normal';
const findAll = await User.getAllUser({ role });
static async getAll(req, res) {
const role = req.user.role === 'normal' ? 'normal' : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should have the role check here. we have to keep them in a helper file


switch (verb) {
case 'PATCH':
console.log(URL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove console

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

@sengayire sengayire force-pushed the ft-Users-follow-unfollow-165412925 branch 2 times, most recently from 2aca6c4 to 5989bbc Compare June 7, 2019 11:50
* @return {object} return all users in database
*/
static async getAll(req, res) {
const [offset, limit] = [req.query.offset || 0, req.query.limit || 20];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these lines are not covered in tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

@sengayire sengayire force-pushed the ft-Users-follow-unfollow-165412925 branch 2 times, most recently from 3d3753a to 4e7181d Compare June 7, 2019 12:53
@sengayire sengayire force-pushed the ft-Users-follow-unfollow-165412925 branch 3 times, most recently from a413ecc to 8bf2e68 Compare June 10, 2019 09:56
@sengayire sengayire force-pushed the ft-Users-follow-unfollow-165412925 branch from 8bf2e68 to 0961e22 Compare June 10, 2019 11:36
@e-liyai e-liyai merged commit 1885c3a into develop Jun 10, 2019
@e-liyai e-liyai deleted the ft-Users-follow-unfollow-165412925 branch June 10, 2019 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants