Skip to content

Instantly share code, notes, and snippets.

@nax3t

nax3t/bugfix.md Secret

Last active May 1, 2021 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nax3t/6299773cad06a61048e996353ae8ea38 to your computer and use it in GitHub Desktop.
Save nax3t/6299773cad06a61048e996353ae8ea38 to your computer and use it in GitHub Desktop.
Bug fixes for Code with Node course

Bug 1

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;
}

Bug 2

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment