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

#169258650 User should be able to edit trip request #32

Merged
merged 1 commit into from
Nov 29, 2019

Conversation

NiyoEric
Copy link
Contributor

@NiyoEric NiyoEric commented Nov 26, 2019

What does this PR do?

This PR helps users to edit the trip request

Description of Task to be completed?

Why

Sometimes, mistakes happen and the requester needs to ensure the right information about the travel request is conveyed
As a requester, I should be able to edit a request that is still open
So that, I can immediately make modifications to it and submit for approval

How should this be manually tested?

  • git clone https://github.com/andela/team-odd-bn-backend.git
  • cd team-odd-bn-backend
  • git checkout -b ft-edit-travel-request-169258650
  • npm install
  • update .env file with super admin credentials
  • Drop existing migration npm run dropTables
  • Update migration npm run db-migrate
  • Populate the seed data npm run db-seed-dev
  • npm run dev-start check API in development
  • Pass trips request id in params
  • pass trips info in body
  • npm test testing API

Any background context you want to provide?

What are the relevant pivotal tracker stories?

#169258650

Screenshots (if appropriate)

Edit Two-way trip
Screen Shot 2019-11-26 at 18 13 11

Edit One-way trip
Screen Shot 2019-11-26 at 18 27 40

API Documentation
Screen Shot 2019-11-27 at 23 19 09

Questions:

@NiyoEric NiyoEric force-pushed the ft-edit-travel-request-169258650 branch from b6235a9 to aa4c72c Compare November 26, 2019 17:31
@NiyoEric NiyoEric added the bug Something isn't working label Nov 27, 2019
@NiyoEric NiyoEric force-pushed the ft-edit-travel-request-169258650 branch from aa4c72c to 5b6a98b Compare November 27, 2019 11:52
@NiyoEric NiyoEric removed the bug Something isn't working label Nov 27, 2019
@NiyoEric NiyoEric force-pushed the ft-edit-travel-request-169258650 branch 2 times, most recently from 072af82 to c241c71 Compare November 27, 2019 21:32
@NiyoEric NiyoEric added Ready for review Task is done. It is ready to be reviewed and removed work in progress labels Nov 28, 2019
@NiyoEric NiyoEric force-pushed the ft-edit-travel-request-169258650 branch from c241c71 to ddf1851 Compare November 28, 2019 06:47
@NiyoEric NiyoEric added the bug Something isn't working label Nov 28, 2019
Copy link
Contributor

@ivymwende ivymwende left a comment

Choose a reason for hiding this comment

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

@NiyoEric Great work done! Please take note of the few changes I have pointed out.

Comment on lines 83 to 110
try {
const itinerary = req.body.itinerary ? req.body.itinerary : [req.body];
const Ids = await trips.findAll(
{
attributes: ['id'],
where: {
tripRequestId: req.params.id
}
}
);
await tripRequests.update(
{ statusId: 1 },
{ where: { id: req.params.id } }
);

itinerary.forEach(async (item, index) => {
const tripId = Ids[index].dataValues.id;
await trips.update({
originId: item.originId,
destinationId: item.destinationId,
reason: item.reason,
startDate: item.startDate,
returnDate: item.returnDate
},
{
where: { id: tripId }
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

@NiyoEric To avoid having a very bulky controller function I would recommend we refactor this. I'd recommend putting this in services to query the database.

Comment on lines 245 to 253
'/edit/:id',
verifyToken,
isUserVerified,
Validate.isIDInteger(),
checkInputDataError,
Validate.editRequest(),
checkInputDataError,
Conflict.isTripRequestFound,
IsOwnerOfTrip,
IsTripApproved,
ValidateTrip.checkIfOriginDestinationExists,
ValidateTrip.checkIfOriginSameAsDestination,
ValidateTrip.checkMultiCityForSimilarRequests,
ValidateTrip.checkForSimilarRequests,
TripController.editTrip
);
Copy link
Contributor

Choose a reason for hiding this comment

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

@NiyoEric I'd recommend sticking to one convention. If you are destructuring please ensure it is destructured through and through

Copy link
Collaborator

@hezronkimutai hezronkimutai left a comment

Choose a reason for hiding this comment

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

Eric, please see the comments I have left.

@@ -3,7 +3,7 @@ import chaiHttp from 'chai-http';
import dotenv from 'dotenv';
import app from '../index';
import tripMockData from './mock/tripMockData';
import mockData from './mock/mockData';
import mockData, { superAdminToken } from './mock/mockData';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Eric, can you help us refactor this, superAdminToken is in mockData.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Collaborator

@hezronkimutai hezronkimutai left a comment

Choose a reason for hiding this comment

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

You can make the format of the req.body to be uniform. Nice work.

@NiyoEric NiyoEric force-pushed the ft-edit-travel-request-169258650 branch from ddf1851 to 305b45e Compare November 28, 2019 10:30
Copy link
Collaborator

@victkarangwa victkarangwa left a comment

Choose a reason for hiding this comment

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

@NiyoEric you did a good job!
Just review some few comments I left.

Comment on lines 83 to 85
try {
const itinerary = req.body.itinerary ? req.body.itinerary : [req.body];
const Ids = await trips.findAll(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice shot @NiyoEric

Comment on lines 244 to 245
.put(
'/edit/:id',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you use tripRequestId instead of id, so that we may all reflect on the same ID name?

Copy link
Contributor Author

@NiyoEric NiyoEric Nov 28, 2019

Choose a reason for hiding this comment

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

I have changed it.

Comment on lines 264 to 265
*
* /trips/edit/{id}:
Copy link
Collaborator

Choose a reason for hiding this comment

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

tripRequestId instead of id

@NiyoEric NiyoEric force-pushed the ft-edit-travel-request-169258650 branch from 305b45e to d3d53e4 Compare November 28, 2019 17:17
@@ -0,0 +1,53 @@
import database, { tripRequests, trips } from '../database/models';
Copy link

Choose a reason for hiding this comment

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

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@@ -0,0 +1,69 @@

import Customize from '../helpers/Customize';
Copy link

Choose a reason for hiding this comment

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

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@NiyoEric NiyoEric removed the bug Something isn't working label Nov 28, 2019
@NiyoEric NiyoEric force-pushed the ft-edit-travel-request-169258650 branch from d3d53e4 to 5083458 Compare November 28, 2019 17:57
Copy link
Collaborator

@william000000 william000000 left a comment

Choose a reason for hiding this comment

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

Looks good to go, keep it up! @NiyoEric

Copy link
Collaborator

@hezronkimutai hezronkimutai left a comment

Choose a reason for hiding this comment

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

Nice work eric

@NiyoEric NiyoEric force-pushed the ft-edit-travel-request-169258650 branch from 5083458 to d3dc4e9 Compare November 29, 2019 06:54
it('User should not edit and send the same city', (done) => {
chai.request(app)
.put(`/api/v1/trips/edit/${tripRequestMulticityId.id}`)
.set('token',mockData.superAdminToken)
Copy link

Choose a reason for hiding this comment

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

A space is required after ',' comma-spacing

it('User should edit one way', (done) => {
chai.request(app)
.put(`/api/v1/trips/edit/${tripRequestOneWayId.id}`)
.set('token',mockData.superAdminToken)
Copy link

Choose a reason for hiding this comment

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

A space is required after ',' comma-spacing

it('User should edit multi city', (done) => {
chai.request(app)
.put(`/api/v1/trips/edit/${tripRequestMulticityId.id}`)
.set('token',mockData.superAdminToken)
Copy link

Choose a reason for hiding this comment

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

A space is required after ',' comma-spacing

it('User should be able to re-send the same multitrip', (done) => {
chai.request(app)
.put(`/api/v1/trips/edit/${tripRequestMulticityId.id}`)
.set('token',mockData.superAdminToken)
Copy link

Choose a reason for hiding this comment

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

A space is required after ',' comma-spacing

before((done) => {
chai.request(app)
.post('/api/v1/trips/oneway')
.set('token',mockData.superAdminToken)
Copy link

Choose a reason for hiding this comment

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

A space is required after ',' comma-spacing


const getTripsIds = await CommonQueries.findAll(req, res, trips, findAllObjQuery, 'Trip not found', 404);

await CommonQueries.update(req, res, tripRequests, updateStatusQuery, 'status did not update', 409)
Copy link

Choose a reason for hiding this comment

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

Missing semicolon semi

where: {
tripRequestId: req.params.tripRequestId
}
}
Copy link

Choose a reason for hiding this comment

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

Missing semicolon semi

* @returns {object} either an error or data
*/

static async editTripRequestToUser(req, res) {
Copy link

Choose a reason for hiding this comment

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

Missing JSDoc comment require-jsdoc

@@ -0,0 +1,53 @@
import database, { tripRequests, trips } from '../database/models';
Copy link

Choose a reason for hiding this comment

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

'database' is defined but never used no-unused-vars

@@ -1,8 +1,8 @@
import Customize from '../helpers/Customize';
import { tripRequests, users } from '../database/models';
import { tripRequests, users, trips } from '../database/models';
Copy link

Choose a reason for hiding this comment

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

'trips' is defined but never used no-unused-vars

@NiyoEric NiyoEric force-pushed the ft-edit-travel-request-169258650 branch from d3dc4e9 to 0babf8a Compare November 29, 2019 07:52
},
{
where: { id: tripId }
});
Copy link

Choose a reason for hiding this comment

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

Expected a newline before ')' function-paren-newline


itinerary.forEach(async (item, index) => {
const tripId = getTripsIds[index].dataValues.id;
await trips.update({
Copy link

Choose a reason for hiding this comment

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

Expected a newline after '(' function-paren-newline


const getTripsIds = await CommonQueries.findAll(req, res, trips, findAllObjQuery, 'Trip not found', 404);

await CommonQueries.update(req, res, tripRequests, updateStatusQuery, 'status did not update', 409)
Copy link

Choose a reason for hiding this comment

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

Missing semicolon semi

@NiyoEric NiyoEric force-pushed the ft-edit-travel-request-169258650 branch 5 times, most recently from eec4e78 to a938bd0 Compare November 29, 2019 16:18
done();
});
});
});
Copy link

Choose a reason for hiding this comment

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

Newline required at end of file but not found eol-last

ValidateTrip.checkMultiCityForSimilarRequests,
ValidateTrip.checkForSimilarRequests,
ValidateTrip.checkForSimilarRequestsDateRange,
returnTripController);
Copy link

Choose a reason for hiding this comment

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

Expected a newline before ')' function-paren-newline

isUserVerified,
TripController.getUserRequests
);
tripRouter.post('/twoWay',
Copy link

Choose a reason for hiding this comment

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

Expected a newline after '(' function-paren-newline

checkInputDataError,
ValidateTrip.checkIfOriginDestinationExists,
ValidateTrip.checkIfOriginSameAsDestination,
ValidateTrip.checkMultiCityForSimilarRequests,
ValidateTrip.checkForSimilarRequests,
ValidateTrip.checkForSimilarRequestsDateRange,
TripController.requestTrip
);
OneWayTripController);
Copy link

Choose a reason for hiding this comment

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

Expected a newline before ')' function-paren-newline

AuthenticateToken.verifyToken,
Validate.requestMultiTripRules(),

tripRouter.post('/oneway',
Copy link

Choose a reason for hiding this comment

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

Expected a newline after '(' function-paren-newline

- api development
- database verification
- validation
- testing api
- api documentation
- [Finishes #169258650]
@NiyoEric NiyoEric force-pushed the ft-edit-travel-request-169258650 branch from a938bd0 to 49a9235 Compare November 29, 2019 16:23
@NiyoEric NiyoEric merged commit 1032894 into develop Nov 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready for review Task is done. It is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants