Week 2 Exercise - Initial Commit#16
Open
bbarth86 wants to merge 1 commit intopce-uw-jscript400:masterfrom
Open
Week 2 Exercise - Initial Commit#16bbarth86 wants to merge 1 commit intopce-uw-jscript400:masterfrom
bbarth86 wants to merge 1 commit intopce-uw-jscript400:masterfrom
Conversation
bwreid
reviewed
Jul 15, 2019
| const { vegetables } = data; | ||
| const { name } = req.query; | ||
| // Filter array for vegetable objects where vegetable name contains the value provided for req.query.name | ||
| // Question: What is the best way to handle case sensitivity and quotes in the query param? Regex? |
Contributor
There was a problem hiding this comment.
A couple options for this, but here's one:
const { name: unformattedName } = req.query
const sanitized = JSON.parse(unformattedName)
const name = sanitized.toLowerCase()Then, compare to the vegetable name lowercased as well.
| const { name } = req.query; | ||
| // Filter array for vegetable objects where vegetable name contains the value provided for req.query.name | ||
| // Question: What is the best way to handle case sensitivity and quotes in the query param? Regex? | ||
| const filteredVeg = vegetables.filter(veg => veg.name.includes(name)); |
Contributor
There was a problem hiding this comment.
I would move this below to your else case. That way you skip over running this if there's no name.
| // find the index of vegetable where id matches req.params.id (again, only one match) and update name and price values using req.params. | ||
| // then return updated vegetable with 201 response code | ||
| let indexOfVeg = vegetables.findIndex(veg => veg.id === id); | ||
| vegetables[indexOfVeg] = {id: id, ...req.body} |
Contributor
There was a problem hiding this comment.
This totally works, but the instructions technically say to throw an error if all of the keys are not present.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.