Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

1.1 KB
Raw Blame
import type { OrganizationList, Workspace } from "./schemas.js";

function metadataDescription(metadata: unknown): string | null {
  const parsed =
    typeof metadata === "string"
      ? (() => {
          try {
            return JSON.parse(metadata) as unknown;
          } catch {
            return null;
          }
        })()
      : metadata;
  const description = (parsed as { description?: unknown } | null)?.description;
  return typeof description === "string" && description.trim() !== ""
    ? description
    : null;
}

export function fromOrganizations(
  organizations: OrganizationList,
): Workspace[] {
  return organizations
    .map((organization) => ({
      id: organization.id,
      name: organization.name,
      slug: organization.slug,
      logo: organization.logo ?? null,
      description:
        organization.description?.trim() ||
        metadataDescription(organization.metadata),
      createdAt: String(organization.createdAt),
      role: null,
    }))
    .sort(
      (a, b) =>
        a.name.toLowerCase().localeCompare(b.name.toLowerCase()) ||
        a.id.localeCompare(b.id),
    );
}