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

#167750066 Users should be able to comment on Travel requests #27

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

oyewoas
Copy link
Collaborator

@oyewoas oyewoas commented Sep 11, 2019

What does this PR do?
This PR implements Travel request comments features

Description of tasks to be completed?

  • setup controller for user to comment on requests
  • setup route for user to comment on requests
  • setup unit test for user to comment on requests route

How should this be manually tested/checked?

  1. In your terminal, run git clone https://github.com/andela/wolfsbane-backend.git
  2. Run cd wolfsbane-backend
  3. Run git fetch origin ft-create-accommodation-facilities-167750066
  4. Run git checkout origin/ft-create-accommodation-facilities-167750066
  5. Run npm install
  6. Run npm run pre-test to run migrations and seed the database
  7. Run npm test
  8. To test using postman run npm run migrate and npm run seed to migrate and seed the database
  9. Run npm run start:dev to start the development server
  10. Open Postman and send a POST request to http://localhost:3000/api/v1/users/signin using the following details as a JSON object:
{
    "email" : "funmi1@gmail.com",
    "password" : "funmi1234"
}
  1. Copy the token property in the response object
  2. Click the Authorization tab and in the Type dropdown, choose Bearer Token, then paste the token you copied into the token input field.
  3. Go to src/database/seeders/create-6-request.js then copy any of the id values
  4. To add a comment send a POST request to http://localhost:3000/api/v1/requests/:requestId/comments , replace :requestId with the id copied in 13 above:
    Sample request:
 {
	"comment": "i need to comment"
 }

Sample response:

 {
    "status": 200,
    "message": "Comment added successfully",
    "data": {
        "id": "e94c1c79-88b0-475c-909e-6868f0793446",
        "comment": "i need to comment",
        "userId": "e71c28fd-73d8-4d92-9125-ab3d022093b9",
        "requestId": "2b770fbc-76e6-4b5a-afab-882759fd1f06",
        "updatedAt": "2019-09-11T17:45:24.699Z",
        "createdAt": "2019-09-11T17:45:24.699Z"
    }
}
  1. To get all comments on a request send a GET request to http://localhost:3000/api/v1/requests/:requestId/comments , replace :requestId with the id copied in 13 above:
    Sample response:
 {
    "status": 200,
    "message": "Comment retrieved successfully",
    "data": {
        "id": "2b770fbc-76e6-4b5a-afab-882759fd1f06",
        "comment": "i need to comment",
        "userId": "e71c28fd-73d8-4d92-9125-ab3d022093b9",
        "requestId": "2b770fbc-76e6-4b5a-afab-882759fd1f06",
        "updatedAt": "2019-09-11T17:45:24.699Z",
        "createdAt": "2019-09-11T17:45:24.699Z"
        "theUser": {
                "id": "e71c28fd-73d8-4d92-9125-ab3d022093b9",
                "firstName": "",
                "lastName": "",
                "email": "funmi1@gmail.com"
            }
    }
}
  1. To get a single comment send a GET request to http://localhost:3000/api/v1/comments/:commentId, replace :commentId with the id of one of the returned comment in 15 above:
    Sample response:
 {
    "status": 200,
    "message": "Comment retrieved successfully",
    "data": {
        "id": "2b770fbc-76e6-4b5a-afab-882759fd1f06",
        "comment": "i need to comment",
        "userId": "e71c28fd-73d8-4d92-9125-ab3d022093b9",
        "requestId": "2b770fbc-76e6-4b5a-afab-882759fd1f06",
        "updatedAt": "2019-09-11T17:45:24.699Z",
        "createdAt": "2019-09-11T17:45:24.699Z"
        "theUser": {
                "id": "e71c28fd-73d8-4d92-9125-ab3d022093b9",
                "firstName": "",
                "lastName": "",
                "email": "funmi1@gmail.com"
            }
    }
}
  1. To update a single comment send a PUT request to http://localhost:3000/api/v1/comments/:commentId, replace :commentId with the id of one of the returned comment in 15 above:
    Sample response:
 {
    "status": 200,
    "message": "Comment updated successfully",
}
  1. To delete a single comment send a DELETE request to http://localhost:3000/api/v1/comments/:commentId, replace :commentId with the id of one of the returned comment in 15 above:
    Sample response:
 {
    "status": 200,
    "message": "Comment deleted successfully",
}

Any background context you want to provide?
Make sure you drop your database tables, then run migrations and seeds again, both for test and development environments

What are the relevant pivotal tracker stories?
#167750066

@oyewoas oyewoas added the work in progress Don't review yet label Sep 11, 2019
@feobaby feobaby temporarily deployed to barefootnomad10-staging-pr-27 September 11, 2019 18:17 Inactive
@oyewoas oyewoas force-pushed the ft-travel-request-comment-167750066 branch from 1fe9620 to 280db99 Compare September 12, 2019 00:46
@oyewoas oyewoas temporarily deployed to barefootnomad10-staging-pr-27 September 12, 2019 00:46 Inactive
@oyewoas oyewoas changed the title feat(request comments): request comments #167750066 Users should be able to comment on Travel requests Sep 12, 2019
@oyewoas oyewoas force-pushed the ft-travel-request-comment-167750066 branch from 280db99 to 3d8ad23 Compare September 12, 2019 08:17
@oyewoas oyewoas temporarily deployed to barefootnomad10-staging-pr-27 September 12, 2019 08:17 Inactive
@oyewoas oyewoas force-pushed the ft-travel-request-comment-167750066 branch from 3d8ad23 to 54942f5 Compare September 12, 2019 08:18
@oyewoas oyewoas temporarily deployed to barefootnomad10-staging-pr-27 September 12, 2019 08:18 Inactive
@oyewoas oyewoas force-pushed the ft-travel-request-comment-167750066 branch from 54942f5 to b3e00d9 Compare September 12, 2019 08:21
@oyewoas oyewoas temporarily deployed to barefootnomad10-staging-pr-27 September 12, 2019 08:21 Inactive
@oyewoas oyewoas force-pushed the ft-travel-request-comment-167750066 branch from b3e00d9 to 2980d9a Compare September 12, 2019 09:39
@oyewoas oyewoas temporarily deployed to barefootnomad10-staging-pr-27 September 12, 2019 09:40 Inactive
static async getCommentById(req, res) {
const { commentId } = req.params;
try {
const getComment = await Comments.findByPk(commentId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @oyewoas. Nice work so far. But I'd like to suggest, can we take advantage of the model relationships to fetch more details? For example, here, can we also get the user details and also the request details related to the comment?

Please check using include in Sequelize queries.

Copy link
Collaborator Author

@oyewoas oyewoas Sep 12, 2019

Choose a reason for hiding this comment

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

why do you think we need extra details apart from the comment @darasimiolaifa

Copy link
Collaborator

Choose a reason for hiding this comment

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

Say for instance, currently, what you're going to send to the frontend is the userId of the person who made the comment. But the frontend needs more than that. It needs the firstName, and lastname of the person, because that is what will be displayed. So, rather than send the userId, and then discover later that you still need to make another round trip to the database to fetch the user details, you can do it in one full query sweep by using include.

import './utils/jwt.test';
import './utils/emailTemplatesFunction.test';
import './services/autoMailer.test';
// import './controllers/users.test';
Copy link
Collaborator

Choose a reason for hiding this comment

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

You forgot to 'un-comment' these lines before pushing. Merge conflicts lurking.

@oyewoas oyewoas force-pushed the ft-travel-request-comment-167750066 branch from 2980d9a to a5f86fe Compare September 12, 2019 10:34
@oyewoas oyewoas temporarily deployed to barefootnomad10-staging-pr-27 September 12, 2019 10:34 Inactive
@oyewoas oyewoas force-pushed the ft-travel-request-comment-167750066 branch from a5f86fe to e702c80 Compare September 12, 2019 10:36
@oyewoas oyewoas temporarily deployed to barefootnomad10-staging-pr-27 September 12, 2019 10:36 Inactive
@oyewoas oyewoas force-pushed the ft-travel-request-comment-167750066 branch from e702c80 to d57ea72 Compare September 12, 2019 10:48
@oyewoas oyewoas temporarily deployed to barefootnomad10-staging-pr-27 September 12, 2019 10:48 Inactive
@oyewoas oyewoas force-pushed the ft-travel-request-comment-167750066 branch from d57ea72 to 3a2f327 Compare September 12, 2019 10:55
@oyewoas oyewoas temporarily deployed to barefootnomad10-staging-pr-27 September 12, 2019 10:55 Inactive
@oyewoas oyewoas force-pushed the ft-travel-request-comment-167750066 branch from 3a2f327 to 02b397b Compare September 15, 2019 16:14
@oyewoas oyewoas temporarily deployed to barefootnomad10-staging-pr-27 September 15, 2019 16:14 Inactive
@oyewoas oyewoas force-pushed the ft-travel-request-comment-167750066 branch from 02b397b to 6fccc41 Compare September 15, 2019 16:26
@oyewoas oyewoas temporarily deployed to barefootnomad10-staging-pr-27 September 15, 2019 16:26 Inactive
- setup controller for  user to comment on requests
- setup route for  user to comment on requests
- setup unit test for user to comment on requests route

[Delivers  #167750066]
@oyewoas oyewoas force-pushed the ft-travel-request-comment-167750066 branch from 6fccc41 to 022760d Compare September 15, 2019 17:09
@oyewoas oyewoas added review me Ready for review and removed work in progress Don't review yet labels Sep 15, 2019
@feobaby feobaby self-requested a review September 16, 2019 16:54
Copy link
Collaborator

@feobaby feobaby left a comment

Choose a reason for hiding this comment

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

Very good job @oyewoas

  • if i update, I should be able to get a response of the update, i only got a message.
  • I tried to do some security checks and I realized that anybody could get all comments/single comment, update or delete. It would be better it if its only the user that created the comment to be able to update/delete/get

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review me Ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants