-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
b6235a9
to
aa4c72c
Compare
aa4c72c
to
5b6a98b
Compare
072af82
to
c241c71
Compare
c241c71
to
ddf1851
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.
@NiyoEric Great work done! Please take note of the few changes I have pointed out.
src/controllers/TripController.js
Outdated
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 } | ||
}); | ||
}); |
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.
@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.
src/routes/api/tripRoute.js
Outdated
'/edit/:id', | ||
verifyToken, | ||
isUserVerified, | ||
Validate.isIDInteger(), | ||
checkInputDataError, | ||
Validate.editRequest(), | ||
checkInputDataError, | ||
Conflict.isTripRequestFound, | ||
IsOwnerOfTrip, | ||
IsTripApproved, | ||
ValidateTrip.checkIfOriginDestinationExists, | ||
ValidateTrip.checkIfOriginSameAsDestination, | ||
ValidateTrip.checkMultiCityForSimilarRequests, | ||
ValidateTrip.checkForSimilarRequests, | ||
TripController.editTrip | ||
); |
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.
@NiyoEric I'd recommend sticking to one convention. If you are destructuring please ensure it is destructured through and through
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.
Eric, please see the comments I have left.
src/tests/060-tripTest.js
Outdated
@@ -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'; |
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.
Eric, can you help us refactor this, superAdminToken is in mockData.
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.
Done.
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.
You can make the format of the req.body to be uniform. Nice work.
ddf1851
to
305b45e
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.
@NiyoEric you did a good job!
Just review some few comments I left.
src/controllers/TripController.js
Outdated
try { | ||
const itinerary = req.body.itinerary ? req.body.itinerary : [req.body]; | ||
const Ids = await trips.findAll( |
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.
Nice shot @NiyoEric
src/routes/api/tripRoute.js
Outdated
.put( | ||
'/edit/:id', |
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.
Can you use tripRequestId
instead of id
, so that we may all reflect on the same ID name?
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.
I have changed it.
src/routes/api/tripRoute.js
Outdated
* | ||
* /trips/edit/{id}: |
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.
tripRequestId
instead of id
305b45e
to
d3d53e4
Compare
src/services/TripService.js
Outdated
@@ -0,0 +1,53 @@ | |||
import database, { tripRequests, trips } from '../database/models'; |
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.
Parsing error: 'import' and 'export' may appear only with 'sourceType: module'
src/services/CommonQueries.js
Outdated
@@ -0,0 +1,69 @@ | |||
|
|||
import Customize from '../helpers/Customize'; |
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.
Parsing error: 'import' and 'export' may appear only with 'sourceType: module'
d3d53e4
to
5083458
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.
Looks good to go, keep it up! @NiyoEric
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.
Nice work eric
5083458
to
d3dc4e9
Compare
src/tests/060-tripTest.js
Outdated
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) |
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.
A space is required after ',' comma-spacing
src/tests/060-tripTest.js
Outdated
it('User should edit one way', (done) => { | ||
chai.request(app) | ||
.put(`/api/v1/trips/edit/${tripRequestOneWayId.id}`) | ||
.set('token',mockData.superAdminToken) |
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.
A space is required after ',' comma-spacing
src/tests/060-tripTest.js
Outdated
it('User should edit multi city', (done) => { | ||
chai.request(app) | ||
.put(`/api/v1/trips/edit/${tripRequestMulticityId.id}`) | ||
.set('token',mockData.superAdminToken) |
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.
A space is required after ',' comma-spacing
src/tests/060-tripTest.js
Outdated
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) |
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.
A space is required after ',' comma-spacing
src/tests/060-tripTest.js
Outdated
before((done) => { | ||
chai.request(app) | ||
.post('/api/v1/trips/oneway') | ||
.set('token',mockData.superAdminToken) |
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.
A space is required after ',' comma-spacing
src/services/TripService.js
Outdated
|
||
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) |
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.
Missing semicolon semi
src/services/TripService.js
Outdated
where: { | ||
tripRequestId: req.params.tripRequestId | ||
} | ||
} |
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.
Missing semicolon semi
src/services/TripService.js
Outdated
* @returns {object} either an error or data | ||
*/ | ||
|
||
static async editTripRequestToUser(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.
Missing JSDoc comment require-jsdoc
src/services/TripService.js
Outdated
@@ -0,0 +1,53 @@ | |||
import database, { tripRequests, trips } from '../database/models'; |
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.
'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'; |
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.
'trips' is defined but never used no-unused-vars
d3dc4e9
to
0babf8a
Compare
src/services/TripService.js
Outdated
}, | ||
{ | ||
where: { id: 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.
Expected a newline before ')' function-paren-newline
src/services/TripService.js
Outdated
|
||
itinerary.forEach(async (item, index) => { | ||
const tripId = getTripsIds[index].dataValues.id; | ||
await trips.update({ |
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.
Expected a newline after '(' function-paren-newline
src/services/TripService.js
Outdated
|
||
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) |
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.
Missing semicolon semi
eec4e78
to
a938bd0
Compare
src/tests/060-tripTest.js
Outdated
done(); | ||
}); | ||
}); | ||
}); |
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.
Newline required at end of file but not found eol-last
src/routes/api/tripRoute.js
Outdated
ValidateTrip.checkMultiCityForSimilarRequests, | ||
ValidateTrip.checkForSimilarRequests, | ||
ValidateTrip.checkForSimilarRequestsDateRange, | ||
returnTripController); |
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.
Expected a newline before ')' function-paren-newline
src/routes/api/tripRoute.js
Outdated
isUserVerified, | ||
TripController.getUserRequests | ||
); | ||
tripRouter.post('/twoWay', |
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.
Expected a newline after '(' function-paren-newline
src/routes/api/tripRoute.js
Outdated
checkInputDataError, | ||
ValidateTrip.checkIfOriginDestinationExists, | ||
ValidateTrip.checkIfOriginSameAsDestination, | ||
ValidateTrip.checkMultiCityForSimilarRequests, | ||
ValidateTrip.checkForSimilarRequests, | ||
ValidateTrip.checkForSimilarRequestsDateRange, | ||
TripController.requestTrip | ||
); | ||
OneWayTripController); |
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.
Expected a newline before ')' function-paren-newline
src/routes/api/tripRoute.js
Outdated
AuthenticateToken.verifyToken, | ||
Validate.requestMultiTripRules(), | ||
|
||
tripRouter.post('/oneway', |
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.
Expected a newline after '(' function-paren-newline
- api development - database verification - validation - testing api - api documentation - [Finishes #169258650]
a938bd0
to
49a9235
Compare
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
npm install
.env
file with super admin credentialsnpm run dropTables
npm run db-migrate
npm run db-seed-dev
npm run dev-start
check API in developmentnpm test
testing APIAny 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](https://user-images.githubusercontent.com/56690376/69651371-a646d000-1078-11ea-94e8-d6ecab5dcd45.png)
Edit One-way trip
![Screen Shot 2019-11-26 at 18 27 40](https://user-images.githubusercontent.com/56690376/69652530-78fb2180-107a-11ea-9c59-cdfbb2365cb1.png)
API Documentation
![Screen Shot 2019-11-27 at 23 19 09](https://user-images.githubusercontent.com/56690376/69760141-5d704380-116c-11ea-873e-b43d96b86772.png)
Questions: