feat: add user confirmation functionality and dynamic table creation; enhance MainForm with user selection and next ID display
This commit is contained in:
@@ -22,4 +22,59 @@ export const getUser = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
export const confirmUser = async (username) => {
|
||||
const [rows] = await pool.query("SELECT * FROM usersNEW WHERE username = ?", [
|
||||
username,
|
||||
]);
|
||||
|
||||
if (rows.length > 0) {
|
||||
// creating userTicketTable
|
||||
const d = new Date();
|
||||
|
||||
const day = d.getDate();
|
||||
const month = d.getMonth() + 1;
|
||||
const year = d.getFullYear();
|
||||
const date = `${day}_${month}_${year}`;
|
||||
const tableName = `${username}_${date}`;
|
||||
|
||||
console.log(tableName);
|
||||
|
||||
const [createTable] = await pool.query(
|
||||
`CREATE TABLE IF NOT EXISTS ${tableName} (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
Vorname VARCHAR(100) NOT NULL,
|
||||
Nachname Varchar(100) NOT NULL,
|
||||
EMail Varchar(100) NOT NULL,
|
||||
Telefonnummer Varchar(100) NOT NULL,
|
||||
Lose INT NOT NULL,
|
||||
Firmenname Varchar(100),
|
||||
Vorname_Geschaeftlich Varchar(100),
|
||||
Nachname_Geschaeftlich Varchar(100),
|
||||
EMail_Geschaeftlich Varchar(100),
|
||||
Telefonnummer_Geschaeftlich Varchar(100),
|
||||
Strasse_Hausnr Varchar(100),
|
||||
Plz_Ort Varchar(100),
|
||||
Zahlungsmethode Varchar(100),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)`
|
||||
);
|
||||
|
||||
if (createTable) {
|
||||
let nextID;
|
||||
const getNextID = async () => {
|
||||
const [rows] = await pool.query(
|
||||
`SELECT id FROM ${tableName} ORDER BY id DESC LIMIT 1`
|
||||
);
|
||||
nextID = rows.length > 0 ? rows[0].id + 1 : 1;
|
||||
};
|
||||
await getNextID();
|
||||
return { success: true, nextID };
|
||||
} else {
|
||||
return { success: false, message: "Table creation failed" };
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const confirmData = async (data) => {};
|
||||
|
||||
@@ -3,7 +3,7 @@ import dotenv from "dotenv";
|
||||
const router = express.Router();
|
||||
dotenv.config();
|
||||
|
||||
import { getUser, confirmData } from "./frontend.data.js";
|
||||
import { getUser, confirmData, confirmUser } from "./frontend.data.js";
|
||||
|
||||
router.post("/frontend", async (req, res) => {
|
||||
const result = await confirmData(req.body);
|
||||
@@ -11,7 +11,6 @@ router.post("/frontend", async (req, res) => {
|
||||
return res.status(500).json({ message: "Form Data Invalid" });
|
||||
}
|
||||
console.log(req.body);
|
||||
const user = await getUser(req.body.code);
|
||||
console.log(user);
|
||||
res.sendStatus(204);
|
||||
});
|
||||
@@ -21,4 +20,16 @@ router.get("/users", async (req, res) => {
|
||||
res.json(users);
|
||||
});
|
||||
|
||||
router.get("/confirm-user", async (req, res) => {
|
||||
const username = req.query.username;
|
||||
if (!username) {
|
||||
return res.status(400).json({ message: "Username is required" });
|
||||
}
|
||||
const user = await confirmUser(username);
|
||||
if (!user) {
|
||||
return res.status(404).json({ message: "User not found" });
|
||||
}
|
||||
res.json(user);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user