From 2be41f8cf9165274c966d7415f7eb9e0d99c239f Mon Sep 17 00:00:00 2001 From: DucHuy2801 Date: Fri, 17 May 2024 23:14:57 +0700 Subject: [PATCH 1/4] update API: updateSchedule --- server/src/postman/BKTravel.json | 59 +++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/server/src/postman/BKTravel.json b/server/src/postman/BKTravel.json index ef56587..f07d065 100644 --- a/server/src/postman/BKTravel.json +++ b/server/src/postman/BKTravel.json @@ -1768,8 +1768,7 @@ "header": [ { "key": "Authorization", - "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNTg1OTEwMSwiZXhwIjoxNzA1ODYwOTAxfQ.CVQhYHm4g_-xFLV-rIezkRoyzOPogEkxm5nzrX6S930", - "disabled": true + "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNTg1OTEwMSwiZXhwIjoxNzA1ODYwOTAxfQ.CVQhYHm4g_-xFLV-rIezkRoyzOPogEkxm5nzrX6S930" } ], "body": { @@ -2029,9 +2028,9 @@ "response": [] }, { - "name": "Get schedule of tour", + "name": "Update schedule", "request": { - "method": "GET", + "method": "PUT", "header": [ { "key": "Authorization", @@ -2039,8 +2038,17 @@ "disabled": true } ], + "body": { + "mode": "raw", + "raw": "{\r\n \"tour_id\": 2,\r\n \"schedule_detail\": [\r\n {\r\n \"date\": \"08/03/2024\",\r\n \"detail\": [\r\n {\r\n \"name\": \"Ăn sáng\",\r\n \"note\": \"Updated note for Cố Đô Huế\",\r\n \"range_time\": \"8AM-10AM\",\r\n \"description\": \"Updated description for Cố Đô Huế\"\r\n },\r\n {\r\n \"name\": \"Xóm rế\",\r\n \"note\": \"Updated note for Chùa Thiên Mụ\",\r\n \"range_time\": \"12PM-2PM\",\r\n \"description\": \"Updated description for Chùa Thiên Mụ\"\r\n }\r\n ],\r\n \"schedule_date\": \"Ngày 1\"\r\n },\r\n {\r\n \"date\": \"09/03/2024\",\r\n \"detail\": [\r\n {\r\n \"name\": \"Đập Đá\",\r\n \"note\": \"Updated note for Đập Đá\",\r\n \"range_time\": \"8AM-10AM\",\r\n \"description\": \"Updated description for Đập Đá\"\r\n },\r\n {\r\n \"name\": \"Đa cua\",\r\n \"note\": \"Updated note for Đa cua\",\r\n \"range_time\": \"12PM-2PM\",\r\n \"description\": \"Updated description for Đa cua\"\r\n }\r\n ],\r\n \"schedule_date\": \"Ngày 2\"\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, "url": { - "raw": "http://localhost:8080/api/v1/tours/1/schedules", + "raw": "http://localhost:8080/api/v1/schedules/1", "protocol": "http", "host": [ "localhost" @@ -2049,9 +2057,8 @@ "path": [ "api", "v1", - "tours", - "1", - "schedules" + "schedules", + "1" ] } }, @@ -2287,8 +2294,7 @@ "header": [ { "key": "Authorization", - "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNTg1OTEwMSwiZXhwIjoxNzA1ODYwOTAxfQ.CVQhYHm4g_-xFLV-rIezkRoyzOPogEkxm5nzrX6S930", - "type": "text" + "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNTg1OTEwMSwiZXhwIjoxNzA1ODYwOTAxfQ.CVQhYHm4g_-xFLV-rIezkRoyzOPogEkxm5nzrX6S930" } ], "body": { @@ -2405,8 +2411,7 @@ "header": [ { "key": "Authorization", - "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNTg1OTEwMSwiZXhwIjoxNzA1ODYwOTAxfQ.CVQhYHm4g_-xFLV-rIezkRoyzOPogEkxm5nzrX6S930", - "disabled": true + "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNTg1OTEwMSwiZXhwIjoxNzA1ODYwOTAxfQ.CVQhYHm4g_-xFLV-rIezkRoyzOPogEkxm5nzrX6S930" } ], "body": { @@ -2439,7 +2444,7 @@ }, { "key": "payment_id", - "value": "", + "value": "15233424", "type": "text" } ] @@ -3030,6 +3035,34 @@ } }, "response": [] + }, + { + "name": "pendingtour", + "request": { + "method": "GET", + "header": [ + { + "key": "Authorization", + "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNTg1OTEwMSwiZXhwIjoxNzA1ODYwOTAxfQ.CVQhYHm4g_-xFLV-rIezkRoyzOPogEkxm5nzrX6S930" + } + ], + "url": { + "raw": "http://localhost:8080/api/v1/users/1/pendingtour", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "api", + "v1", + "users", + "1", + "pendingtour" + ] + } + }, + "response": [] } ] } \ No newline at end of file From abec92c3df9e28f0cada59ea85e5f2ef92103bf4 Mon Sep 17 00:00:00 2001 From: DucHuy2801 Date: Fri, 17 May 2024 23:15:07 +0700 Subject: [PATCH 2/4] add updateSchedule controller --- server/src/controllers/schedule.controller.js | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/server/src/controllers/schedule.controller.js b/server/src/controllers/schedule.controller.js index 766e4eb..0fae7a1 100644 --- a/server/src/controllers/schedule.controller.js +++ b/server/src/controllers/schedule.controller.js @@ -75,6 +75,73 @@ class ScheduleController { } } + updateSchedule = async (req, res, next) => { + try { + const id = req.params.id; + const { + tour_id, schedule_detail + } = req.body + + const tour = await findTourById(tour_id) + if (!tour) { + return res.status(404).json({ message: "Not found tour!" }) + } + + const schedule = await Schedule.findOne({ + where: { + id, + tour_id + } + }) + if (!schedule) { + return res.status(404).json({ message: "Not found schedule for updating!" }) + } + + for (const scheduleItem of schedule_detail) { + for (const detail of scheduleItem.detail) { + const name = detail.name; + + const attraction = await Attraction.findOne({ where: { name: name } }); + if (!attraction) { + let exist_attraction = await OtherAttraction.findOne({ where: { name: name } }); + if (!exist_attraction) { + exist_attraction = await OtherAttraction.create({ + name: detail.name, + note: detail.note || null, + description: detail.description + }); + } else { + exist_attraction.note = detail.note || null; + exist_attraction.description = detail.description; + await exist_attraction.save(); + } + } else { + attraction.note = detail.note || null; + attraction.description = detail.description; + await attraction.save(); + } + } + } + + schedule.schedule_detail = JSON.parse(JSON.stringify(schedule_detail)); + await schedule.save(); + + tour.status = StatusTour.ONLINE; + await tour.save(); + + redisClient.del("waiting_tours"); + redisClient.del("online_tours"); + + return res.status(200).json({ + message: "Update schedule for tour successfully!", + data: schedule + }); + + } catch (error) { + return res.status(500).json({ message: error.message }) + } + } + deleteSchedule = async(req, res, next) => { try { const tour_id = req.params.tour_id From 6cc94d98d6ffcf85d7772d72418591673903a143 Mon Sep 17 00:00:00 2001 From: DucHuy2801 Date: Fri, 17 May 2024 23:15:16 +0700 Subject: [PATCH 3/4] init route updateSchedule --- server/src/routes/schedule/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/routes/schedule/index.js b/server/src/routes/schedule/index.js index 367a8a0..1fa76aa 100644 --- a/server/src/routes/schedule/index.js +++ b/server/src/routes/schedule/index.js @@ -7,6 +7,7 @@ const scheduleController = require("../../controllers/schedule.controller") const { authenticate } = require("../../middlewares/authenticate") router.post("/", authenticate, asyncHandler(scheduleController.createSchedule)) +router.put("/:id", authenticate, asyncHandler(scheduleController.updateSchedule)) router.get("/weather", asyncHandler(scheduleController.getWeatherData)) module.exports = router \ No newline at end of file From 8b0cd349d7513da4eb709a0be315af19152f5332 Mon Sep 17 00:00:00 2001 From: DucHuy2801 Date: Sat, 18 May 2024 12:25:28 +0700 Subject: [PATCH 4/4] fix route proposeTour --- server/src/routes/user/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/routes/user/index.js b/server/src/routes/user/index.js index 2ef13d5..4b0bf25 100644 --- a/server/src/routes/user/index.js +++ b/server/src/routes/user/index.js @@ -11,7 +11,7 @@ const cartController = require("../../controllers/cart.controller") router.get("/:user_id", authenticate, asyncHandler(userController.getInfoUser)) router.get("/:user_id", authenticate, asyncHandler(userController.getInfoUser)) -router.post("/:user_id/tours", authenticate, asyncHandler(userController.proposeTour)) +router.post("/tours", authenticate, asyncHandler(userController.proposeTour)) router.get("/:user_id/groups", authenticate, asyncHandler(userController.getAllGroupsByUserId)) router.get("/:user_id/cart", authenticate, asyncHandler(cartController.getCartByUser)) router.get("/:user_id/pendingtour", authenticate, asyncHandler(userController.getPendingTour))