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

#169258648 User can search trip requests by preference #53

Merged
merged 1 commit into from
Dec 12, 2019

Conversation

nziokaivy
Copy link
Contributor

@nziokaivy nziokaivy commented Dec 11, 2019

What does this PR do?

As a user, I should be able to use the search component so, I can easily retrieve records from both the request and approval table

Description of Task to be completed?

  • Add tests
  • Add verify token and is verified validation
  • Add validate query parameters validation middleware
  • Add search query parameter query function
  • Add search controller
  • Add route API documentation

How should this be manually tested?

  • Clone this repository using the command: git clone https://github.com/andela/team-odd-bn-backend.git
  • Checkout to this branch using the command: git checkout ft-search-functionality-169258648
  • Run the application using the command: npm run dev-start
  • Run the tests using the command: npm test

Any background context you want to provide?

As requests and approval tables grow, it should be easy to find requests through the search functionality

What are the relevant pivotal tracker stories?

#169258648

Screenshots (if appropriate)

Search by originId

image

Search by destinationId

image

Search by trip type

image

Search by status

image

Search by trip owner(by their first name)

image

Questions:

src/services/commonSearchQueries.js Show resolved Hide resolved
src/services/SearchService.js Outdated Show resolved Hide resolved
src/routes/api/searchRoute.js Outdated Show resolved Hide resolved
src/middlewares/validateSearchQueries.js Show resolved Hide resolved
src/middlewares/SearchMiddleware.js Show resolved Hide resolved
src/controllers/SearchController.js Show resolved Hide resolved
@nziokaivy nziokaivy force-pushed the ft-search-functionality-169258648 branch from 1fb90f3 to 2a7355a Compare December 12, 2019 09:31
@nziokaivy nziokaivy added Ready for review Task is done. It is ready to be reviewed and removed work in progress labels Dec 12, 2019
src/services/commonSearchQueries.js Outdated Show resolved Hide resolved
@nziokaivy nziokaivy force-pushed the ft-search-functionality-169258648 branch 3 times, most recently from 4581f9f to fb4014a Compare December 12, 2019 14:10
@ivymwende ivymwende added feedback implemented and removed Ready for review Task is done. It is ready to be reviewed labels Dec 12, 2019
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 job @ivymwende , I left a comment, please view it and we will be good to go.

return Response.errorMessage(req, res, 'You provided an invalid search query key(s) parameter.Your search key should be either originId, destinationId, startDate, returnDate, firstName, status, or tripType', 400);
}

if (query.originId === '' || query.destinationId === '' || query.startDate === '' || query.returnDate === '' || query.firstName === '' || query.tripType === '') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @ivymwende , lets make this line shorter ie

 if (query.originId === '' || query.destinationId === '' 
      || query.startDate === '' || query.returnDate === '' 
       || query.firstName === '' || query.tripType === ''
)

});


export default query;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wow! this file looks nice.

- Add tests
- Add verify token validation
- Add user is verified validation
- Add validate query parameters validation middleware
- Add search query parameter query function
- Add search controller
- Add route API documentation

[Finishes #169258648]
@nziokaivy nziokaivy force-pushed the ft-search-functionality-169258648 branch from fb4014a to 1988f65 Compare December 12, 2019 14:19
Comment on lines +19 to +21
const searchingTrips = await CommonQueries.findAll(
trips, commonSearchQueries(query, req.user.id)
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wonderful nested queries! That's great.

Comment on lines +7 to +29
const query = (searchQueryParams, id) => ({
where: {
...searchQueryParams.startDate && {
startDate: {
[Op.iLike]: `%${searchQueryParams.startDate.trim()}%`
}
},
...searchQueryParams.returnDate && {
returnDate: {
[Op.iLike]: `%${searchQueryParams.returnDate.trim()}%`
}
},
...searchQueryParams.originId && {
originId: {
[Op.eq]: parseInt((searchQueryParams.originId), 10)
}
},
...searchQueryParams.destinationId && {
destinationId: {
[Op.eq]: parseInt((searchQueryParams.destinationId), 10)
}
},
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like the way you come up with this queries.

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.

Great Job @nziokaivy. I have lost a mistake that you might have done.

@julietezekwe julietezekwe merged commit bff2dfe into develop Dec 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants