clear cart
This commit is contained in:
@@ -83,6 +83,13 @@ export class CartController {
|
||||
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')
|
||||
@ApiOperation({ summary: 'Apply coupon to cart' })
|
||||
@ApiBody({ type: ApplyCouponDto })
|
||||
|
||||
@@ -71,6 +71,10 @@ export class CartService {
|
||||
}
|
||||
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)
|
||||
|
||||
@@ -23,7 +23,8 @@ export class OrdersService {
|
||||
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
|
||||
const cart = await this.cartService.findOne(userId, restaurantId);
|
||||
|
||||
@@ -31,7 +32,7 @@ export class OrdersService {
|
||||
const validationResult = await this.validateCartForOrder(userId, restaurantId, cart);
|
||||
|
||||
// Create order within a transaction
|
||||
return await this.em.transactional(async em => {
|
||||
return this.em.transactional(async em => {
|
||||
// Create order entity
|
||||
const order = em.create(Order, {
|
||||
user: validationResult.user,
|
||||
@@ -76,15 +77,10 @@ export class OrdersService {
|
||||
// Flush all changes
|
||||
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
|
||||
if (validationResult.paymentMethod.paymentMethod.isOnline) {
|
||||
const paymentRedirect = await this.paymentGatewayService.generateRedirectUrl(
|
||||
order,
|
||||
validationResult.paymentMethod,
|
||||
);
|
||||
const paymentRedirect = this.paymentGatewayService.generateRedirectUrl(order, validationResult.paymentMethod);
|
||||
// await this.cartService.clearCart(userId, restaurantId);
|
||||
|
||||
// Return order with redirect URL for online payment
|
||||
return {
|
||||
@@ -92,12 +88,13 @@ export class OrdersService {
|
||||
redirectUrl: paymentRedirect.redirectUrl,
|
||||
};
|
||||
} else {
|
||||
// await this.cartService.clearCart(userId, restaurantId);
|
||||
|
||||
// For offline payment methods (cash on delivery, etc.), order is created and pending
|
||||
// Payment status will be updated when payment is confirmed
|
||||
// TODO: Implement offline payment confirmation flow if needed
|
||||
}
|
||||
|
||||
return order;
|
||||
return { order };
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user