-
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
#167727329 feat(user receives notification): user should be able edit his trip request #54
base: develop
Are you sure you want to change the base?
Conversation
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.
Apart from all those changes i pointed out, These look good to me. Thanks.
src/controllers/chatController.js
Outdated
@@ -1,4 +1,4 @@ | |||
import { chatEmitter, getChatsEmitter } from '../helpers/notificationHandler'; | |||
import { actionEmitter } from '../helpers/notificationHandler'; |
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.
Thank you very much for the effort in trying to refactor the code. but i think you should revert all these changes on the notifications the reason is because we don't have a frontend to test them with now and I'm sure you didn't test them after you change them. I can see some of the changes that will result in a bug that would need to be fixed later. Another reason is because other team members that were given this same task can understand the workflow between event emitter
and socket.io
easily. So please leave them the way they are now when we have an actual frontend platform then we can begin to start refactoring were needed to meet best practice but for now, leave them the way they are. I tested them and they are working perfectly with a frontend I created myself. It'll be a good idea to create your own notification and test if it is working as expected. Thanks
src/helpers/notificationHandler.js
Outdated
/** | ||
* @exports approvedEmitter | ||
* @exports approveTripNotification | ||
*/ | ||
|
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.
Kindly revert these changes. Thanks.
src/helpers/notificationHandler.js
Outdated
export const approvedEmitter = (data) => { | ||
tripEmitter.emit('approved trip', data); | ||
}; | ||
|
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.
Kindly revert these changes. Thanks.
src/helpers/notificationHandler.js
Outdated
@@ -33,21 +30,26 @@ export const approvedTripNotification = (io, staffs) => { | |||
}); | |||
}; | |||
|
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.
Kindly revert these changes.
src/helpers/notificationHandler.js
Outdated
*/ | ||
export const chatEmitter = (data) => { | ||
tripEmitter.emit('chat', data); | ||
}; | ||
|
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.
Kindly revert these changes. Thanks
src/helpers/notificationHandler.js
Outdated
export const getChatsEmitter = (data) => { | ||
tripEmitter.emit('chats', data); | ||
}; | ||
|
||
/** |
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.
Kindly revert these changes. Thanks.
src/middlewares/tripMiddleware.js
Outdated
@@ -3,7 +3,14 @@ import { respondWithWarning } from '../helpers/responseHandler'; | |||
import statusCode from '../helpers/statusCode'; | |||
|
|||
export const verifyTrip = async (req, res, next) => { | |||
const trip = await findTripById(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.
Kindly stick to tripId
as the parameter for trip id and use Number(req.params.tripId)
instead of parseInt(req.params.tripId, 10)
.
src/middlewares/tripMiddleware.js
Outdated
|
||
if(!Number.isInteger(id)) { | ||
return respondWithWarning(res, statusCode.resourceNotFound, 'Trip 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.
please, these changes are not needed, your validation should take care of that. Thank you.
src/routes/api/trip.routes.js
Outdated
@@ -25,6 +26,7 @@ trip.get('/:tripId', authenticateUserToken, validateTripId, verifyTrip, checkPer | |||
trip.get('/', authenticateUserToken, checkPermission('VIEW_USERS_TRIP_REQUESTS'), getAllTripRequests); | |||
trip.patch('/:tripId/reject', authenticateUserToken, validateTripId, verifyTrip, checkPermission('APPROVE_TRIP_REQUEST'), rejectTripRequest); | |||
|
|||
trip.patch('/:id/edit', authenticateUserToken, validateEditRequest, verifyTrip, verifyTripDestination, updateTripRequest); |
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.
kindly use :tripId
as the parameter. Thanks.
5c4b084
to
b28bb7c
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.
Awesome job. LGTM.
try { | ||
const [, tripRequest] = await editTripRequest(body, params.tripId, auth.id); | ||
const payload = { | ||
type: 'Trip Request edited', |
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.
why are we making the type to be a sentence
as opposed to word
. This is ambiguous and it'll make sense to use updateTrip
or tripUpdated
, depending on which you find more appropriate.
src/helpers/notificationHandler.js
Outdated
*/ | ||
|
||
export const editRequestEmitter = data => { | ||
tripEmitter.emit('edit Request', data) |
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.
Likewise this, let's use editRequest
as opposed to edit Request
src/helpers/notificationHandler.js
Outdated
const [ Roles ] = await getAllManager(); | ||
const managers = Roles.toJSON(); | ||
const { users } = managers; | ||
const managersEmail = users.map(items => items.email); |
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 iteration is not necessary. Doing this introduces an avoidable iteration (O(N)2) which reduces performance.
managersEmail.forEach(email => { | ||
io.to(staffs[email]).emit('edit Request', notification); | ||
}); | ||
}) |
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.
Rather than this
managersEmail.forEach(email => {
io.to(staffs[email]).emit('edit Request', notification);
});
,we can do this
users.forEach(({ email }) => {
io.to(staffs[email]).emit('editRequest', notification);
});
instead to reduce the number of overall iteration we have above const managersEmail = users.map(items => items.email);
src/helpers/notificationHandler.js
Outdated
|
||
const [ Roles ] = await getAllManager(); | ||
const managers = Roles.toJSON(); | ||
const { users } = managers; |
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.
const managers = Roles.toJSON();
const { users } = managers;
Can be refactored to
const { user } = Roles.toJSON();
…cation when they edit their trip request [Delivers #167727329]
b28bb7c
to
177fa69
Compare
What does this PR do?
endpoint that allow a logged in user to edit his trip request
Description of Task to be completed?
ensure that the endpoint is working
run a test on the endpoint on the endpoint
PATCH /trips/{tripId}/edit
How should this be manually tested?
after cloning the repo, cd into it directory and Run
npm run migration
npm db:seed to insert dummy data into the database
npm run start:dev to start the server
use postman to test the endpoint by:
POST /auth/siginin to login
copy return token and paste into the header in this format Bearer Token
test PATCH /trips/{tripId}/edit
What are the relevant pivotal tracker stories?
#167727329