Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

gracemugwanezak
Copy link
Contributor

Purpose

Performing crud operations on a user's cart

Describe the changes made in this pull request

  • Created a cartController file for defining functionality
  • Created a cartRoute file for specifying routes
  • Created a cart yaml file for documentation

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:

  • Code follows the project's coding standards
  • Changes are covered by tests
  • Documentation is updated (if applicable)
  • All tests pass

@gracemugwanezak gracemugwanezak added WIP and removed WIP labels May 10, 2024
@gracemugwanezak gracemugwanezak force-pushed the 187354263-ft-cart-crud-api branch 3 times, most recently from 42590cc to fc58bb8 Compare May 11, 2024 22:06
Comment on lines 34 to 45
// 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',
// });
// }
Copy link
Collaborator

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?

Copy link
Collaborator

@hozayves hozayves left a 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

const userId = (req.user as User).id;
const { productId, quantity } = req.body;
const existingItem = await UserProduct.findOne({ where: { userId, productId } });
if (existingItem) {
Copy link
Collaborator

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?

Copy link
Collaborator

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

Copy link
Collaborator

@hozayves hozayves left a 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

@gracemugwanezak gracemugwanezak force-pushed the 187354263-ft-cart-crud-api branch 2 times, most recently from a78fa70 to ebce8a8 Compare May 14, 2024 22:23
Copy link
Contributor

@JeanIrad JeanIrad left a 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

if (missingFields.length > 0) {
res.status(400).json({
ok: false,
message: req.t('requiredFieldsMissing', {
Copy link
Contributor

@JeanIrad JeanIrad May 15, 2024

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 :

@gracemugwanezak gracemugwanezak force-pushed the 187354263-ft-cart-crud-api branch from ebce8a8 to 2edcea6 Compare May 15, 2024 18:24
	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
@gracemugwanezak gracemugwanezak force-pushed the 187354263-ft-cart-crud-api branch from 2edcea6 to cfb4db2 Compare May 15, 2024 18:44
export const addCartItem = async (req: Request, res: Response) => {
try {
const userId = (req.user as User).id;
const { productId, quantity } = req.body;
Copy link
Collaborator

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?


export const updateCartItem = async (req: Request, res: Response): Promise<void> => {
try {
const { productId, quantity } = req.body;
Copy link
Collaborator

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)

try {
const userId = (req.user as User).id;
const productId = req.params.id;
const cartItem = await UserProduct.findOne({ where: { userId, productId }, include: { model: Product } });
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants