- Updated LoanTable component to fetch loan data from new API endpoint and display notes. - Enhanced UserTable component to include additional user fields (first name, last name, email, admin status) and updated input handling. - Modified fetcher utility to use new user data API endpoint. - Adjusted login functionality to point to the new admin login endpoint and handle unauthorized access. - Refactored user actions utility to align with updated API endpoints for user management. - Updated backend routes for user and loan data management to reflect new structure and naming conventions. - Revised SQL schema and mock data to accommodate new fields and constraints. - Changed Docker configuration to use the new database name.
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
import express from "express";
|
|
import { authenticateAdmin } from "../../services/authentication.js";
|
|
const router = express.Router();
|
|
import dotenv from "dotenv";
|
|
dotenv.config();
|
|
|
|
// database funcs import
|
|
import {
|
|
getAllApiKeys,
|
|
createAPIentry,
|
|
deleteAPKey,
|
|
} from "./database/apiDataMgmt.database.js";
|
|
|
|
router.get("/get-api-keys", authenticateAdmin, async (req, res) => {
|
|
const result = await getAllApiKeys();
|
|
if (result.success) {
|
|
return res.status(200).json(result.data);
|
|
}
|
|
return res.status(500).json({ message: "Failed to retrieve API keys" });
|
|
});
|
|
|
|
router.post("/create-api-key", authenticateAdmin, async (req, res) => {
|
|
const apiKey = req.body.apiKey;
|
|
const entryName = req.body.entryName;
|
|
const result = await createAPIentry(apiKey, entryName);
|
|
if (result.success) {
|
|
return res.status(201).json({ message: "API key created successfully" });
|
|
}
|
|
return res.status(500).json({ message: "Failed to create API key" });
|
|
});
|
|
|
|
router.delete("/delete-api-key/:id", authenticateAdmin, async (req, res) => {
|
|
const apiKeyId = req.params.id;
|
|
const result = await deleteAPKey(apiKeyId);
|
|
if (result.success) {
|
|
return res.status(200).json({ message: "API key deleted successfully" });
|
|
}
|
|
return res.status(500).json({ message: "Failed to delete API key" });
|
|
});
|
|
|
|
export default router;
|