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

#167727330 Post comment notification #39

Merged
merged 1 commit into from
Sep 11, 2019

Conversation

joaquinto
Copy link
Collaborator

@joaquinto joaquinto commented Sep 9, 2019

What does this PR do?

  • Send a notification when a user post a comment
  • Get all comments for a particular trip
  • Delete a comment

Description of Task to be completed?

  • Create Comment model
  • Create comment migration
  • Create comment seeder
  • Create comment controller
  • Create comment route
  • Create comment middleware
  • Create comment service

Any background context you want to provide?

  • Users or manager were not able to get notifications when a comment was made on the trip and they were not also able to delete their comments, Hence, this PR enables staff to get notifications when a comment has been made on a trip and users can be able to delete their comments.

How should this be manually tested?

  • clone the repo and cd into the root directory
  • create a postgresql database
  • npm install
  • npm run start:dev
  • use postman and test the following endpoints
  • POST /api/v1/trips/<:tripId>/comment
  • GET /api/v1/trips/<:tripId>/comments
  • DELETE /api/v1/trips/<:tripId>/comments/<:commentId>

What are the relevant PT stories?

(#167727330)[https://www.pivotaltracker.com/story/show/167727330]

@joaquinto joaquinto added the work in progress Waiting for a dependent branch label Sep 9, 2019
@joaquinto joaquinto force-pushed the ft-create-comment-notification-167727330 branch 5 times, most recently from 3b5beac to ddff467 Compare September 10, 2019 05:15
@joaquinto joaquinto added review needed Review this pull request and removed work in progress Waiting for a dependent branch labels Sep 10, 2019
@joaquinto joaquinto force-pushed the ft-create-comment-notification-167727330 branch 3 times, most recently from b591e47 to fc746f2 Compare September 10, 2019 15:47
@joaquinto joaquinto force-pushed the ft-create-comment-notification-167727330 branch from fc746f2 to 7f2c69f Compare September 10, 2019 15:53
Copy link
Collaborator

@orley12 orley12 left a comment

Choose a reason for hiding this comment

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

LGTM. well done bro

@joaquinto joaquinto force-pushed the ft-create-comment-notification-167727330 branch 3 times, most recently from 8e4bf02 to 23378c8 Compare September 10, 2019 19:51
const comment = await createComment(data);

// get the reason of the trip as title for the notification
const reason = await findTripById(Number(req.params.tripId));
Copy link
Contributor

Choose a reason for hiding this comment

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

the variable naming reason lacks context, tripReason seems more appropriate.

const reason = await findTripById(Number(req.params.tripId));

// check if the comment was sent from the manager or the staff
const senderRole = (Number(reason.toJSON().userId) !== req.auth.id) ? 'Manager' : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

we can destructure userId and use it in multiple places where we have reason.toJSON().userId

const { userId } = reason.toJSON();

Then Number(userId)

* @param {Object} res
* @returns {Object} response object
*/
export const getAllComment = async (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.

getComments seems more appropriate to getAllComment

*/
export const getAllComment = async (req, res) => {
try {
const comment = await getAllComments(Number(req.params.tripId));
Copy link
Contributor

Choose a reason for hiding this comment

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

If comment is an array of comments then it should be renamed comments.

export const getAllComment = async (req, res) => {
try {
const comment = await getAllComments(Number(req.params.tripId));
return !comment ? respondWithWarning(res, statusCode.resourceNotFound, 'Comments not 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 !comment is buggy. If no record is found, comment should be an empty array which is a truthy value, hence respondWithWarning(res, statusCode.resourceNotFound, 'Comments not found') will never be called.

Instead, check for !comment.length

- Add Comment model
- Add comment migration
- Add comment seeder
- Add comment controller
- Add comment route
- Add comment middleware
- Add comment service
- Add comment notification

[Finishes #167727330]
@joaquinto joaquinto force-pushed the ft-create-comment-notification-167727330 branch from 23378c8 to cb2aa68 Compare September 11, 2019 10:21
@Hector101 Hector101 merged commit 7f94953 into develop Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review needed Review this pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants