Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 7161be25 authored by 65160268's avatar 65160268
Browse files

Update 2 files

- /server.js
- /views/thread-view.ejs
parent 2b5fac65
Branches main
No related tags found
No related merge requests found
......@@ -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}`);
}
);
}
);
});
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment