Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug #29

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading