Gitlab@Informatics
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IFREPAIRS_FINAL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
65160111
IFREPAIRS_FINAL
Commits
f6cfd2f1
Commit
f6cfd2f1
authored
2 weeks ago
by
65160111
Browse files
Options
Downloads
Patches
Plain Diff
Edit report url image
parent
8a289fb9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
routes/reports.js
+12
-4
12 additions, 4 deletions
routes/reports.js
with
12 additions
and
4 deletions
routes/reports.js
+
12
−
4
View file @
f6cfd2f1
...
...
@@ -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
)
=>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment