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

@@ -61,7 +61,44 @@ export function registerServiceRoutes(app: FastifyInstance) {
return { service: result.rows[0] };
});
// Create/update service (manual entry)
// Create service (console route: POST /api/v1/services)
app.post('/api/v1/services', async (req, reply) => {
const body = upsertServiceSchema.parse(req.body);
const tenantId = (req as any).tenantId;
const result = await withTenant(tenantId, async (client) => {
return client.query(
`INSERT INTO services (tenant_id, name, type, owner, owner_source, description, tier, lifecycle, links, tags)
VALUES ($1, $2, $3, $4, 'config', $5, $6, $7, $8, $9)
RETURNING *`,
[tenantId, body.name, body.type, body.owner, body.description, body.tier, body.lifecycle, JSON.stringify(body.links), JSON.stringify(body.tags)],
);
});
return reply.status(201).send({ service: result.rows[0] });
});
// Update service by id (console route: PUT /api/v1/services/:id)
app.put('/api/v1/services/:id', async (req, reply) => {
const { id } = req.params as { id: string };
const body = upsertServiceSchema.parse(req.body);
const tenantId = (req as any).tenantId;
const result = await withTenant(tenantId, async (client) => {
return client.query(
`UPDATE services SET name = $1, type = $2, owner = $3, owner_source = 'config',
description = $4, tier = $5, lifecycle = $6, links = $7, tags = $8, updated_at = now()
WHERE id = $9 AND tenant_id = $10
RETURNING *`,
[body.name, body.type, body.owner, body.description, body.tier, body.lifecycle, JSON.stringify(body.links), JSON.stringify(body.tags), id, tenantId],
);
});
if (!result.rows[0]) return reply.status(404).send({ error: 'Not found' });
return { service: result.rows[0] };
});
// Create/update service via upsert (legacy route)
app.put('/api/v1/services', async (req, reply) => {
const body = upsertServiceSchema.parse(req.body);
const tenantId = (req as any).tenantId;