Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Commit dba4694

Browse files
author
Steph Dietz
committed
take 3 adding item ID to cart object
1 parent 01cf0d6 commit dba4694

File tree

2 files changed

+5
-35
lines changed

2 files changed

+5
-35
lines changed

backend/functions/assembly/crud.ts

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -314,37 +314,6 @@ export function addToCart(cartId: string, productId: string): string {
314314
return "success";
315315
}
316316

317-
export function decreaseQuantity(cartId: string, productId: string): string {
318-
const cartItemId = cartId + "_" + productId;
319-
const cartItemQuantity = collections.getText(
320-
consts.cartItemsCollection,
321-
cartItemId,
322-
);
323-
324-
if (cartItemQuantity === null || cartItemQuantity === "") {
325-
console.log("Failed to retrieve cart item quantity for:");
326-
return "error";
327-
}
328-
329-
const newQuantity = parseFloat(cartItemQuantity) - 1;
330-
if (newQuantity === 0) {
331-
return removeFromCart(cartId, productId);
332-
}
333-
334-
const upsertQuantityResult = collections.upsert(
335-
consts.cartItemsCollection,
336-
cartItemId,
337-
newQuantity.toString(),
338-
);
339-
340-
if (!upsertQuantityResult.isSuccessful) {
341-
console.log("Failed to update quantity:");
342-
return upsertQuantityResult.error;
343-
}
344-
345-
return "success";
346-
}
347-
348317
export function removeFromCart(cartId: string, productId: string): string {
349318
const cartItemId = cartId + "_" + productId;
350319
const result = collections.remove(consts.cartItemsCollection, cartItemId);
@@ -361,15 +330,16 @@ export function getCart(cartId: string): Cart {
361330
const cartItems = cartItemIds.split(",");
362331
const items = new Array<CartItemObject>();
363332
for (let i = 0; i < cartItems.length; i++) {
333+
const cartItemID = cartItems[i];
364334
const quantity = collections.getText(
365335
consts.cartItemsCollection,
366-
cartId + "_" + cartItems[i],
336+
cartId + "_" + cartItemID,
367337
);
368-
const product = getProduct(cartItems[i]);
338+
const product = getProduct(cartItemID);
369339
const cartItemObject = new CartItemObject(
340+
cartItemID,
370341
product,
371342
parseFloat(quantity),
372-
cartItems[i],
373343
);
374344
items.push(cartItemObject);
375345
}

backend/functions/assembly/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ export class Cart {
4848
@json
4949
export class CartItemObject {
5050
constructor(
51+
public cartItemID: string,
5152
public Product: Product,
5253
public quantity: f64,
53-
public cartItemId: string,
5454
) {}
5555
}
5656

0 commit comments

Comments
 (0)