Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 298d031e authored by 65160268's avatar 65160268
Browse files

Update 2 files

- /views/thread-view.ejs
- /server.js
parent 9ccd2919
Branches
No related tags found
No related merge requests found
......@@ -32,7 +32,7 @@ const connection = mysql.createConnection({
connection.connect(err => {
if (err) {
console.error('Error connecting to MySQL:', err);
console.error('Error connecting to MySQL:', err);
process.exit(1);
}
console.log('Connected to MySQL Successfully');
......@@ -195,17 +195,28 @@ app.get('/thread/delete/:id', isAuthenticated, (req, res) => {
// หน้าแสดง thread พร้อมคอมเมนต์
app.get('/thread/:id', (req, res) => {
const threadId = req.params.id;
connection.query(
`SELECT threads.*, users.username AS ownerName FROM threads JOIN users ON threads.user_id = users.id WHERE threads.id = ?`,
`SELECT threads.*, users.username AS ownerName
FROM threads
JOIN users ON threads.user_id = users.id
WHERE threads.id = ?`,
[threadId],
(err, results) => {
if (err || results.length === 0) return res.send('ไม่พบ thread ที่ต้องการ');
const thread = results[0];
connection.query(
`SELECT comments.*, users.username AS commentUser FROM comments JOIN users ON comments.user_id = users.id WHERE comments.thread_id = ? ORDER BY comments.id DESC`,
`SELECT comments.*, users.username AS commentUser, users.email
FROM comments
JOIN users ON comments.user_id = users.id
WHERE comments.thread_id = ?
ORDER BY comments.id DESC`,
[threadId],
(err2, comments) => {
if (err2) return res.send('เกิดข้อผิดพลาดในการดึงคอมเมนต์');
res.render('thread-view', {
username: req.session.username,
userId: req.session.userId,
......@@ -218,6 +229,7 @@ app.get('/thread/:id', (req, res) => {
);
});
// เพิ่มคอมเมนต์ใหม่
app.post('/thread/:id/comment', isAuthenticated, (req, res) => {
const threadId = req.params.id;
......
......@@ -54,10 +54,10 @@
<!-- แสดงชื่อผู้คอมเมนต์และข้อความ -->
<strong><%= c.commentUser %>:</strong> <%= c.comment %>
<!-- แสดง Comment ID เล็ก ๆ -->
<span class="text-muted" style="font-size: 0.8em;">
(Comment ID: <%= c.id %>)
</span>
<!-- แสดง Email -->
<span class="text-muted" style="font-size: 0.8em;">
<b>(User Email: <%= c.email %>)</b>
</span>
<!-- ปุ่มลบคอมเมนต์ (เฉพาะเจ้าของคอมเมนต์) -->
<% if (c.user_id === userId) { %>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment