Skip to content

Commit

Permalink
search filter
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuagoldmeier committed Jan 31, 2017
1 parent 9a7c536 commit 83a7a37
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app/components/SearchFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SearchFilter extends Component {
constructor(){
super();
this.state = {
name: -1,
artistName: -1,
options: [],
min: -1,
max: -1,
Expand Down Expand Up @@ -44,7 +44,7 @@ class SearchFilter extends Component {
if (genres && genres.length ===0) genres=-1;

var searchfilterinfo = {
name: this.state.name,
artistName: this.state.artistName,
min: this.state.min,
max: this.state.max,
location: this.state.location,
Expand Down Expand Up @@ -77,7 +77,7 @@ class SearchFilter extends Component {
<div className="container">
<div className="col-md-3">
<label>DJ Name</label>
<input onChange={(event) => this.setState({name: event.target.value})} placeholder="Enter DJ Name" type="text" />
<input onChange={(event) => this.setState({artistName: event.target.value})} placeholder="Enter DJ Name" type="text" />
</div>

<div className="col-md-3">
Expand Down
38 changes: 37 additions & 1 deletion server/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,51 @@ customProductsRoutes.delete('/:productId',function(request,response,next){

customProductsRoutes.get('/search/filter', function(request, response, next){
console.log(request.query, "FILTER ROUTE");
var filterInfo = createTheWhereObject(request.query)
console.log(filterInfo, "FILTER ROUTE");
Product.findAll({
where:request.query
where:filterInfo
})
.then(products =>{
response.json(products)
})
.catch(next);
})

function createTheWhereObject(query){
var whereObject = {};
if (query.artistName){
whereObject.artistName = {
$like: `%${query.artistName}%`
}
}
if (query.location){
whereObject.location = query.location
}
if (query.rating){
whereObject.rating = query.rating
}
if (query.max){
whereObject.price = {
$lte: query.max
}
}
if (query.min){
if(whereObject.price){
whereObject.price.$gte = query.min
}
else {
whereObject.price = {
$gte: query.min
}
}
}



return whereObject
}

module.exports = customProductsRoutes

// Epilogue will automatically create standard RESTful routes
Expand Down

0 comments on commit 83a7a37

Please sign in to comment.