Open /middleware/index.js
file and change:
try {
location = JSON.parse(location);
coordinates = location;
} catch(err) {
const response = await geocodingClient
.forwardGeocode({
query: location,
limit: 1
})
.send();
coordinates = response.body.features[0].geometry.coordinates;
}
to:
try {
if(typeof JSON.parse(location) === 'number') {
throw new Error;
}
location = JSON.parse(location);
coordinates = location;
} catch(err) {
const response = await geocodingClient
.forwardGeocode({
query: location,
limit: 1
})
.send();
coordinates = response.body.features[0].geometry.coordinates;
}
Open /models/post.js
file and change:
price: String,
to:
price: Number,
Open /middleware/index.js
file and change:
if (price) {
if (price.min) dbQueries.push({ price: { $gte: price.min } });
if (price.max) dbQueries.push({ price: { $lte: price.max } });
}
to:
if (price) {
if (price.min) dbQueries.push({ price: { $gte: Number(price.min) } });
if (price.max) dbQueries.push({ price: { $lte: Number(price.max) } });
}
Before running this step, please note that this will delete all of your existing posts! Open app.js and uncomment:
// const seedPosts = require('./seeds');
// seedPosts();
then run the app with node app.js
and confirm that the posts were re-seeded
Navigate to the /posts route and test the price filter, it should now be working.