Skip to content

Commit

Permalink
Feat(projects show): Always show org-id, and show name of user when o…
Browse files Browse the repository at this point in the history
…rg is the personal account. (#261)
  • Loading branch information
arnauorriols authored Feb 16, 2024
1 parent 6dce4af commit 53c34a3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
14 changes: 11 additions & 3 deletions src/subcommands/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,21 @@ async function showProject(args: Args): Promise<void> {
);
return Deno.exit(1);
}
const organizationName = project.organization.name
? magenta(project.organization.name)
: `${
magenta(
// If project exists, organization must also exist
(await api.getOrganizationById(project.organization.id))!.members[0]
.user
.name,
)
} [personal]`;
spinner.succeed(`Project '${args.project}' found`);
console.log();
console.log(bold(green(project.name)));
console.log(new Array(project.name.length).fill("-").join(""));
if (project.organization.name) {
console.log(`Organization:\t${magenta(project.organization.name)}`);
}
console.log(`Organization:\t${organizationName} (${project.organizationId})`);
const ingress_root = new URL(endpoint()).hostname.split(".").at(-2);
domains.push({
domain: `${project.name}.${ingress_root}.dev`,
Expand Down
4 changes: 4 additions & 0 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ export class API {
}
}

async getOrganizationById(id: string): Promise<Organization | undefined> {
return await this.#requestJson(`/organizations/${id}`);
}

async createOrganization(name: string): Promise<Organization> {
const body = { name };
return await this.#requestJson(
Expand Down
19 changes: 15 additions & 4 deletions src/utils/api_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,24 @@ export interface Project {

export type Organization = UserOrganization | NormalOrganization;

export interface UserOrganization {
id: string;
export type UserOrganization = CommonOrganization & {
name: null;
}
};

export type NormalOrganization = CommonOrganization & {
name: string;
};

export interface NormalOrganization {
export interface CommonOrganization {
id: string;
members: OrganizationMember[];
}

export interface OrganizationMember {
user: User;
}

export interface User {
name: string;
}

Expand Down

0 comments on commit 53c34a3

Please sign in to comment.