-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
3b5beac
to
ddff467
Compare
b591e47
to
fc746f2
Compare
fc746f2
to
7f2c69f
Compare
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.
LGTM. well done bro
8e4bf02
to
23378c8
Compare
src/controllers/commentController.js
Outdated
const comment = await createComment(data); | ||
|
||
// get the reason of the trip as title for the notification | ||
const reason = await findTripById(Number(req.params.tripId)); |
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.
the variable naming reason
lacks context, tripReason
seems more appropriate.
src/controllers/commentController.js
Outdated
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; |
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.
we can destructure userId
and use it in multiple places where we have reason.toJSON().userId
const { userId } = reason.toJSON();
Then Number(userId)
src/controllers/commentController.js
Outdated
* @param {Object} res | ||
* @returns {Object} response object | ||
*/ | ||
export const getAllComment = async (req, res) => { |
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.
getComments
seems more appropriate to getAllComment
src/controllers/commentController.js
Outdated
*/ | ||
export const getAllComment = async (req, res) => { | ||
try { | ||
const comment = await getAllComments(Number(req.params.tripId)); |
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.
If comment
is an array of comments then it should be renamed comments
.
src/controllers/commentController.js
Outdated
export const getAllComment = async (req, res) => { | ||
try { | ||
const comment = await getAllComments(Number(req.params.tripId)); | ||
return !comment ? respondWithWarning(res, statusCode.resourceNotFound, 'Comments not 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 !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]
23378c8
to
cb2aa68
Compare
What does this PR do?
Description of Task to be completed?
Any background context you want to provide?
How should this be manually tested?
npm install
npm run start:dev
/api/v1/trips/<:tripId>/comment
/api/v1/trips/<:tripId>/comments
/api/v1/trips/<:tripId>/comments/<:commentId>
What are the relevant PT stories?
(#167727330)[https://www.pivotaltracker.com/story/show/167727330]