From 7161be25073d598f2efd186c08078cd2ec99abbc Mon Sep 17 00:00:00 2001
From: 65160268 <65160268@go.buu.ac.th>
Date: Fri, 28 Mar 2025 13:12:23 +0000
Subject: [PATCH] Update 2 files

- /server.js
- /views/thread-view.ejs
---
 server.js             | 18 ++++++++++++------
 views/thread-view.ejs |  2 +-
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/server.js b/server.js
index 5556572..9e438f1 100644
--- a/server.js
+++ b/server.js
@@ -246,16 +246,22 @@ app.post('/thread/:id/comment', isAuthenticated, (req, res) => {
 // เธฅเธšเธ„เธญเธกเน€เธกเธ™เธ•เนŒ
 app.get('/comment/delete/:id', isAuthenticated, (req, res) => {
   const commentId = req.params.id;
-  connection.query(
-    'SELECT * FROM comments WHERE id = ? AND user_id = ?',
+
+   connection.query(
+    'SELECT * FROM comments WHERE comment_id = ? AND user_id = ?',
     [commentId, req.session.userId],
     (err, results) => {
       if (err || results.length === 0) return res.send('เน„เธกเนˆเธžเธšเธ„เธญเธกเน€เธกเธ™เธ•เนŒเธ—เธตเนˆเธ•เน‰เธญเธ‡เธเธฒเธฃเธฅเธš');
+
       const comment = results[0];
-      connection.query('DELETE FROM comments WHERE id = ?', [commentId], (err2) => {
-        if (err2) return res.send('เน€เธเธดเธ”เธ‚เน‰เธญเธœเธดเธ”เธžเธฅเธฒเธ”เนƒเธ™เธเธฒเธฃเธฅเธšเธ„เธญเธกเน€เธกเธ™เธ•เนŒ');
-        res.redirect(`/thread/${comment.thread_id}`);
-      });
+      connection.query(
+        'DELETE FROM comments WHERE comment_id = ?', 
+        [commentId], 
+        (err2) => {
+          if (err2) return res.send('เน€เธเธดเธ”เธ‚เน‰เธญเธœเธดเธ”เธžเธฅเธฒเธ”เนƒเธ™เธเธฒเธฃเธฅเธšเธ„เธญเธกเน€เธกเธ™เธ•เนŒ');
+          res.redirect(`/thread/${comment.thread_id}`);
+        }
+      );
     }
   );
 });
diff --git a/views/thread-view.ejs b/views/thread-view.ejs
index 1157bad..91e52e4 100644
--- a/views/thread-view.ejs
+++ b/views/thread-view.ejs
@@ -61,7 +61,7 @@
 
             <!-- เธ›เธธเนˆเธกเธฅเธšเธ„เธญเธกเน€เธกเธ™เธ•เนŒ (เน€เธ‰เธžเธฒเธฐเน€เธˆเน‰เธฒเธ‚เธญเธ‡เธ„เธญเธกเน€เธกเธ™เธ•เนŒ) -->
             <% if (c.user_id === userId) { %>
-              <a href="/comment/delete/<%= c.id %>"
+              <a href="/comment/delete/<%= c.comment_id %>"
                  class="btn btn-sm btn-outline-danger float-right"
                  onclick="return confirm('Delete this comment?');">
                 Delete
-- 
GitLab