-
Notifications
You must be signed in to change notification settings - Fork 0
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
[finishes #187354263]crud operations of items to a cart #62
Conversation
42590cc
to
fc58bb8
Compare
// const images: unknown = req.files; | ||
// if (images instanceof Array && images.length > 3) { | ||
// for (const image of images) { | ||
// const imageBuffer: Buffer = image.buffer; | ||
// const url = await uploadImage(imageBuffer); | ||
// productImages.push(url); | ||
// } | ||
// } else { | ||
// return res.status(400).json({ | ||
// message: 'Product should have at least 4 images', | ||
// }); | ||
// } |
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.
can you please uncomment these codes?
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.
Hey Grace,
From what I see, I believe this model might lead to duplicate data since customers could end up with multiple rows for their cart items. I suggest creating a column for product IDs as an array and a column for the total price. This way, customers can have a single entry for their cart, simplifying the data
src/controllers/cartController.ts
Outdated
const userId = (req.user as User).id; | ||
const { productId, quantity } = req.body; | ||
const existingItem = await UserProduct.findOne({ where: { userId, productId } }); | ||
if (existingItem) { |
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.
Hi Grace,
How do you make sure there's enough of the items you've put in your cart available in stock?
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.
Hey Grace,
From what I see, I believe this model might lead to duplicate data since customers could end up with multiple rows for their cart items. I suggest creating a column for product IDs as an array and a column for the total price. This way, customers can have a single entry for their cart, simplifying the data
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.
Hi Grace,
How do you make sure there's enough of the items you've put in your cart available in stock? #cartController
a78fa70
to
ebce8a8
Compare
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.
Please refactor your codes accordingly by removing all those languages that are triggering github action
src/controllers/cartController.ts
Outdated
if (missingFields.length > 0) { | ||
res.status(400).json({ | ||
ok: false, | ||
message: req.t('requiredFieldsMissing', { |
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.
seems you committed the other language John uses in his code :
ebce8a8
to
2edcea6
Compare
new file: src/controllers/cartController.ts new file: src/database/migrations/20240510102608-create-user-product.js new file: src/database/models/userProduct.ts new file: src/docs/cart.yaml new file: src/routes/cartRoute.ts modified: src/routes/index.ts pick a62f333 [finishes #187354263]crud operations of items to a cart
2edcea6
to
cfb4db2
Compare
src/controllers/cartController.ts
Outdated
export const addCartItem = async (req: Request, res: Response) => { | ||
try { | ||
const userId = (req.user as User).id; | ||
const { productId, quantity } = req.body; |
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.
why can't you pass productId as a parameter?
src/controllers/cartController.ts
Outdated
|
||
export const updateCartItem = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const { productId, quantity } = req.body; |
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.
pass it as parameter(productId)
src/controllers/cartController.ts
Outdated
try { | ||
const userId = (req.user as User).id; | ||
const productId = req.params.id; | ||
const cartItem = await UserProduct.findOne({ where: { userId, productId }, include: { model: Product } }); |
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.
we have to get also data from Size model.
Purpose
Performing crud operations on a user's cart
Describe the changes made in this pull request
Testing Instructions
No tests done
Related Issues
No issues found
Checklist
Please review the following checklist and make sure all tasks are complete before submitting: