Files
support_backend/src/modules/ai-support/knowledge/routes/knowledge.routes.ts
T
saqib mirandClaude Sonnet 5 7948182988 feat(012-admin-list-views): add GET /admin/products/:id/knowledge for governance
Follow-up to 012-admin-list-views, discovered while building supporthub-
web's own knowledge-governance screen (001-agent-admin-ui User Story 7):
GET /knowledge/retrieve only ever returns published entries (its own
AI-consumption purpose), so a governance screen that needs to see and
publish a draft entry had no endpoint to list it. Adds a small
admin-list-views-style read query scoped to the knowledge module itself.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-07 16:35:25 +05:30

88 lines
3.5 KiB
TypeScript

import { FastifyInstance } from 'fastify';
import { requireRole } from '@/modules/identity/auth';
import { knowledgeController, errorCodesController, runbooksController } from '../controller';
/**
* Admin write routes gated by fastify.authenticate + requireRole('ADMIN'), now real
* (010-identity-auth). Reads stay agent-usable (fastify.authenticate only).
* /knowledge/retrieve is intentionally NOT gated — it's a read path the future AI-support
* feature will call, not an admin surface (research.md "Admin endpoint authentication").
*/
export async function knowledgeRoutes(fastify: FastifyInstance): Promise<void> {
fastify.post(
'/admin/products/:externalProductId/knowledge',
{ preHandler: [fastify.authenticate, requireRole('ADMIN')] },
(req, reply) => knowledgeController.create(req, reply),
);
// 012-admin-list-views follow-up: the governance screen's own data source (every status).
fastify.get(
'/admin/products/:externalProductId/knowledge',
{ preHandler: fastify.authenticate },
(req, reply) => knowledgeController.listForGovernance(req, reply),
);
fastify.patch(
'/admin/knowledge/:code/publish',
{ preHandler: [fastify.authenticate, requireRole('ADMIN')] },
(req, reply) => knowledgeController.publish(req, reply),
);
fastify.patch(
'/admin/knowledge/:code/unpublish',
{ preHandler: [fastify.authenticate, requireRole('ADMIN')] },
(req, reply) => knowledgeController.unpublish(req, reply),
);
fastify.patch(
'/admin/knowledge/:code/validate',
{ preHandler: [fastify.authenticate, requireRole('ADMIN')] },
(req, reply) => knowledgeController.validate(req, reply),
);
fastify.put(
'/admin/knowledge/:code',
{ preHandler: [fastify.authenticate, requireRole('ADMIN')] },
(req, reply) => knowledgeController.edit(req, reply),
);
fastify.get(
'/admin/knowledge/:code/versions',
{ preHandler: fastify.authenticate },
(req, reply) => knowledgeController.listVersions(req, reply),
);
fastify.post(
'/admin/products/:externalProductId/error-codes',
{ preHandler: [fastify.authenticate, requireRole('ADMIN')] },
(req, reply) => errorCodesController.createErrorCode(req, reply),
);
fastify.post(
'/admin/products/:externalProductId/known-issues',
{ preHandler: [fastify.authenticate, requireRole('ADMIN')] },
(req, reply) => errorCodesController.createKnownIssue(req, reply),
);
fastify.get(
'/admin/products/:externalProductId/known-issues/by-error-code/:code',
{ preHandler: fastify.authenticate },
(req, reply) => errorCodesController.findByErrorCode(req, reply),
);
fastify.post(
'/admin/products/:externalProductId/runbooks',
{ preHandler: [fastify.authenticate, requireRole('ADMIN')] },
(req, reply) => runbooksController.create(req, reply),
);
fastify.get(
'/admin/products/:externalProductId/runbooks/:key',
{ preHandler: fastify.authenticate },
(req, reply) => runbooksController.getCurrent(req, reply),
);
fastify.put(
'/admin/products/:externalProductId/runbooks/:key',
{ preHandler: [fastify.authenticate, requireRole('ADMIN')] },
(req, reply) => runbooksController.edit(req, reply),
);
fastify.patch(
'/admin/products/:externalProductId/runbooks/:key/deactivate',
{ preHandler: [fastify.authenticate, requireRole('ADMIN')] },
(req, reply) => runbooksController.deactivate(req, reply),
);
fastify.get('/knowledge/retrieve', (req, reply) => knowledgeController.retrieve(req, reply));
}