Open
Conversation
…art for PUT /me/cart/:productId
| summary: "all brands offered in the store" | ||
| produces: | ||
| - application/json | ||
| responses: |
There was a problem hiding this comment.
no example of what it should return:
items:
$ref: '#/definitions/Brands'
| const brandId = req.params.id; | ||
| const targetBrand = brands.filter(brand => brand.id === brandId); | ||
| if (targetBrand.length === 0) { | ||
| return res.status(404).json({ error: 'Invalid brand ID' }); |
There was a problem hiding this comment.
this message is too technical, imagine you get this as web page user. Something better would be:
Suggested change
| return res.status(404).json({ error: 'Invalid brand ID' }); | |
| return res.status(404).json({ error: 'Brand not found' }); |
| const brandName = targetBrand[0].name; | ||
| const brandProducts = products.filter(product => product.categoryId === brandId) | ||
| if (brandProducts.length === 0) { | ||
| return res.status(422).json({ error: `No products found for ${brandName}` }); |
There was a problem hiding this comment.
wrong code, also, its an error that there are not product? you can just return an empty array, but its not really an error.
Check documentation for error 422
422 Unprocessable Content
| const { username, password } = req.body; | ||
| const user = users.find(user => user.login.username === username && user.login.password === password); | ||
| if (!user) { | ||
| return res.status(401).json({ error: 'Invalid login info' }); |
There was a problem hiding this comment.
if the login is incorrect, its 403 not 401. Check documentation - there's a subtle difference between the 2
| }); | ||
|
|
||
| app.get('/me/cart', verifyToken, (req, res) => { | ||
| const currentUser = users.find(user => user.login.username === req.username); |
There was a problem hiding this comment.
why are you checking this here? Shouldn't be part of your verifyToken?
| const productId = req.params.productId; | ||
| const product = products.find(product => product.id === productId); | ||
| if (!product) { | ||
| return res.status(404).json({ error: 'Invalid Product ID' }); |
|
|
||
| const existingItemIndex = user.cart.findIndex(item => item.productId === productId); | ||
| if (existingItemIndex < 0) { | ||
| return res.status(404).json({ error: 'Product not in cart' }); |
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.