phase 2 and 3

This commit is contained in:
jason
2026-04-21 08:56:51 -05:00
parent b98837a72c
commit d79aaf6ef8
42 changed files with 4962 additions and 19 deletions
+46
View File
@@ -0,0 +1,46 @@
import { type NextRequest } from "next/server";
import { prisma } from "@/lib/prisma";
import { ok, errorResponse, requireRole, parseJson } from "@/lib/api";
import { CreateMachineSchema } from "@/lib/schemas";
import { audit } from "@/lib/audit";
import { clientIp } from "@/lib/request";
export async function GET(req: NextRequest) {
try {
await requireRole("admin");
const includeInactive = req.nextUrl.searchParams.get("includeInactive") === "1";
const machines = await prisma.machine.findMany({
where: includeInactive ? undefined : { active: true },
orderBy: [{ active: "desc" }, { name: "asc" }],
});
return ok({ machines });
} catch (err) {
return errorResponse(err);
}
}
export async function POST(req: NextRequest) {
try {
const actor = await requireRole("admin");
const body = await parseJson(req, CreateMachineSchema);
const created = await prisma.machine.create({
data: {
name: body.name,
kind: body.kind,
location: body.location ?? null,
notes: body.notes ?? null,
},
});
await audit({
actorId: actor.id,
action: "create",
entity: "Machine",
entityId: created.id,
after: created,
ipAddress: clientIp(req),
});
return ok({ machine: created }, { status: 201 });
} catch (err) {
return errorResponse(err);
}
}