feat: enhance token handling in removeSelection and saveRow functions
This commit is contained in:
@@ -8,6 +8,8 @@ import {
|
||||
createEntry,
|
||||
removeEntries,
|
||||
saveRow,
|
||||
resetData,
|
||||
getVitals,
|
||||
} from "./services/database.js";
|
||||
import { generateToken, authenticate } from "./services/tokenService.js";
|
||||
env.config();
|
||||
@@ -37,8 +39,10 @@ app.post("/lose", async (req, res) => {
|
||||
|
||||
app.get("/table-data", authenticate, async (req, res) => {
|
||||
const result = await getTableData();
|
||||
if (result.success) {
|
||||
if (result.success && result.data) {
|
||||
res.status(200).json(result.data);
|
||||
} else if (result.success && !result.data) {
|
||||
res.status(204).json({ success: true });
|
||||
} else {
|
||||
res.status(500).json({ success: false });
|
||||
}
|
||||
@@ -87,6 +91,15 @@ app.post("/login", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
app.delete("/reset-data", authenticate, async (req, res) => {
|
||||
const result = await resetData();
|
||||
if (result.success) {
|
||||
res.status(200).json({ success: true });
|
||||
} else {
|
||||
res.status(400).json({ success: false });
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server is running on port: ${port}`);
|
||||
});
|
||||
|
Reference in New Issue
Block a user