Skip to content

Commit

Permalink
Merge pull request #29 from DucHuy2801/fix-bug
Browse files Browse the repository at this point in the history
Fix bug
  • Loading branch information
augustus281 authored May 22, 2024
2 parents c178403 + 9d37fee commit 3862c7f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
13 changes: 8 additions & 5 deletions server/src/controllers/order.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class OrderController {
const order = await Order.findAll({
where: { user_id: user_id, status: StatusOrder.PENDING },
include: [
Tour, OrderItem
OrderItem
]
})

Expand All @@ -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 })
Expand Down
12 changes: 3 additions & 9 deletions server/src/controllers/payment.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit 3862c7f

Please sign in to comment.