created backend to create lottery entries manually
This commit is contained in:
@@ -1,7 +1,12 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import env from "dotenv";
|
import env from "dotenv";
|
||||||
import { query, loginAdmin, getTableData } from "./services/database.js";
|
import {
|
||||||
|
query,
|
||||||
|
loginAdmin,
|
||||||
|
getTableData,
|
||||||
|
createEntry,
|
||||||
|
} from "./services/database.js";
|
||||||
import { generateToken, authenticate } from "./services/tokenService.js";
|
import { generateToken, authenticate } from "./services/tokenService.js";
|
||||||
env.config();
|
env.config();
|
||||||
const app = express();
|
const app = express();
|
||||||
@@ -30,7 +35,16 @@ app.get("/table-data", authenticate, async (req, res) => {
|
|||||||
if (result.success) {
|
if (result.success) {
|
||||||
res.status(200).json(result.data);
|
res.status(200).json(result.data);
|
||||||
} else {
|
} else {
|
||||||
res.status(500);
|
res.status(500).json({ success: false });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post("/create-entry", async (req, res) => {
|
||||||
|
const result = await createEntry(req.body);
|
||||||
|
if (result.success) {
|
||||||
|
res.status(201).json({ success: true });
|
||||||
|
} else {
|
||||||
|
res.status(400).json({ success: false });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -50,3 +50,19 @@ export async function getTableData() {
|
|||||||
}
|
}
|
||||||
return { success: false };
|
return { success: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function createEntryCSV(file) {
|
||||||
|
// Implement CSV creation logic here
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createEntry(data) {
|
||||||
|
const [result] = await pool.query("INSERT INTO lose (losnummer) VALUES (?)", [
|
||||||
|
data.losnummer,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (result.affectedRows > 0) {
|
||||||
|
return { success: true };
|
||||||
|
} else {
|
||||||
|
return { success: false };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user