Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 7cb14280 authored by 65160394's avatar 65160394
Browse files

Project Round 3

parent 516bf2b7
No related branches found
No related tags found
No related merge requests found
...@@ -83,19 +83,22 @@ exports.Logout = (req, res) => { ...@@ -83,19 +83,22 @@ exports.Logout = (req, res) => {
//CRUD //CRUD
// ฟังก์ชั่นสำหรับแสดงฟอร์มสร้างทัวร์ // ฟังก์ชั่นสำหรับแสดงฟอร์มสร้างทัวร์
exports.getCreateTour = (req, res) => { exports.getCreateTour = (req, res) => {
res.render('createtour', { message: null }); // แสดงฟอร์มสร้างทัวร์ res.render('createtour', { message: null }); // ไม่ต้องดึงข้อมูลทัวร์ใด ๆ
}; };
exports.createTour = async (req, res) => { exports.createTour = async (req, res) => {
const { name, description, price, duration } = req.body; const { name, description, price, duration } = req.body;
try { try {
// สร้างทัวร์ใหม่ในฐานข้อมูล if (!name || !description || !price || !duration) {
await Tour.createTour({ name, description, price, duration }); return res.render('createtour', { message: 'All fields are required!' });
res.redirect('/'); // ไปยังหน้าหลักหลังจากสร้างทัวร์เสร็จ }
await Tour.createTour({ name, description, price, duration }); // เพิ่มข้อมูลทัวร์
res.redirect('/'); // หลังจากสร้างเสร็จให้กลับไปที่หน้าแรก
} catch (error) { } catch (error) {
console.error(error); console.error('Error creating tour:', error);
res.render('createtour', { message: error.message }); // แสดงข้อความข้อผิดพลาด res.render('createtour', { message: 'Error creating tour' });
} }
}; };
// ฟังก์ชั่นสำหรับสร้างทัวร์ // ฟังก์ชั่นสำหรับสร้างทัวร์
......
...@@ -15,19 +15,19 @@ ...@@ -15,19 +15,19 @@
<form action="/tour/create" method="POST"> <form action="/tour/create" method="POST">
<div> <div>
<label for="tourName">Tour Name:</label> <label for="tourName">Tour Name:</label>
<input type="text" id="tourName" name="tourName" required> <input type="text" id="tourName" name="name" required>
</div> </div>
<div> <div>
<label for="tourDescription">Description:</label> <label for="tourDescription">Description:</label>
<textarea id="tourDescription" name="tourDescription" required></textarea> <textarea id="tourDescription" name="description" required></textarea>
</div> </div>
<div> <div>
<label for="tourPrice">Price:</label> <label for="tourPrice">Price:</label>
<input type="number" id="tourPrice" name="tourPrice" required> <input type="number" id="tourPrice" name="price" required>
</div> </div>
<div> <div>
<label for="tourDate">Date:</label> <label for="tourDuration">Duration (days):</label>
<input type="date" id="tourDate" name="tourDate" required> <input type="number" id="tourDuration" name="duration" required>
</div> </div>
<button type="submit">Create Tour</button> <button type="submit">Create Tour</button>
</form> </form>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment