Skip to content

Commit

Permalink
fix propose tour
Browse files Browse the repository at this point in the history
  • Loading branch information
augustus281 committed Jun 2, 2024
1 parent 05b39f8 commit 77b85ec
Showing 1 changed file with 2 additions and 39 deletions.
41 changes: 2 additions & 39 deletions server/src/controllers/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ class UserController {
time,
max_number,
note,
user_id,
schedule_detail
user_id
} = req.body

const currentDate = new Date()
Expand Down Expand Up @@ -385,55 +384,19 @@ class UserController {
})
}


await UserTour.create({
user_id: user_id,
tour_id: newTour.tour_id
})

// Create schedule for tour

for (const schedule of schedule_detail) {
for (const detail of schedule.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()
}
}
}
const new_schedule = await Schedule.create({
schedule_detail: JSON.parse(JSON.stringify(schedule_detail)),
tour_id: newTour.tour_id
})

return res.status(200).json({
message: "Propose tour successfully!",
data: await Tour.findOne({
where: {
tour_id: newTour.tour_id
},
include: [Destination, Attraction]
}),
schedule: new_schedule
})
})
} catch (error) {
return res.status(500).json({ message: error.message })
Expand Down

0 comments on commit 77b85ec

Please sign in to comment.