diff --git a/controllers/tourController.js b/controllers/tourController.js index 48091bce056e6ad1f2aae7d847f94225dc047cb8..e9325a9cd99cac4100f2f3fa582db6c2f3ab1221 100644 --- a/controllers/tourController.js +++ b/controllers/tourController.js @@ -209,13 +209,19 @@ exports.postCreateTour = async (req, res) => { } }; -//ค้นหาทัวร์ +// ค้นหาทัวร์ 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"); } -}; \ No newline at end of file +}; diff --git a/views/search.ejs b/views/search.ejs index b4eb48955cfdadf5110c7302ea85336cfcd6d1a5..ec60cf83279bb7460b5bf5f495a9575b1d1687a6 100644 --- a/views/search.ejs +++ b/views/search.ejs @@ -9,7 +9,7 @@ </li> <% }) %> <% } else { %> - <p>No tours found</p> + <p>ไม่พบทัวร์ที่ค้นหา</p> <% } %> </ul>