nexus/server/src/routes/nexus-settings.ts
Nexus Dev 86e30e5c69 feat(30-01): hardware and nexus-settings routes, app.ts mounting
- Add hardwareRoutes with unauthenticated GET /system/providers
- Add hardwareRoutes with GET /system/providers/recommendation
- Add nexusSettingsRoutes with board-auth GET/PATCH /nexus/settings
- Mount hardwareRoutes on app before boardMutationGuard (unauthenticated)
- Mount nexusSettingsRoutes on api router (board-auth gated)
2026-04-02 23:22:20 +00:00

39 lines
1.2 KiB
TypeScript

import { Router } from "express";
import { assertBoard } from "./authz.js";
import { nexusSettingsService } from "../services/nexus-settings.js";
export function nexusSettingsRoutes(): Router {
const router = Router();
router.get("/nexus/settings", async (req, res) => {
try {
assertBoard(req);
const settings = await nexusSettingsService().get();
res.json(settings);
} catch (err: unknown) {
if (err && typeof err === "object" && "status" in err) {
const e = err as { status: number; message: string };
res.status(e.status).json({ error: e.message });
return;
}
res.status(500).json({ error: "Unexpected error" });
}
});
router.patch("/nexus/settings", async (req, res) => {
try {
assertBoard(req);
const updated = await nexusSettingsService().set(req.body);
res.json(updated);
} catch (err: unknown) {
if (err && typeof err === "object" && "status" in err) {
const e = err as { status: number; message: string };
res.status(e.status).json({ error: e.message });
return;
}
res.status(500).json({ error: "Unexpected error" });
}
});
return router;
}