Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 9db1e988 authored by 65160394's avatar 65160394
Browse files

Project Round 11

parent d6e57d85
No related branches found
No related tags found
No related merge requests found
const { User, Tour } = require('../models/tourModel');
const { User, Tour, company } = require('../models/tourModel');
const pool = require('../config/database');
exports.getTours = async (req, res) => {
......@@ -147,8 +147,18 @@ exports.updateProfile = async (req, res) => {
//CRUD
// แสดงฟอร์มสร้างทัวร์
exports.getCreateTour = (req, res) => {
res.render('createtour');
// ฟังก์ชันแสดงฟอร์มสร้างทัวร์
exports.getCreateTour = async (req, res) => {
try {
// ดึงข้อมูลบริษัททั้งหมดจากฐานข้อมูล
const companies = await company.getAllCompanies();
// ส่งข้อมูลบริษัทไปยัง view 'createtour.ejs'
res.render('createtour', { companies });
} catch (error) {
console.error('Error fetching companies:', error);
res.status(500).send('เกิดข้อผิดพลาดในการดึงข้อมูลบริษัท');
}
};
// บันทึกทัวร์ใหม่
......@@ -198,6 +208,8 @@ exports.postCreateTour = async (req, res) => {
res.render('createtour', { message: 'เกิดข้อผิดพลาดในการสร้างทัวร์' });
}
};
//edit
exports.getEditTour = async (req, res) => {
try {
const tour = await Tour.getTourById(req.params.id);
......@@ -247,7 +259,7 @@ exports.postEditTour = async (req, res) => {
}
};
//delete
exports.deleteTour = async (req, res) => {
try {
const tourId = req.params.id;
......
......@@ -137,4 +137,12 @@ class User {
}
}
module.exports = { User, Tour };
class company {
static async getAllCompany() {
const query = 'SELECT * FROM company';
const [rows] = await pool.execute(query);
return rows;
}
}
module.exports = { User, Tour ,company};
......@@ -30,12 +30,12 @@
<div>
<label for="tourCompany">บริษัท:</label>
<select id="tourCompany" name="company_id" required>
<option value="" re>เลือกบริษัท</option>
<option value="1">Amazing Travel</option>
<option value="2">Wonderful Tours</option>
<option value="3">Explore Asia</option>
<option value="">เลือกบริษัท</option>
<% companies.forEach(company => { %>
<option value="<%= company.id %>"><%= company.name %></option>
<% }) %>
</select>
</div>
</div>
<button type="submit">สร้างโปรแกรม Tour</button>
</form>
</main>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment