feat(ADM-018): completed feature
This commit is contained in:
25
project/src/modules/cache/api/cache.routes.ts
vendored
Normal file
25
project/src/modules/cache/api/cache.routes.ts
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import type { FastifyInstance } from 'fastify';
|
||||
import type { Authenticate } from '../../../shared/auth.js';
|
||||
import { requireRole } from '../../../shared/auth.js';
|
||||
import { CacheService } from '../application/cache-service.js';
|
||||
|
||||
export interface CacheRoutesDeps {
|
||||
cache: CacheService;
|
||||
authenticate: Authenticate;
|
||||
}
|
||||
|
||||
export async function registerCacheRoutes(
|
||||
app: FastifyInstance,
|
||||
deps: CacheRoutesDeps,
|
||||
): Promise<void> {
|
||||
app.get('/cache/contracts', async (request, reply) => {
|
||||
const user = await deps.authenticate(request);
|
||||
requireRole(user, 'admin');
|
||||
return reply.send({ items: deps.cache.listContracts() });
|
||||
});
|
||||
|
||||
app.get('/cache/metrics', async (request, reply) => {
|
||||
await deps.authenticate(request);
|
||||
return reply.send(deps.cache.metrics());
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user