This commit is contained in:
2026-02-17 21:53:14 -06:00
parent 6d951e426d
commit 987a1c8a6a
35 changed files with 1539 additions and 39 deletions
+20
View File
@@ -0,0 +1,20 @@
import { createRoute } from "../../modules/api-utils/createRoute";
import { apiResponse } from "../../modules/api-utils/apiResponse";
import { ContentfulStatusCode } from "hono/utils/http-status";
import { authMiddleware } from "../middleware/authorization";
import { PERMISSION_NODES } from "../../types/PermissionNodes";
/* /v1/permissions */
export default createRoute(
"get",
["/"],
async (c) => {
const response = apiResponse.successful(
"Permission Nodes Fetched Successfully!",
PERMISSION_NODES,
);
return c.json(response, response.status as ContentfulStatusCode);
},
authMiddleware({ permissions: ["role.read"] }),
);
+34
View File
@@ -0,0 +1,34 @@
import { createRoute } from "../../modules/api-utils/createRoute";
import { apiResponse } from "../../modules/api-utils/apiResponse";
import { ContentfulStatusCode } from "hono/utils/http-status";
import { authMiddleware } from "../middleware/authorization";
import { PERMISSION_NODES } from "../../types/PermissionNodes";
import GenericError from "../../Errors/GenericError";
/* /v1/permissions/:category */
export default createRoute(
"get",
["/:category"],
async (c) => {
const categoryKey = c.req.param(
"category",
) as keyof typeof PERMISSION_NODES;
if (!(categoryKey in PERMISSION_NODES)) {
throw new GenericError({
name: "NotFound",
message: `Permission category "${categoryKey}" not found`,
status: 404,
cause: `Valid categories: ${Object.keys(PERMISSION_NODES).join(", ")}`,
});
}
const response = apiResponse.successful(
"Permission Category Fetched Successfully!",
PERMISSION_NODES[categoryKey],
);
return c.json(response, response.status as ContentfulStatusCode);
},
authMiddleware({ permissions: ["role.read"] }),
);
+22
View File
@@ -0,0 +1,22 @@
import { createRoute } from "../../modules/api-utils/createRoute";
import { apiResponse } from "../../modules/api-utils/apiResponse";
import { ContentfulStatusCode } from "hono/utils/http-status";
import { authMiddleware } from "../middleware/authorization";
import { getAllPermissionNodes } from "../../types/PermissionNodes";
/* /v1/permissions/nodes */
export default createRoute(
"get",
["/nodes"],
async (c) => {
const allNodes = getAllPermissionNodes();
const response = apiResponse.successful(
"All Permission Nodes Fetched Successfully!",
allNodes,
);
return c.json(response, response.status as ContentfulStatusCode);
},
authMiddleware({ permissions: ["role.read"] }),
);
+5
View File
@@ -0,0 +1,5 @@
import { default as fetchAll } from "./fetchAll";
import { default as fetchByCategory } from "./fetchByCategory";
import { default as fetchNodes } from "./fetchNodes";
export { fetchAll, fetchByCategory, fetchNodes };