Gitlab@Informatics
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BorrowProject65160024-deleted-1917
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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This project is pending deletion, and will be deleted on
2025-07-22
. Repository and other project resources are read-only.
Show more breadcrumbs
65160024
BorrowProject65160024-deleted-1917
Commits
07275c38
Commit
07275c38
authored
4 months ago
by
65160024
Browse files
Options
Downloads
Patches
Plain Diff
update
parent
4ecc7f75
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
index.js
+17
-25
17 additions, 25 deletions
index.js
with
17 additions
and
25 deletions
index.js
+
17
−
25
View file @
07275c38
...
...
@@ -337,34 +337,26 @@ app.post("/approve-loan", isAuthenticated, isAdmin, (req, res) => {
// Route แสดงหน้าการยืนยันการยืม
app
.
post
(
'
/confirm-loan
'
,
(
req
,
res
)
=>
{
const
{
equipment_id
,
quantity
}
=
req
.
body
;
// คำสั่ง SQL เพื่อลงข้อมูลการยืม
const
query
=
`
INSERT INTO loans (equipment_id, quantity, user_id, loan_date)
VALUES (?, ?, ?, NOW())`
;
app
.
post
(
"
/confirm-loan
"
,
(
req
,
res
)
=>
{
if
(
!
req
.
user
)
{
return
res
.
redirect
(
"
/login
"
);
// หากไม่ได้ล็อกอิน ให้กลับไปที่หน้า login
}
// รับ user_id จาก session หรือจาก JWT token (ถ้าใช้ระบบล็อกอิน)
const
user_id
=
req
.
session
.
userId
;
// สมมติว่าเก็บ user_id ไว้ใน session
const
equipment_id
=
req
.
body
.
equipment_id
;
const
quantity
=
req
.
body
.
quantity
;
db
.
query
(
query
,
[
equipment_id
,
quantity
,
user_id
],
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
error
(
'
Error inserting loan data:
'
,
err
);
return
res
.
status
(
500
).
send
(
'
เกิดข้อผิดพลาดในการยืมอุปกรณ์
'
);
}
// ดึงข้อมูลอุปกรณ์จากฐานข้อมูล
db
.
query
(
"
SELECT * FROM equipment WHERE id = ?
"
,
[
equipment_id
],
(
err
,
result
)
=>
{
if
(
err
)
throw
err
;
const
equipment
=
result
[
0
];
// ปรับสถานะของอุปกรณ์หลังการยืม
const
updateQuery
=
'
UPDATE equipment SET quantity = quantity - ? WHERE id = ?
'
;
db
.
query
(
updateQuery
,
[
quantity
,
equipment_id
],
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
'
Error updating equipment quantity:
'
,
err
);
return
res
.
status
(
500
).
send
(
'
เกิดข้อผิดพลาดในการปรับปรุงข้อมูลอุปกรณ์
'
);
// ส่งข้อมูล user ไปยัง confirm-loan.ejs
res
.
render
(
"
confirm-loan
"
,
{
equipment
,
quantity
,
user
:
req
.
user
});
}
res
.
redirect
(
'
/loans
'
);
// ไปยังหน้ารวมการยืมอุปกรณ์
});
});
);
});
...
...
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