Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(schemas): add util method to convert admin tenant org id to user tenant id #5570

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading