31 lines
748 B
TypeScript
31 lines
748 B
TypeScript
import { FastifyInstance } from "fastify";
|
|
import { createTokenHandler, getTokenHandler } from "./token.controller";
|
|
import { $token } from "./token.schema";
|
|
|
|
export async function tokenRoutes(fastify: FastifyInstance) {
|
|
fastify.post(
|
|
"/",
|
|
{
|
|
schema: {
|
|
body: $token("createTokenInput"),
|
|
response: {
|
|
201: $token("createTokenResponse"),
|
|
},
|
|
},
|
|
config: { requiredClaims: ["token:write"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
createTokenHandler
|
|
);
|
|
|
|
fastify.get(
|
|
"/:tokenId",
|
|
{
|
|
schema: { response: { 200: $token("getTokenResponse") } },
|
|
config: { requiredClaims: ["token:read"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
getTokenHandler
|
|
);
|
|
}
|