This repository was archived by the owner on Jun 2, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
backend/functions/assembly Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -314,6 +314,37 @@ 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+
317348export function removeFromCart ( cartId : string , productId : string ) : string {
318349 const cartItemId = cartId + "_" + productId ;
319350 const result = collections . remove ( consts . cartItemsCollection , cartItemId ) ;
You can’t perform that action at this time.
0 commit comments