fullfilled landingpage

This commit is contained in:
2025-09-21 00:48:28 +02:00
parent 679ef7dcbd
commit ab93c9959d
3 changed files with 222 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import {
setReturnDateV2,
setTakeDateV2,
getLoanByCodeV2,
getAllLoansV2,
} from "../services/database.js";
dotenv.config();
@@ -90,4 +91,12 @@ router.post("/setTakeDate/:key/:loan_code", async (req, res) => {
}
});
router.get("/allLoans", async (req, res) => {
const result = await getAllLoansV2();
if (result.success) {
return res.status(200).json(result.data);
}
return res.status(500).json({ message: "Failed to fetch loans" });
});
export default router;

View File

@@ -447,3 +447,13 @@ export const updateItemByID = async (itemId, item_name, can_borrow_role) => {
if (result.affectedRows > 0) return { success: true };
return { success: false };
};
export const getAllLoansV2 = async () => {
const [rows] = await pool.query(
"SELECT id, username, start_date, end_date, loaned_items_name, returned_date, take_date FROM loans"
);
if (rows.length > 0) {
return { success: true, data: rows };
}
return { success: false };
};