cart refactor

This commit is contained in:
2026-02-10 12:40:44 +03:30
parent 5fb1c63c4c
commit 30be5402f3
5 changed files with 49 additions and 43 deletions
+6 -6
View File
@@ -156,18 +156,18 @@ export class CartService {
/**
* Increment item quantity in cart
*/
async incrementItem(userId: string, shopId: string, foodId: string, quantity: number): Promise<Cart> {
async incrementItem(userId: string, shopId: string, variantId: string, quantity: number): Promise<Cart> {
const cart = await this.getOrCreateCart(userId, shopId);
await this.itemService.addOrIncrementItem(cart, foodId, shopId, quantity);
await this.itemService.addOrIncrementItem(cart, variantId, shopId, quantity);
return this.recalculateAndSaveCart(cart);
}
/**
* Decrement item quantity in cart by 1 (removes item if quantity reaches 0)
*/
async decrementItem(userId: string, shopId: string, foodId: string): Promise<Cart> {
async decrementItem(userId: string, shopId: string, variantId: string): Promise<Cart> {
const cart = await this.findOneOrFail(userId, shopId);
await this.itemService.decrementOrRemoveItem(cart, foodId);
await this.itemService.decrementOrRemoveItem(cart, variantId);
return this.recalculateAndSaveCart(cart);
}
@@ -187,9 +187,9 @@ export class CartService {
/**
* Remove item from cart
*/
async removeItem(userId: string, shopId: string, foodId: string): Promise<Cart> {
async removeItem(userId: string, shopId: string, variantId: string): Promise<Cart> {
const cart = await this.findOneOrFail(userId, shopId);
this.itemService.removeItemOrFail(cart, foodId);
this.itemService.removeItemOrFail(cart, variantId);
return this.recalculateAndSaveCart(cart);
}