-
-
Notifications
You must be signed in to change notification settings - Fork 414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add to cart api added #938
Changes from 3 commits
5583337
cb8bc54
b180010
a58a3dc
1a6c947
89ff044
8378c6b
e31271e
1d10645
884b7ab
8694dd1
f5e20ce
ec536bd
e644c8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,4 +78,29 @@ router.get("/:productSlug", async (req, res) => { | |
} | ||
}); | ||
|
||
// Route 4 - Add to Cart | ||
/** | ||
* @description Add a product to the cart | ||
* @route POST /cart/add | ||
* @access Public | ||
* @requires email (string) | ||
* @requires productId (string) | ||
* @returns Updated cart object (JSON) | ||
*/ | ||
router.post("/cart/add", async (req, res) => { | ||
try{ | ||
const {email,productId} = req.body; | ||
const response = await User.updateOne({email:email},{$push:{cart:{id:productId}}}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you defined the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const User = require("../../schema/user/UserSchema"); |
||
if(response.modifiedCount === 1){ | ||
return res.send('Product added successfully'); | ||
}else{ | ||
res.status(404).json({message:"User not Found"}) | ||
} | ||
} | ||
catch(err){ | ||
res.status(500).json({ message: "Failed to add product to cart" }); | ||
console.log(err) | ||
} | ||
}); | ||
|
||
module.exports = router; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also there are instances of
Missing semicolon.
please do fix that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you getting Errors ?