add view routes

This commit is contained in:
2025-03-04 11:35:52 +05:30
parent da5e67e0cd
commit a8d336ca4e
6 changed files with 239 additions and 6 deletions

View File

@@ -0,0 +1,87 @@
import { FastifyInstance } from "fastify";
import {
createViewHandler,
deleteViewHandler,
getViewHandler,
listViewHandler,
updateViewHandler,
} from "./view.controller";
import { $view } from "./view.schema";
export async function viewRoutes(fastify: FastifyInstance) {
fastify.post(
"/",
{
schema: {
body: $view("createViewInput"),
},
config: { requiredClaims: ["view:write"] },
preHandler: [fastify.authorize],
},
createViewHandler
);
fastify.get(
"/",
{
schema: {
querystring: $view("pageQueryParams"),
},
config: { requiredClaims: ["view:read"] },
preHandler: [fastify.authorize],
},
listViewHandler
);
fastify.get(
"/:viewId",
{
schema: {
params: {
type: "object",
properties: {
viewId: { type: "string" },
},
},
},
config: { requiredClaims: ["view:read"] },
preHandler: [fastify.authorize],
},
getViewHandler
);
fastify.patch(
"/:viewId",
{
schema: {
params: {
type: "object",
properties: {
viewId: { type: "string" },
},
},
body: $view("updateViewInput"),
},
config: { requiredClaims: ["view:write"] },
preHandler: [fastify.authorize],
},
updateViewHandler
);
fastify.delete(
"/:viewId",
{
schema: {
params: {
type: "object",
properties: {
viewId: { type: "string" },
},
},
},
config: { requiredClaims: ["view:delete"] },
preHandler: [fastify.authorize],
},
deleteViewHandler
);
}