Conversation
bwreid
left a comment
There was a problem hiding this comment.
Great job! For the most part, everything seems to be working as intended but there are some code quality issues and an error that is surfacing. Please take a look at my comments for more details.
| const id = req.params.id; | ||
| let vegetable = vegetables.find(veggie => veggie.id === id); | ||
|
|
||
| console.log(id); |
There was a problem hiding this comment.
Remove console.log() statements before committing!
| console.log(name); | ||
|
|
||
| myList = vegetables.filter(veggie => | ||
| veggie.name.includes(name.substring(1, req.query.name.length - 1)) |
There was a problem hiding this comment.
Interesting. I assume this was to get around the quotations. This will work but also return possibly more results than expected.
| } | ||
| vegetable.name = name; | ||
| vegetable.price = price; | ||
| res.status(201).json(vegetable); |
There was a problem hiding this comment.
Per the instructions, this should be a 200.
| next({ status: 404, message }); | ||
| } | ||
| let filtered = fruits.filter( | ||
| (x = (value, index, arr) => { |
| const message = `PUT: Could not find ${name} with ID of ${id}`; | ||
| next({ status: 404, message }); | ||
| } | ||
| vegetable.name = name; |
There was a problem hiding this comment.
I'm getting an error here of TypeError: Cannot set property 'name' of undefined. My guess is you need to return here to stop the rest of the function from executing.
| //console.log(data.vegetables); | ||
| //console.log("==========================="); | ||
| data.fruits = filtered; | ||
| //console.log(data.vegetables); |
There was a problem hiding this comment.
These kind of statements should be removed as well.
|
Thanks a lot Wes for your comments.
Definitely I'll pay attention more next time.
…On Sun, Jul 14, 2019, 6:11 PM Wes Reid ***@***.***> wrote:
***@***.**** commented on this pull request.
Great job! For the most part, everything seems to be working as intended
but there are some code quality issues and an error that is surfacing.
Please take a look at my comments for more details.
------------------------------
In app.js
<#13 (comment)>
:
> + }
+ console.log(name);
+
+ myList = vegetables.filter(veggie =>
+ veggie.name.includes(name.substring(1, req.query.name.length - 1))
+ );
+
+ res.json(myList);
+});
+/******************************************** */
+app.get("/vegetables/:id", (req, res, next) => {
+ const { vegetables } = data;
+ const id = req.params.id;
+ let vegetable = vegetables.find(veggie => veggie.id === id);
+
+ console.log(id);
Remove console.log() statements before committing!
------------------------------
In app.js
<#13 (comment)>
:
>
-app.get('/vegetables/:id', (req, res, next) => {
- const { vegetables } = data
- const { id } = req.params
- const vegetable = vegetables.find(veggie => veggie.id === id)
+ const name = req.query.name;
+
+ let myList = [];
+
+ if (!name) {
+ return res.json(vegetables);
+ }
+ console.log(name);
+
+ myList = vegetables.filter(veggie =>
+ veggie.name.includes(name.substring(1, req.query.name.length - 1))
Interesting. I assume this was to get around the quotations. This will
work but also return possibly more results than expected.
------------------------------
In app.js
<#13 (comment)>
:
> }
+ vegetable.name = name;
+ vegetable.price = price;
+ res.status(201).json(vegetable);
Per the instructions, this should be a 200.
------------------------------
In app.js
<#13 (comment)>
:
> + res.status(201).json(fruit);
+});
+/******************************************** */
+app.delete("/fruits/:id", (req, res, next) => {
+ const { fruits } = data;
+ const { id } = req.params;
+ let fruit = fruits.find(fruit => fruit.id === id);
+
+ //console.log(id);
+
+ if (!fruit) {
+ const message = `DELETE: Could not find fruit with ID of ${id}`;
+ next({ status: 404, message });
+ }
+ let filtered = fruits.filter(
+ (x = (value, index, arr) => {
What is this x = bit?
------------------------------
In app.js
<#13 (comment)>
:
> }
+ vegetable.name = name;
I'm getting an error here of TypeError: Cannot set property 'name' of
undefined. My guess is you need to return here to stop the rest of the
function from executing.
------------------------------
In app.js
<#13 (comment)>
:
> +
+ //console.log(id);
+
+ if (!fruit) {
+ const message = `DELETE: Could not find fruit with ID of ${id}`;
+ next({ status: 404, message });
+ }
+ let filtered = fruits.filter(
+ (x = (value, index, arr) => {
+ return value.id !== id;
+ })
+ );
+ //console.log(data.vegetables);
+ //console.log("===========================");
+ data.fruits = filtered;
+ //console.log(data.vegetables);
These kind of statements should be removed as well.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#13?email_source=notifications&email_token=ALYY2X2A6XYJYSNUSP3UZ4DP7PFF7A5CNFSM4H7KRPQ2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOB6L5PLI#pullrequestreview-261609389>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALYY2X5VWAB4F34ABQNMK5DP7PFF7ANCNFSM4H7KRPQQ>
.
|
No description provided.