From f6cfd2f13253ea9b718c877b989708af05a7faf0 Mon Sep 17 00:00:00 2001 From: 65160111 <65160111@go.buu.ac.th> Date: Fri, 21 Mar 2025 13:51:22 +0700 Subject: [PATCH] Edit report url image --- routes/reports.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/routes/reports.js b/routes/reports.js index 3f0821b..7840b71 100644 --- a/routes/reports.js +++ b/routes/reports.js @@ -50,6 +50,8 @@ router.get("/", authMiddleware, (req, res) => { const floor = req.query.floor; // optional: ชั้นที่เลือก const room = req.query.room; // optional: ห้องที่เลือก + const BASE_URL = "https://repairsys.th2.melon.cloud"; // ✅ ใช้ URL จริงของ Melon Cloud + let conditions = ["(reports.title LIKE ? OR reports.description LIKE ?)"]; let params = [`%${search}%`, `%${search}%`]; @@ -75,7 +77,9 @@ router.get("/", authMiddleware, (req, res) => { results.forEach(report => { if (report.image_url) { - report.image_url = `http://localhost:8080${report.image_url}`; + report.image_url = `${BASE_URL}${report.image_url}`; + } else { + report.image_url = null; // 🔥 ป้องกันกรณีไม่มีรูปภาพ } }); @@ -89,6 +93,8 @@ router.get("/", authMiddleware, (req, res) => { // 🔹 Get Single Report by ID router.get("/:id", authMiddleware, (req, res) => { + const BASE_URL = "https://repairsys.th2.melon.cloud"; // ✅ ใช้ URL จริงของ Melon Cloud + db.query(` SELECT reports.*, users.username, rooms.room_name, rooms.floor FROM reports @@ -102,13 +108,15 @@ router.get("/:id", authMiddleware, (req, res) => { const report = results[0]; if (report.image_url) { - // ลบช่องว่างที่ไม่จำเป็นออก - report.image_url = `http://localhost:8080${report.image_url}`; + report.image_url = `${BASE_URL}${report.image_url}`; + } else { + report.image_url = null; // 🔥 ป้องกันกรณีไม่มีรูปภาพ } res.json(report); }); - }); +}); + // 🔹 Update Report (แก้ไขเฉพาะ Title, Description) router.put("/:id", authMiddleware, (req, res) => { -- GitLab