Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit e7677368 authored by 65160024's avatar 65160024
Browse files

update loans

parent 64cf15f4
No related branches found
No related tags found
No related merge requests found
......@@ -294,15 +294,17 @@ app.post("/delete-equipment", isAuthenticated, (req, res) => {
app.get("/loans", (req, res) => {
if (req.user && req.user.role === "user") {
db.query(
`SELECT loans.id, loans.quantity, loans.status, equipment.name AS equipment_name
`SELECT loans.id, loans.quantity, loans.status, equipment.name AS equipment_name, users.name AS borrower_name
FROM loans
JOIN equipment ON loans.equipment_id = equipment.id
JOIN users ON loans.user_id = users.id
WHERE loans.user_id = ?`,
[req.user.id], // req.user.id will be substituted into the ?
[req.user.id], // Ensure that user_id is being passed correctly
(err, loans) => {
if (err) {
return res.status(500).send("Error retrieving loans");
}
// ส่งข้อมูลทั้ง loans และ borrower_name ไปยัง EJS
res.render("loans", { loans: loans, user: req.user });
}
);
......@@ -313,6 +315,7 @@ app.get("/loans", (req, res) => {
// หน้าแสดงรายการการยืมสำหรับ Admin
app.get("/admin-loans", (req, res) => {
if (req.isAuthenticated() && req.user.role === "admin") {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment