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

#167727329 feat(user receives notification): user should be able edit his trip request #54

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

Conversation

solomonfrank
Copy link
Collaborator

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

Copy link
Collaborator

@joaquinto joaquinto left a 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.

@@ -1,4 +1,4 @@
import { chatEmitter, getChatsEmitter } from '../helpers/notificationHandler';
import { actionEmitter } from '../helpers/notificationHandler';
Copy link
Collaborator

@joaquinto joaquinto Sep 14, 2019

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

/**
* @exports approvedEmitter
* @exports approveTripNotification
*/

Copy link
Collaborator

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.

export const approvedEmitter = (data) => {
tripEmitter.emit('approved trip', data);
};

Copy link
Collaborator

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.

@@ -33,21 +30,26 @@ export const approvedTripNotification = (io, staffs) => {
});
};

Copy link
Collaborator

Choose a reason for hiding this comment

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

Kindly revert these changes.

*/
export const chatEmitter = (data) => {
tripEmitter.emit('chat', data);
};

Copy link
Collaborator

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

export const getChatsEmitter = (data) => {
tripEmitter.emit('chats', data);
};

/**
Copy link
Collaborator

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.

@@ -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);

Copy link
Collaborator

@joaquinto joaquinto Sep 14, 2019

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).


if(!Number.isInteger(id)) {
return respondWithWarning(res, statusCode.resourceNotFound, 'Trip not found');
}
Copy link
Collaborator

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.

@@ -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);
Copy link
Collaborator

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.

@solomonfrank solomonfrank force-pushed the ft-notification-on-edit-167727329 branch 3 times, most recently from 5c4b084 to b28bb7c Compare September 15, 2019 15:57
Copy link
Collaborator

@joaquinto joaquinto left a 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',
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 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.

*/

export const editRequestEmitter = data => {
tripEmitter.emit('edit Request', data)
Copy link
Contributor

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

const [ Roles ] = await getAllManager();
const managers = Roles.toJSON();
const { users } = managers;
const managersEmail = users.map(items => items.email);
Copy link
Contributor

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);
});
})
Copy link
Contributor

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);


const [ Roles ] = await getAllManager();
const managers = Roles.toJSON();
const { users } = managers;
Copy link
Contributor

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]
@solomonfrank solomonfrank force-pushed the ft-notification-on-edit-167727329 branch from b28bb7c to 177fa69 Compare September 16, 2019 13:15
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