diff --git a/server/src/controllers/order.controller.js b/server/src/controllers/order.controller.js index 12da4a0..574898e 100644 --- a/server/src/controllers/order.controller.js +++ b/server/src/controllers/order.controller.js @@ -323,7 +323,7 @@ class OrderController { const order = await Order.findAll({ where: { user_id: user_id, status: StatusOrder.PENDING }, include: [ - Tour, OrderItem + OrderItem ] }) @@ -344,19 +344,22 @@ class OrderController { try { const user_id = req.params.user_id; - const order = await Order.findAll({ - where: { user_id: user_id, status: StatusOrder.COMPLETE }, + const orders = await Order.findAll({ + where: { + user_id: user_id, + status: StatusOrder.COMPLETE + }, include: [{ model: OrderItem }] }); - if (!order) + if (!orders) return res.status(404).json({ message: "You haven't complete order"}) return res.status(200).json({ message: "Get complete order successfully!", - complete_orders: order + complete_orders: orders }) } catch(error) { return res.status(500).json({ message: error.message }) diff --git a/server/src/controllers/payment.controller.js b/server/src/controllers/payment.controller.js index 2b670a5..33d877b 100644 --- a/server/src/controllers/payment.controller.js +++ b/server/src/controllers/payment.controller.js @@ -159,7 +159,6 @@ class PaymentController { // update current_customers & booked_number tour const listOrderItems = await OrderItem.findAll({ where: { order_id: order.order_id } }); - console.log("1", listOrderItems) for (const orderItem of listOrderItems) { console.log("orderItem.is_updated_slot", orderItem.is_updated_slot) if (orderItem.is_updated_slot == 0) { @@ -172,15 +171,10 @@ class PaymentController { redisClient.del("online_tours") } else continue - } - - // remove tour from cart - await OrderItem.destroy({ - where: { - id: { [Op.in]: listOrderItems.map(orderItem => orderItem.id)} - } - }) + await orderItem.update({ cart_id: null }); + } + return res.status(200).json({ RspCode: '00', Message: 'You pay for order successfully!' }); } else { // convert status of order ---> FAILED