Skip to content

Commit

Permalink
feat(schemas): add util method to convert admin tenant org id to user…
Browse files Browse the repository at this point in the history
… tenant id
  • Loading branch information
charIeszhao committed Mar 28, 2024
1 parent 2ccc54a commit fd72332
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/schemas/src/types/tenant-organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ import { adminTenantId } from '../seeds/tenant.js';
/** Given a tenant ID, return the corresponding organization ID in the admin tenant. */
export const getTenantOrganizationId = (tenantId: string) => `t-${tenantId}`;

/** Given an admin tenant organization ID, check the format and return the corresponding user tenant ID. */
export const getTenantIdFromOrganizationId = (organizationId: string) => {
if (!organizationId.startsWith('t-')) {
throw new Error(`Invalid admin tenant organization ID: ${organizationId}`);
}

return organizationId.slice(2);
};

/**
* Given a tenant ID, return the organization create data for the admin tenant. It follows a
* convention to generate the organization ID and name which can be used across the system.
Expand Down

0 comments on commit fd72332

Please sign in to comment.