From 97797ff7584b5dadf2c6f4fbec84cd8ebecd1a11 Mon Sep 17 00:00:00 2001 From: DucHuy2801 Date: Sun, 19 May 2024 03:00:26 +0700 Subject: [PATCH 1/4] log for api --- server/logs/test.log | 1 + 1 file changed, 1 insertion(+) diff --git a/server/logs/test.log b/server/logs/test.log index 9912540..e4238af 100644 --- a/server/logs/test.log +++ b/server/logs/test.log @@ -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! From 9ec6b2a1b35beac5361993a0f9cb5cd237d1e494 Mon Sep 17 00:00:00 2001 From: DucHuy2801 Date: Sun, 19 May 2024 03:00:40 +0700 Subject: [PATCH 2/4] fix createOrderFromCart --- server/src/controllers/order.controller.js | 37 ++++++++++++---------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/server/src/controllers/order.controller.js b/server/src/controllers/order.controller.js index 6097117..12da4a0 100644 --- a/server/src/controllers/order.controller.js +++ b/server/src/controllers/order.controller.js @@ -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!"}) @@ -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; From 2aafd3101eb9ef8dd133a10d393c8c3b200cb0b2 Mon Sep 17 00:00:00 2001 From: DucHuy2801 Date: Sun, 19 May 2024 03:05:00 +0700 Subject: [PATCH 3/4] table for relationship for tourGuide and tour --- server/src/models/guide_tour.model.js | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 server/src/models/guide_tour.model.js diff --git a/server/src/models/guide_tour.model.js b/server/src/models/guide_tour.model.js new file mode 100644 index 0000000..db0d435 --- /dev/null +++ b/server/src/models/guide_tour.model.js @@ -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 + + From 9bbc858b11dd5a4bbf93cb9b8315909cf43883d8 Mon Sep 17 00:00:00 2001 From: DucHuy2801 Date: Sun, 19 May 2024 03:05:14 +0700 Subject: [PATCH 4/4] fix route uploadCoverImage of tour --- server/src/routes/tour/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/routes/tour/index.js b/server/src/routes/tour/index.js index d6ab686..7ac50dc 100644 --- a/server/src/routes/tour/index.js +++ b/server/src/routes/tour/index.js @@ -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 \ No newline at end of file