- 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)
39 lines
1.2 KiB
TypeScript
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;
|
|
}
|