add rts routes

This commit is contained in:
2025-01-21 11:54:09 +05:30
parent 7e3218f84e
commit a54541518c
15 changed files with 653 additions and 28 deletions

98
src/rts/rts.route.ts Normal file
View File

@@ -0,0 +1,98 @@
import { FastifyInstance } from "fastify";
import { $rts } from "./rts.schema";
import {
createRtsHandler,
deleteRtsHandler,
getRtsHandler,
listRtsHandler,
newFilesHandler,
updateRtsHandler,
} from "./rts.controller";
import { hideFields } from "../auth";
export async function rtsRoutes(fastify: FastifyInstance) {
fastify.post(
"/",
{
schema: {
body: $rts("rtsCreateInput"),
},
config: { requiredClaims: ["rts:write"] },
preHandler: [fastify.authorize],
},
createRtsHandler
);
fastify.get(
"/:rtsId",
{
schema: {
params: {
type: "object",
properties: {
rtsId: { type: "string" },
},
},
},
config: { requiredClaims: ["rts:read"] },
preHandler: [fastify.authorize],
},
getRtsHandler
);
fastify.get(
"/",
{
schema: {
querystring: $rts("pageQueryParams"),
},
config: { requiredClaims: ["rts:read"] },
preHandler: [fastify.authorize],
},
listRtsHandler
);
fastify.patch(
"/:rtsId",
{
schema: {
params: {
type: "object",
properties: { rtsId: { type: "string" } },
},
body: $rts("rtsUpdateInput"),
},
},
updateRtsHandler
);
fastify.delete(
"/:rtsId",
{
schema: {
params: {
type: "object",
properties: { rtsId: { type: "string" } },
},
},
config: { requiredClaims: ["rts:delete"] },
preHandler: [fastify.authorize],
},
deleteRtsHandler
);
fastify.post(
"/:rtsId/files",
{
schema: {
body: $rts("rtsNewUpload"),
},
config: { requiredClaims: ["rts:write"] },
preHandler: [fastify.authorize],
},
newFilesHandler
);
fastify.addHook("onSend", hideFields("rts"));
}