From 0ec926f41f2bc710f3fc005f5aa02a3aba4f96f3 Mon Sep 17 00:00:00 2001 From: Atiwit Pattanapukdee <65160394@go.buu.ac.th> Date: Wed, 26 Mar 2025 17:27:02 +0700 Subject: [PATCH] Project Round 10 --- models/tourModel.js | 8 ++++---- views/edittour.ejs | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/models/tourModel.js b/models/tourModel.js index 0cd1985..b3b335a 100644 --- a/models/tourModel.js +++ b/models/tourModel.js @@ -53,19 +53,19 @@ class Tour { // อัปเดตทัวร์ static async updateTour(tourId, tourData) { - const { name, description, price, duration } = tourData; + const { name, description, price, duration, companyid } = tourData; // ตรวจสอบข้อมูลให้ครบถ้วน - if (!name || !description || !price || !duration) { + if (!name || !description || !price || !duration|| !companyid) { throw new Error('ข้อมูลไม่ครบถ้วน'); } // สร้างคำสั่ง SQL สำหรับการอัปเดตข้อมูล - const query = 'UPDATE tours SET name = ?, description = ?, price = ?, duration = ? WHERE id = ?'; + const query = 'UPDATE tours SET name = ?, description = ?, price = ?, duration = ? , companyid = ? WHERE id = ?'; try { // ใช้ tourId ที่รับมาในการอัปเดต - const [results] = await pool.execute(query, [name, description, price, duration, tourId]); + const [results] = await pool.execute(query, [name, description, price, duration, companyid, tourId]); console.log('✅ Update results:', results); return results; } catch (error) { diff --git a/views/edittour.ejs b/views/edittour.ejs index 9d8a864..53b3446 100644 --- a/views/edittour.ejs +++ b/views/edittour.ejs @@ -26,6 +26,15 @@ <label for="tourDuration">ระยะเวลา (วัน):</label> <input type="number" id="tourDuration" name="duration" value="<%= tour.duration %>" required> </div> + <div> + <label for="tourCompany">บริษัท:</label> + <select id="tourCompany" name="companyid" required> + <option value="" disabled selected>เลือกบริษัท</option> + <option value="1">Amazing Travel</option> + <option value="2">Wonderful Tours</option> + <option value="3">Explore Asia</option> + </select> + </div> <button type="submit">Update Tour</button> </form> </main> -- GitLab