fosrl.pangolin/server/routers/external.ts

59 lines
2.4 KiB
TypeScript
Raw Normal View History

2024-09-27 21:39:03 -04:00
import { Router } from "express";
import * as site from "./site";
import * as org from "./org";
import * as resource from "./resource";
import * as target from "./target";
import * as user from "./user";
import * as auth from "./auth";
import HttpCode from "@server/types/HttpCode";
2024-10-02 23:54:14 -04:00
import { verifySessionMiddleware } from "@server/middlewares";
2024-09-27 21:39:03 -04:00
// Root routes
export const unauthenticated = Router();
2024-09-27 21:39:03 -04:00
unauthenticated.get("/", (_, res) => {
res.status(HttpCode.OK).json({ message: "Healthy" });
2024-09-27 21:39:03 -04:00
});
// Authenticated Root routes
export const authenticated = Router();
2024-10-02 23:54:14 -04:00
authenticated.use(verifySessionMiddleware);
2024-09-28 12:14:44 -04:00
authenticated.put("/org", org.createOrg);
2024-10-02 21:22:17 -04:00
authenticated.get("/orgs", org.listOrgs);
2024-10-02 22:05:21 -04:00
authenticated.get("/org/:orgId", org.getOrg);
authenticated.post("/org/:orgId", org.updateOrg);
authenticated.delete("/org/:orgId", org.deleteOrg);
2024-10-02 22:05:21 -04:00
authenticated.put("/org/:orgId/site", site.createSite);
authenticated.get("/org/:orgId/sites", site.listSites);
authenticated.get("/site/:siteId", site.getSite);
authenticated.post("/site/:siteId", site.updateSite);
authenticated.delete("/site/:siteId", site.deleteSite);
authenticated.put("/org/:orgId/site/:siteId/resource", resource.createResource);
authenticated.get("/site/:siteId/resources", resource.listResources);
authenticated.get("/org/:orgId/resources", resource.listResources);
authenticated.get("/resource/:resourceId", resource.getResource);
authenticated.post("/resource/:resourceId", resource.updateResource);
authenticated.delete("/resource/:resourceId", resource.deleteResource);
2024-10-02 22:05:21 -04:00
authenticated.put("/resource/:resourceId/target", target.createTarget);
authenticated.get("/resource/:resourceId/targets", target.listTargets);
authenticated.get("/target/:targetId", target.getTarget);
authenticated.post("/target/:targetId", target.updateTarget);
authenticated.delete("/target/:targetId", target.deleteTarget);
2024-10-02 21:22:17 -04:00
authenticated.get("/users", user.listUsers);
2024-10-02 22:17:43 -04:00
// authenticated.get("/org/:orgId/users", user.???); // TODO: Implement this
2024-10-02 22:05:21 -04:00
authenticated.get("/user/:userId", user.getUser);
authenticated.delete("/user/:userId", user.deleteUser);
// Auth routes
2024-10-03 20:55:54 -04:00
unauthenticated.put("/auth/signup", auth.signup);
unauthenticated.post("/auth/login", auth.login);
unauthenticated.post("/auth/logout", auth.logout);
authenticated.post("/auth/verify-totp", auth.verifyTotp);
authenticated.post("/auth/request-totp-secret", auth.requestTotpSecret);
authenticated.post("/auth/disable-2fa", auth.disable2fa);