Resolving polling/server migration

This commit is contained in:
Marcelo
2026-01-15 18:43:21 +00:00
parent f231d87ae3
commit 9f1af71d15
15 changed files with 794 additions and 845 deletions

View File

@@ -1,6 +1,7 @@
// mis-control-tower/app/api/ingest/kpi/route.ts
import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
import { getMachineAuth } from "@/lib/machineAuthCache";
import { normalizeSnapshotV1 } from "@/lib/contracts/v1";
function getClientIp(req: Request) {
@@ -75,10 +76,7 @@ export async function POST(req: Request) {
tsDeviceDate = new Date(body.tsDevice);
// Auth: machineId + apiKey must match
const machine = await prisma.machine.findFirst({
where: { id: machineId, apiKey },
select: { id: true, orgId: true },
});
const machine = await getMachineAuth(machineId, apiKey);
if (!machine) {
await prisma.ingestLog.create({
@@ -165,22 +163,6 @@ export async function POST(req: Request) {
},
});
await prisma.ingestLog.create({
data: {
orgId,
machineId: machine.id,
endpoint,
ok: true,
status: 200,
schemaVersion,
seq,
tsDevice: tsDeviceDate,
body: rawBody,
ip,
userAgent,
},
});
return NextResponse.json({
ok: true,
id: row.id,