generated from Dicken/dickendock
Reset-Button, Service-Reorder, Port/HTTPS-Spalten, Healthcheck in Sidebar, Kategorien-Sync
This commit is contained in:
34
apps/backend/src/routes/reset.ts
Normal file
34
apps/backend/src/routes/reset.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { FastifyInstance } from "fastify";
|
||||
import * as deviceRepo from "../db/repositories/devices.js";
|
||||
import * as logRepo from "../db/repositories/logs.js";
|
||||
|
||||
/**
|
||||
* Löscht ALLE Geräte und (per FK-Cascade) alle zugehörigen Dienste.
|
||||
* Kategorien und Logs bleiben unangetastet.
|
||||
*
|
||||
* Erfordert { confirm: true } im Body – zusätzlich zur Bestätigung im
|
||||
* Frontend eine zweite Sicherung gegen versehentliche Aufrufe (z. B. per
|
||||
* Skript oder Browser-Erweiterung).
|
||||
*/
|
||||
export async function resetRoutes(app: FastifyInstance): Promise<void> {
|
||||
app.post("/api/reset", async (request, reply) => {
|
||||
const body = request.body as { confirm?: boolean } | undefined;
|
||||
|
||||
if (body?.confirm !== true) {
|
||||
return reply.code(400).send({
|
||||
error: "Bestätigung erforderlich. Bitte { \"confirm\": true } im Body senden.",
|
||||
});
|
||||
}
|
||||
|
||||
const deviceCount = deviceRepo.listDevices().length;
|
||||
const deletedCount = deviceRepo.deleteAllDevices();
|
||||
|
||||
logRepo.logScan({
|
||||
type: "device",
|
||||
level: "info",
|
||||
message: `Reset: ${deletedCount} Gerät(e) und alle zugehörigen Dienste gelöscht`,
|
||||
});
|
||||
|
||||
return { deletedDevices: deletedCount, previousDeviceCount: deviceCount };
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user