Add pagination, complete organization routes

This commit is contained in:
2024-12-20 23:14:32 +05:30
parent a584fc91b5
commit cc2665544b
6 changed files with 190 additions and 6 deletions

View File

@@ -1,6 +1,12 @@
import { FastifyInstance } from "fastify";
import { $org } from "./organization.schema";
import { createOrgHandler, getOrgHandler } from "./organization.controller";
import {
createOrgHandler,
deleteOrgHandler,
getOrgHandler,
listOrgsHandler,
updateOrgHandler,
} from "./organization.controller";
export default function organizationRoutes(fastify: FastifyInstance) {
fastify.post(
@@ -33,4 +39,43 @@ export default function organizationRoutes(fastify: FastifyInstance) {
},
getOrgHandler
);
fastify.get(
"/",
{
schema: {
querystring: $org("pageQueryParams"),
response: { 200: $org("listOrgResponse") },
},
config: { requiredClaims: ["org:read"] },
preHandler: [fastify.authorize],
},
listOrgsHandler
);
fastify.patch(
"/:orgId",
{
schema: {
params: { type: "object", properties: { orgId: { type: "string" } } },
body: $org("updateOrgInput"),
response: {
200: $org("createOrgResponse"),
},
},
},
updateOrgHandler
);
fastify.delete(
"/:orgId",
{
schema: {
params: { type: "object", properties: { orgId: { type: "string" } } },
},
config: { requiredClaims: ["org:delete"] },
preHandler: [fastify.authorize],
},
deleteOrgHandler
);
}