fix: align backend API routes with console frontend contract
Some checks failed
CI — P3 Alert / test (push) Successful in 34s
CI — P4 Portal / test (push) Successful in 37s
CI — P5 Cost / test (push) Successful in 35s
CI — P6 Run / saas (push) Successful in 33s
CI — P5 Cost / build-push (push) Failing after 5s
CI — P6 Run / build-push (push) Failing after 4s
CI — P2 Drift (Go + Node) / agent (push) Successful in 1m5s
CI — P2 Drift (Go + Node) / saas (push) Successful in 37s
CI — P2 Drift (Go + Node) / build-push (push) Failing after 16s
CI — P3 Alert / build-push (push) Failing after 14s
CI — P4 Portal / build-push (push) Failing after 27s

This commit is contained in:
Max
2026-03-03 06:09:41 +00:00
parent 76715d169e
commit 47a64d53fd
8 changed files with 394 additions and 20 deletions

View File

@@ -74,6 +74,30 @@ export async function registerApiRoutes(app: FastifyInstance) {
return reply.send(result);
});
// Get latest report for a stack (console route: GET /api/v1/stacks/:name/report)
app.get('/api/v1/stacks/:name/report', async (request, reply) => {
const tenantId = (request as any).tenantId;
const { name } = request.params as { name: string };
const pool = (app as any).pool;
const result = await withTenant(pool, tenantId, async (client) => {
const { rows } = await client.query(
`SELECT * FROM drift_reports
WHERE tenant_id = $1 AND stack_name = $2
ORDER BY scanned_at DESC
LIMIT 1`,
[tenantId, name]
);
return rows[0] ?? null;
});
if (!result) {
return reply.status(404).send({ error: 'No report found for stack' });
}
return reply.send(result);
});
// Get stack drift history
app.get('/api/v1/stacks/:stackName/history', async (request, reply) => {
const tenantId = (request as any).tenantId;
@@ -96,7 +120,7 @@ export async function registerApiRoutes(app: FastifyInstance) {
return reply.send(result);
});
// Get single drift report
// Get single drift report (legacy route)
app.get('/api/v1/reports/:reportId', async (request, reply) => {
const tenantId = (request as any).tenantId;
const { reportId } = request.params as { reportId: string };