Skip to content

Commit

Permalink
Merge pull request #23 from DucHuy2801/fix-bug
Browse files Browse the repository at this point in the history
Add feature relate tour guide
  • Loading branch information
augustus281 authored May 18, 2024
2 parents b099266 + 9bbc858 commit 6ea3383
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 18 deletions.
1 change: 1 addition & 0 deletions server/logs/test.log
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
[2024-05-05 03:29:59.781 PM] error: 403 - Voucher is expired, you can't apply it!
[2024-05-11 10:05:06.469 PM] error: Not Found - Not found order!
[2024-05-11 03:17:35.445 PM] error: Not Found - Voucher is not found!
[2024-05-18 07:36:45.506 AM] error: 403 - Order is not completed, you can't review!
37 changes: 20 additions & 17 deletions server/src/controllers/order.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ class OrderController {
await order_item.save()

let tour = await findTourById(order_item.tour_id)
console.log("current_customers", tour.current_customers, tour.max_customer)
if (tour.current_customers >= tour.max_customer)
return res.status(400).json({ message: "Tour is full!"})

Expand Down Expand Up @@ -342,23 +341,27 @@ class OrderController {
}

getCompleteOrderByUser = async (req, res, next) => {
const user_id = req.params.user_id;

const order = await Order.findAll({
where: { user_id: user_id, status: StatusOrder.COMPLETE },
include: [
Tour, OrderItem
]
})

if (!order)
return res.status(404).json({ message: "You haven't complete order"})
try {
const user_id = req.params.user_id;

return res.status(200).json({
message: "Get complete order successfully!",
complete_orders: order
})
}
const order = await Order.findAll({
where: { user_id: user_id, status: StatusOrder.COMPLETE },
include: [{
model: OrderItem
}]
});

if (!order)
return res.status(404).json({ message: "You haven't complete order"})

return res.status(200).json({
message: "Get complete order successfully!",
complete_orders: order
})
} catch(error) {
return res.status(500).json({ message: error.message })
}
}

getFailedOrderByUser = async (req, res, next) => {
const user_id = req.params.user_id;
Expand Down
30 changes: 30 additions & 0 deletions server/src/models/guide_tour.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict'

const { DataTypes, Model } = require('sequelize');
const sequelize = require('../database/connect.mysql');
const TourGuide = require('./tour_guide.model');
const Tour = require('./tour.model');

class GuideTour extends Model {}
GuideTour.init({
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
tour_guide_id: {
type: DataTypes.INTEGER,
allowNull: true,
},
tour_id: {
type: DataTypes.INTEGER,
allowNull: true,
}
}, { sequelize, modelName: "guide_tour" })

TourGuide.belongsToMany(Tour, { through: GuideTour, foreignKey: "tour_guide_id" })
Tour.belongsToMany(TourGuide, { through: GuideTour, foreignKey: "tour_id" })

module.exports = GuideTour


2 changes: 1 addition & 1 deletion server/src/routes/tour/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ router.put("/:tour_id", formidableMiddleware(), authenticate, asyncHandler(tourC
router.put("/:tour_id/response", authenticate, asyncHandler(tourController.responseTour))
router.put("/recover/:tour_id", authenticate, asyncHandler(tourController.recoverTour))
router.patch("/:tour_id/public", authenticate, asyncHandler(tourController.convertWaitingToOnlineTour))
router.post("/:tour_id/upload", authenticate, asyncHandler(tourController.updateCoverImageTour))
router.post("/:tour_id/upload", formidableMiddleware(), authenticate, asyncHandler(tourController.updateCoverImageTour))
router.delete("/:tour_id", authenticate, asyncHandler(tourController.deleteTour))

module.exports = router

0 comments on commit 6ea3383

Please sign in to comment.