From e8aad67232fa729e2a543a91e2edfc36e34a0dc5 Mon Sep 17 00:00:00 2001 From: Atiwit Pattanapukdee <65160394@go.buu.ac.th> Date: Sun, 16 Mar 2025 21:53:45 +0700 Subject: [PATCH] Project Round 2 --- models/tourModel.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/models/tourModel.js b/models/tourModel.js index 60dce7c..11360d9 100644 --- a/models/tourModel.js +++ b/models/tourModel.js @@ -1,13 +1,13 @@ -const db = require('../config/database'); +const pool = require('../config/database'); const bcrypt = require('bcryptjs'); class Tour { static async getAllTours() { - const [rows] = await db.query('SELECT * FROM tours'); + const [rows] = await pool.query('SELECT * FROM tours'); return rows; } static async getTourById(id) { - const [rows] = await db.query('SELECT * FROM tours WHERE id = ?', [id]); + const [rows] = await pool.query('SELECT * FROM tours WHERE id = ?', [id]); return rows[0]; } } @@ -15,7 +15,7 @@ class Tour { class User { static async findOne(email) { try { - const [rows] = await db.query('SELECT * FROM users WHERE email = ?', [email]); + const [rows] = await pool.query('SELECT * FROM users WHERE email = ?', [email]); return rows.length > 0 ? rows[0] : null; } catch (err) { throw err; @@ -25,7 +25,7 @@ class User { static async create(name, email, password) { try { const hashedPassword = await bcrypt.hash(password, 10); - const [result] = await db.query( + const [result] = await pool.query( 'INSERT INTO users (name, email, password) VALUES (?, ?, ?)', [name, email, hashedPassword] ); -- GitLab