diff --git a/routes/reports.js b/routes/reports.js index 3f0821b6ffd03a8752a06d2cf7b4d74992ced4fb..7840b71666cabdcaf1cdb422512d2edaeb84cdc3 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) => {