clear cart
This commit is contained in:
@@ -83,6 +83,13 @@ export class CartController {
|
|||||||
return this.cartService.removeItem(userId, restaurantId, foodId);
|
return this.cartService.removeItem(userId, restaurantId, foodId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Delete()
|
||||||
|
@ApiOperation({ summary: 'Clear entire cart' })
|
||||||
|
@ApiResponse({ status: 200, description: 'Cart cleared successfully' })
|
||||||
|
async clearCart(@UserId() userId: string, @RestId() restaurantId: string) {
|
||||||
|
return this.cartService.clearCart(userId, restaurantId);
|
||||||
|
}
|
||||||
|
|
||||||
@Post('apply-coupon')
|
@Post('apply-coupon')
|
||||||
@ApiOperation({ summary: 'Apply coupon to cart' })
|
@ApiOperation({ summary: 'Apply coupon to cart' })
|
||||||
@ApiBody({ type: ApplyCouponDto })
|
@ApiBody({ type: ApplyCouponDto })
|
||||||
|
|||||||
@@ -71,6 +71,10 @@ export class CartService {
|
|||||||
}
|
}
|
||||||
return cart;
|
return cart;
|
||||||
}
|
}
|
||||||
|
async findOne2(userId: string, restaurantId: string): Promise<Cart | null> {
|
||||||
|
const cart = await this.getCartByRestaurant(userId, restaurantId);
|
||||||
|
return cart;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add item to cart (increment quantity if item exists, otherwise create new)
|
* Add item to cart (increment quantity if item exists, otherwise create new)
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ export class OrdersService {
|
|||||||
private readonly paymentGatewayService: PaymentGatewayService,
|
private readonly paymentGatewayService: PaymentGatewayService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async create(userId: string, restaurantId: string): Promise<Order | { order: Order; redirectUrl: string }> {
|
async create(userId: string, restaurantId: string) {
|
||||||
|
console.log('create order', userId, restaurantId);
|
||||||
// Get cart
|
// Get cart
|
||||||
const cart = await this.cartService.findOne(userId, restaurantId);
|
const cart = await this.cartService.findOne(userId, restaurantId);
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ export class OrdersService {
|
|||||||
const validationResult = await this.validateCartForOrder(userId, restaurantId, cart);
|
const validationResult = await this.validateCartForOrder(userId, restaurantId, cart);
|
||||||
|
|
||||||
// Create order within a transaction
|
// Create order within a transaction
|
||||||
return await this.em.transactional(async em => {
|
return this.em.transactional(async em => {
|
||||||
// Create order entity
|
// Create order entity
|
||||||
const order = em.create(Order, {
|
const order = em.create(Order, {
|
||||||
user: validationResult.user,
|
user: validationResult.user,
|
||||||
@@ -76,15 +77,10 @@ export class OrdersService {
|
|||||||
// Flush all changes
|
// Flush all changes
|
||||||
await em.flush();
|
await em.flush();
|
||||||
|
|
||||||
// Clear cart from cache after successful order creation
|
|
||||||
await this.cartService.clearCart(userId, restaurantId);
|
|
||||||
|
|
||||||
// Check if payment method is online and redirect to payment gateway
|
// Check if payment method is online and redirect to payment gateway
|
||||||
if (validationResult.paymentMethod.paymentMethod.isOnline) {
|
if (validationResult.paymentMethod.paymentMethod.isOnline) {
|
||||||
const paymentRedirect = await this.paymentGatewayService.generateRedirectUrl(
|
const paymentRedirect = this.paymentGatewayService.generateRedirectUrl(order, validationResult.paymentMethod);
|
||||||
order,
|
// await this.cartService.clearCart(userId, restaurantId);
|
||||||
validationResult.paymentMethod,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Return order with redirect URL for online payment
|
// Return order with redirect URL for online payment
|
||||||
return {
|
return {
|
||||||
@@ -92,12 +88,13 @@ export class OrdersService {
|
|||||||
redirectUrl: paymentRedirect.redirectUrl,
|
redirectUrl: paymentRedirect.redirectUrl,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
// await this.cartService.clearCart(userId, restaurantId);
|
||||||
|
|
||||||
// For offline payment methods (cash on delivery, etc.), order is created and pending
|
// For offline payment methods (cash on delivery, etc.), order is created and pending
|
||||||
// Payment status will be updated when payment is confirmed
|
// Payment status will be updated when payment is confirmed
|
||||||
// TODO: Implement offline payment confirmation flow if needed
|
// TODO: Implement offline payment confirmation flow if needed
|
||||||
}
|
}
|
||||||
|
return { order };
|
||||||
return order;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user