implemented service configuration to admin panel
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import mysql from "mysql2";
|
||||
import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
|
||||
const pool = mysql
|
||||
.createPool({
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.DB_NAME,
|
||||
})
|
||||
.promise();
|
||||
|
||||
export const getAllFunctions = async () => {
|
||||
const [rows] = await pool.query("SELECT * FROM functions");
|
||||
return { success: true, data: rows };
|
||||
};
|
||||
|
||||
export const updateFunctionStatus = async (functionName, active) => {
|
||||
const [result] = await pool.query(
|
||||
"UPDATE functions SET active = ? WHERE function_name = ?",
|
||||
[active, functionName],
|
||||
);
|
||||
if (result.affectedRows > 0) return { success: true };
|
||||
return { success: false };
|
||||
};
|
||||
@@ -0,0 +1,50 @@
|
||||
import express from "express";
|
||||
import { authenticateAdmin } from "../../services/authentication.js";
|
||||
const router = express.Router();
|
||||
import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
|
||||
// database funcs import
|
||||
import {
|
||||
getAllFunctions,
|
||||
updateFunctionStatus,
|
||||
} from "./database/serverConfMgmt.database.js";
|
||||
|
||||
// Route to get all functions and their statuses
|
||||
router.get("/all", async (req, res) => {
|
||||
try {
|
||||
const result = await getAllFunctions();
|
||||
if (result.success) {
|
||||
res.status(200).json({ data: result.data });
|
||||
} else {
|
||||
res.status(500).json({ message: "Failed to fetch functions" });
|
||||
}
|
||||
} catch (error) {
|
||||
res
|
||||
.status(500)
|
||||
.json({ message: "An error occurred", error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Route to update the status of a function
|
||||
router.post("/update", async (req, res) => {
|
||||
const functionName = req.query.functionName;
|
||||
let active = req.query.active;
|
||||
|
||||
if (active === "false") {
|
||||
active = 0;
|
||||
} else if (active === "true") {
|
||||
active = 1;
|
||||
} else {
|
||||
res.status(406).json({ message: "Got unexpected format" });
|
||||
}
|
||||
|
||||
const result = await updateFunctionStatus(functionName, active);
|
||||
if (result.success) {
|
||||
res.status(200).json({ message: "Function status updated successfully" });
|
||||
} else {
|
||||
res.status(500).json({ message: "Failed to update function status" });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -5,7 +5,7 @@ const router = express.Router();
|
||||
import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
|
||||
const loan_service = loan_service;
|
||||
const loan_service = "Loan Service";
|
||||
|
||||
import {
|
||||
getItemsFromDatabaseV2,
|
||||
|
||||
@@ -14,6 +14,7 @@ import loanDataMgmtRouter from "./routes/admin/loanDataMgmt.route.js";
|
||||
import itemDataMgmtRouter from "./routes/admin/itemDataMgmt.route.js";
|
||||
import apiDataMgmtRouter from "./routes/admin/apiDataMgmt.route.js";
|
||||
import userMgmtRouterADMIN from "./routes/admin/userMgmt.route.js";
|
||||
import serverConfMgmtRouter from "./routes/admin/serverConfMgmt.route.js";
|
||||
|
||||
// API routes
|
||||
import apiRouter from "./routes/api/api.route.js";
|
||||
@@ -38,6 +39,7 @@ app.use("/api/admin/user-data", userDataMgmtRouter);
|
||||
app.use("/api/admin/item-data", itemDataMgmtRouter);
|
||||
app.use("/api/admin/api-data", apiDataMgmtRouter);
|
||||
app.use("/api/admin/user-mgmt", userMgmtRouterADMIN);
|
||||
app.use("/api/admin/server-config", serverConfMgmtRouter);
|
||||
|
||||
// API routes
|
||||
app.use("/api", apiRouter);
|
||||
|
||||
Reference in New Issue
Block a user