Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 95e3e5d4 authored by 65160394's avatar 65160394
Browse files

Project Round 6

parent 20be8fe5
Branches
No related tags found
No related merge requests found
......@@ -214,12 +214,6 @@ exports.searchTours = async (req, res) => {
try {
const searchQuery = req.query.query;
const tours = await Tour.searchTours(searchQuery);
// หากไม่พบทัวร์จากการค้นหา
if (tours.length === 0) {
return res.render('search', { tours: [], message: 'ไม่พบที่ค้นหา' });
}
res.render('search', { tours, session: req.session });
} catch (error) {
res.status(500).send("Error searching tours");
......
......@@ -14,24 +14,22 @@ class Tour {
}
}
static async searchTours(req, res) {
const query = req.query.query;
// ค้นหาทัวร์โดยใช้ชื่อ
static async searchTours(query) {
try {
const tours = await Tour.searchTours(query);
// ถ้าไม่มีทัวร์ในผลลัพธ์
if (tours.length === 0) {
console.log('ไม่พบทัวร์ที่ค้นหา');
const [rows] = await pool.query('SELECT * FROM tours WHERE name LIKE ?', [`%${query}%`]);
// หากไม่มีทัวร์ที่ตรงกับคำค้นหา
if (rows.length === 0) {
return 'ไม่พบทัวร์ที่ตรงกับคำค้นหาของคุณ';
}
res.render('search', { tours });
return rows;
} catch (error) {
console.error('Error searching tours:', error.message);
res.render('search', { tours: [] });
throw new Error('เกิดข้อผิดพลาดในการค้นหาทัวร์');
}
}
// สร้างทัวร์
static async createTour(name, description, price, duration) {
// ตรวจสอบข้อมูล
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment