From ee196aa4d6c8d65f8d0d239894b2d1f7a5939c59 Mon Sep 17 00:00:00 2001 From: Atiwit Pattanapukdee <65160394@go.buu.ac.th> Date: Tue, 18 Mar 2025 12:56:38 +0700 Subject: [PATCH] Project Round 3 --- controllers/tourController.js | 32 +++++++++++----------- models/tourModel.js | 50 +++++++++++++++++------------------ 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/controllers/tourController.js b/controllers/tourController.js index 3cbf27d..db5b3d4 100644 --- a/controllers/tourController.js +++ b/controllers/tourController.js @@ -1,22 +1,22 @@ const { User, Tour } = require('../models/tourModel'); -exports.getTours = async (req, res) => { - try { - const tours = await Tour.getAllTours(); - res.render('index', { tours,session: req.session }); - } catch (error) { - res.status(500).send(error.message); - } - }; +// exports.getTours = async (req, res) => { +// try { +// const tours = await Tour.getAllTours(); +// res.render('index', { tours,session: req.session }); +// } catch (error) { +// res.status(500).send(error.message); +// } +// }; - exports.getTourDetails = async (req, res) => { - try { - const tour = await Tour.getTourById(req.params.id); - res.render('tour-details', { tour }); - } catch (error) { - res.status(500).send(error.message); - } - }; +// exports.getTourDetails = async (req, res) => { +// try { +// const tour = await Tour.getTourById(req.params.id); +// res.render('tour-details', { tour }); +// } catch (error) { +// res.status(500).send(error.message); +// } +// }; //User// exports.getLogin = (req, res) => { diff --git a/models/tourModel.js b/models/tourModel.js index e19e47e..b51b1a5 100644 --- a/models/tourModel.js +++ b/models/tourModel.js @@ -1,32 +1,32 @@ const pool = require('../config/database'); const bcrypt = require('bcryptjs'); class Tour { - // ดึงทัวร์ทั้งหมด - static async getAllTours() { - try { - console.log('Fetching all tours...'); - const [rows] = await pool.query('SELECT * FROM tours'); - console.log('Tours fetched successfully:', rows); - return rows; - } catch (error) { - console.error('Error fetching tours:', error.message); - throw new Error('เกิดข้อผิดพลาดในการดึงข้อมูลทัวร์: ' + error.message); - } - } + // // ดึงทัวร์ทั้งหมด + // static async getAllTours() { + // try { + // console.log('Fetching all tours...'); + // const [rows] = await pool.query('SELECT * FROM tours'); + // console.log('Tours fetched successfully:', rows); + // return rows; + // } catch (error) { + // console.error('Error fetching tours:', error.message); + // throw new Error('เกิดข้อผิดพลาดในการดึงข้อมูลทัวร์: ' + error.message); + // } + // } - // ดึงทัวร์ตาม ID - static async getTourById(id) { - try { - const [rows] = await pool.query('SELECT * FROM tours WHERE id = ?', [id]); - if (rows.length === 0) { - throw new Error('ไม่พบทัวร์ที่มี ID นี้'); - } - return rows[0]; - } catch (error) { - console.error('Error fetching tour by ID:', error); - throw new Error('เกิดข้อผิดพลาดในการดึงข้อมูลทัวร์'); - } - } + // // ดึงทัวร์ตาม ID + // static async getTourById(id) { + // try { + // const [rows] = await pool.query('SELECT * FROM tours WHERE id = ?', [id]); + // if (rows.length === 0) { + // throw new Error('ไม่พบทัวร์ที่มี ID นี้'); + // } + // return rows[0]; + // } catch (error) { + // console.error('Error fetching tour by ID:', error); + // throw new Error('เกิดข้อผิดพลาดในการดึงข้อมูลทัวร์'); + // } + // } // สร้างทัวร์ static async createTour(tourData) { -- GitLab