enhance dashboard and user interface: update heading sizes, translate user label to German, and implement loan management features including fetching and displaying loans with error handling
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
deleteUserID,
|
||||
handleEdit,
|
||||
createUser,
|
||||
getAllLoans,
|
||||
} from "../services/database.js";
|
||||
import { authenticate, generateToken } from "../services/tokenService.js";
|
||||
const router = express.Router();
|
||||
@@ -238,4 +239,12 @@ router.post("/createUser", authenticate, async (req, res) => {
|
||||
return res.status(500).json({ message: "Failed to create user" });
|
||||
});
|
||||
|
||||
router.get("/allLoans", authenticate, async (req, res) => {
|
||||
const result = await getAllLoans();
|
||||
if (result.success) {
|
||||
return res.status(200).json(result.data);
|
||||
}
|
||||
return res.status(500).json({ message: "Failed to fetch loans" });
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
@@ -358,3 +358,9 @@ export const createUser = async (username, role, password) => {
|
||||
if (result.affectedRows > 0) return { success: true };
|
||||
return { success: false };
|
||||
};
|
||||
|
||||
export const getAllLoans = async () => {
|
||||
const [result] = await pool.query("SELECT * FROM loans");
|
||||
if (result.length > 0) return { success: true, data: result };
|
||||
return { success: false };
|
||||
};
|
||||
|
Reference in New Issue
Block a user