feat: add entry removal and row saving functionality, enhance admin components with localization

This commit is contained in:
2025-08-13 21:48:19 +02:00
parent 5792ce154f
commit 3096e4ab83
8 changed files with 254 additions and 45 deletions

View File

@@ -6,6 +6,8 @@ import {
loginAdmin,
getTableData,
createEntry,
removeEntries,
saveRow,
} from "./services/database.js";
import { generateToken, authenticate } from "./services/tokenService.js";
env.config();
@@ -30,6 +32,22 @@ app.post("/lose", async (req, res) => {
}
});
// !!!!!!! AUTHORISATION HINZUFÜGEN - DENN GEHT NICHT !!!!!!!!
app.get("/table-data", authenticate, async (req, res) => {
const result = await getTableData();
if (result.success) {
@@ -48,6 +66,24 @@ app.post("/create-entry", async (req, res) => {
}
});
app.delete("/remove-entries", async (req, res) => {
const result = await removeEntries(req.body.losnummern);
if (result) {
res.status(200).json({ success: true });
} else {
res.status(400).json({ success: false });
}
});
app.put("/save-row", async (req, res) => {
const result = await saveRow(req.body);
if (result.success) {
res.status(200).json({ success: true });
} else {
res.status(400).json({ success: false });
}
});
app.post("/login", async (req, res) => {
const { username, password } = req.body;
const result = await loginAdmin(username, password);

View File

@@ -51,8 +51,6 @@ export async function getTableData() {
return { success: false };
}
// Create data from array not working !!!
export async function createEntry(data) {
let { status } = { status: true };
for (const item of data) {
@@ -71,3 +69,42 @@ export async function createEntry(data) {
return status;
}
export async function removeEntries(losnummern) {
let { status } = { status: true };
for (const losnummer of losnummern) {
const [result] = await pool.query("DELETE FROM lose WHERE losnummer = ?", [
losnummer,
]);
if (result.affectedRows > 0) {
status = true;
} else {
status = false;
break;
}
}
return status;
}
export async function saveRow(payload) {
const [result] = await pool.query(
"UPDATE lose SET vorname = ?, nachname = ?, adresse = ?, plz = ?, email = ? WHERE losnummer = ?",
[
payload.vorname,
payload.nachname,
payload.adresse,
payload.plz,
payload.email,
payload.losnummer,
]
);
if (result.affectedRows > 0) {
return { success: true };
} else {
return { success: false };
}
}