import { FastifyInstance } from "fastify"; import { $rts } from "./rts.schema"; import { createRtsHandler, deleteRtsHandler, getRtsHandler, listRtsHandler, newFilesHandler, updateRtsHandler, } from "./rts.controller"; import { hideFields } from "../auth"; import { noteRoutes } from "../note/note.route"; 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 ); await noteRoutes(fastify, { read: "rts:read", write: "rts:write", delete: "rts:delete", }); fastify.addHook("onSend", hideFields("rts")); }