Skip to content

Commit

Permalink
Merge pull request #20 from DucHuy2801/fix-bug
Browse files Browse the repository at this point in the history
Fix bug
  • Loading branch information
augustus281 authored May 18, 2024
2 parents 5c52c6b + 8b0cd34 commit f705b7f
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 14 deletions.
67 changes: 67 additions & 0 deletions server/src/controllers/schedule.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 46 additions & 13 deletions server/src/postman/BKTravel.json
Original file line number Diff line number Diff line change
Expand Up @@ -1768,8 +1768,7 @@
"header": [
{
"key": "Authorization",
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNTg1OTEwMSwiZXhwIjoxNzA1ODYwOTAxfQ.CVQhYHm4g_-xFLV-rIezkRoyzOPogEkxm5nzrX6S930",
"disabled": true
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNTg1OTEwMSwiZXhwIjoxNzA1ODYwOTAxfQ.CVQhYHm4g_-xFLV-rIezkRoyzOPogEkxm5nzrX6S930"
}
],
"body": {
Expand Down Expand Up @@ -2029,18 +2028,27 @@
"response": []
},
{
"name": "Get schedule of tour",
"name": "Update schedule",
"request": {
"method": "GET",
"method": "PUT",
"header": [
{
"key": "Authorization",
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNTg1OTEwMSwiZXhwIjoxNzA1ODYwOTAxfQ.CVQhYHm4g_-xFLV-rIezkRoyzOPogEkxm5nzrX6S930",
"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"
Expand All @@ -2049,9 +2057,8 @@
"path": [
"api",
"v1",
"tours",
"1",
"schedules"
"schedules",
"1"
]
}
},
Expand Down Expand Up @@ -2287,8 +2294,7 @@
"header": [
{
"key": "Authorization",
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNTg1OTEwMSwiZXhwIjoxNzA1ODYwOTAxfQ.CVQhYHm4g_-xFLV-rIezkRoyzOPogEkxm5nzrX6S930",
"type": "text"
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNTg1OTEwMSwiZXhwIjoxNzA1ODYwOTAxfQ.CVQhYHm4g_-xFLV-rIezkRoyzOPogEkxm5nzrX6S930"
}
],
"body": {
Expand Down Expand Up @@ -2405,8 +2411,7 @@
"header": [
{
"key": "Authorization",
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNTg1OTEwMSwiZXhwIjoxNzA1ODYwOTAxfQ.CVQhYHm4g_-xFLV-rIezkRoyzOPogEkxm5nzrX6S930",
"disabled": true
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNTg1OTEwMSwiZXhwIjoxNzA1ODYwOTAxfQ.CVQhYHm4g_-xFLV-rIezkRoyzOPogEkxm5nzrX6S930"
}
],
"body": {
Expand Down Expand Up @@ -2439,7 +2444,7 @@
},
{
"key": "payment_id",
"value": "",
"value": "15233424",
"type": "text"
}
]
Expand Down Expand Up @@ -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": []
}
]
}
1 change: 1 addition & 0 deletions server/src/routes/schedule/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion server/src/routes/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit f705b7f

Please sign in to comment.