Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 529e0ce1 authored by 65160394's avatar 65160394
Browse files

Project Round 8

parent 2c5de5b0
No related branches found
No related tags found
No related merge requests found
......@@ -202,8 +202,8 @@ exports.getEditTour = async (req, res) => {
};
exports.postEditTour = async (req, res) => {
console.log('📥 Data received:', req.body); // ตรวจสอบข้อมูลที่ได้รับจากฟอร์ม
const { name, description, price, duration } = req.body;
console.log('📥 Data received:', req.body); // ตรวจสอบข้อมูลที่ได้รับจากฟอร์ม
// ตรวจสอบว่ามีค่าครบถ้วนหรือไม่
if (!name || !description || !price || !duration) {
......@@ -213,8 +213,8 @@ exports.postEditTour = async (req, res) => {
const tourData = { name, description, price, duration };
try {
await Tour.updateTour(req.params.userId, tourData); // ตรวจสอบ tourId
res.redirect('/tour/' + req.params.userId); // ไปที่หน้ารายละเอียดทัวร์
await Tour.updateTour(req.params.id, tourData);
res.redirect('/tour/' + req.params.id); // ไปที่หน้ารายละเอียดทัวร์
} catch (error) {
console.error('Error updating tour:', error); // ข้อผิดพลาด
res.status(500).send('เกิดข้อผิดพลาดในการแก้ไขทัวร์');
......
......@@ -58,7 +58,7 @@ class Tour {
// อัปเดตทัวร์
static async updateTour(userId, tourData) {
static async updateTour(id, tourData) {
const { name, description, price, duration } = tourData;
if (!name || !description || !price || !duration) {
......@@ -68,7 +68,7 @@ class Tour {
const query = 'UPDATE tours SET name = ?, description = ?, price = ?, duration = ? WHERE id = ?';
try {
const [results] = await pool.execute(query, [name, description, price, duration, userId]);
const [results] = await pool.execute(query, [name, description, price, duration, id]);
console.log('✅ Update results:', results);
return results;
} catch (error) {
......@@ -78,7 +78,6 @@ class Tour {
}
// ดึงทัวร์ตาม ID
static async getTourById(id) {
try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment