fullfilled landingpage
This commit is contained in:
@@ -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;
|
||||
|
@@ -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 };
|
||||
};
|
||||
|
Reference in New Issue
Block a user