Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

refactor(sub-org): use typed enums for orderBy and orderDirection

Igor Correaed4dafb5863b
diff --git a/backend/src/ee/routes/v1/sub-org-router.ts b/backend/src/ee/routes/v1/sub-org-router.ts
index 7c56934a53..6d5629a8c7 100644
--- a/backend/src/ee/routes/v1/sub-org-router.ts
+++ b/backend/src/ee/routes/v1/sub-org-router.ts
@@ -2,8 +2,10 @@ import { z } from "zod";
import { OrganizationsSchema } from "@app/db/schemas";
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
+import { SubOrgOrderBy } from "@app/ee/services/sub-org/sub-org-types";
import { ApiDocsTags, SUB_ORGANIZATIONS } from "@app/lib/api-docs";
import { pick } from "@app/lib/fn";
+import { OrderByDirection } from "@app/lib/types";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { GenericResourceNameSchema, slugSchema } from "@app/server/lib/schemas";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
@@ -89,8 +91,8 @@ export const registerSubOrgRouter = async (server: FastifyZodProvider) => {
limit: z.coerce.number().min(1).max(1000).default(25).describe(SUB_ORGANIZATIONS.LIST.limit),
offset: z.coerce.number().min(0).default(0).describe(SUB_ORGANIZATIONS.LIST.offset),
search: z.string().trim().optional().describe(SUB_ORGANIZATIONS.LIST.search),
- orderBy: z.enum(["name"]).default("name").describe(SUB_ORGANIZATIONS.LIST.orderBy),
- orderDirection: z.enum(["asc", "desc"]).default("asc").describe(SUB_ORGANIZATIONS.LIST.orderDirection),
+ orderBy: z.nativeEnum(SubOrgOrderBy).default(SubOrgOrderBy.Name).describe(SUB_ORGANIZATIONS.LIST.orderBy),
+ orderDirection: z.nativeEnum(OrderByDirection).default(OrderByDirection.ASC).describe(SUB_ORGANIZATIONS.LIST.orderDirection),
isAccessible: z
.enum(["true", "false"])
.optional()
diff --git a/backend/src/ee/services/sub-org/sub-org-types.ts b/backend/src/ee/services/sub-org/sub-org-types.ts
index a522c095d3..9bae5f8ecd 100644
--- a/backend/src/ee/services/sub-org/sub-org-types.ts
+++ b/backend/src/ee/services/sub-org/sub-org-types.ts
@@ -1,4 +1,8 @@
-import { OrgServiceActor } from "@app/lib/types";
+import { OrderByDirection, OrgServiceActor } from "@app/lib/types";
+
+export enum SubOrgOrderBy {
+ Name = "name"
+}
export type TCreateSubOrgDTO = {
name: string;
@@ -12,8 +16,8 @@ export type TListSubOrgDTO = {
limit?: number;
offset?: number;
search?: string;
- orderBy?: string;
- orderDirection?: "asc" | "desc";
+ orderBy?: SubOrgOrderBy;
+ orderDirection?: OrderByDirection;
isAccessible?: boolean;
}>;
};
diff --git a/backend/src/services/org/org-dal.ts b/backend/src/services/org/org-dal.ts
index 6f0e2c2788..572beea206 100644
--- a/backend/src/services/org/org-dal.ts
+++ b/backend/src/services/org/org-dal.ts
@@ -26,6 +26,7 @@ import {
withTransaction
} from "@app/lib/knex";
import { generateKnexQueryFromScim } from "@app/lib/knex/scim";
+import { OrderByDirection } from "@app/lib/types";
import { ActorType } from "../auth/auth-type";
import { OrgAuthMethod, TOrgWithSubOrgs } from "./org-types";
@@ -164,7 +165,7 @@ export const orgDALFactory = (db: TDbClient) => {
isAccessible?: boolean;
search?: string;
orderBy?: string;
- orderDirection?: "asc" | "desc";
+ orderDirection?: OrderByDirection;
limit?: number;
offset?: number;
}) => {