From c1b25f438903557b34c0e405bc6f06c5d3eff32e Mon Sep 17 00:00:00 2001 From: Justin Baur <19896123+justindbaur@users.noreply.github.com> Date: Tue, 8 Nov 2022 16:25:19 -0500 Subject: [PATCH] [PS-1841] Fix org-* commands for CLI (#4013) * Add getFromState method * Added a method for CLI to get an org from state * Converted all CLI calls to `.get()` * Used `.getFromState` instead of `.get` * Deprecate getFromState method --- apps/cli/src/commands/get.command.ts | 2 +- apps/cli/src/commands/import.command.ts | 2 +- apps/cli/src/commands/list.command.ts | 4 ++-- .../organization.service.abstraction.ts | 5 +++++ .../services/organization/organization.service.ts | 14 ++++++++++++++ 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/apps/cli/src/commands/get.command.ts b/apps/cli/src/commands/get.command.ts index fb08ce0656..d2ca9edbd4 100644 --- a/apps/cli/src/commands/get.command.ts +++ b/apps/cli/src/commands/get.command.ts @@ -436,7 +436,7 @@ export class GetCommand extends DownloadCommand { private async getOrganization(id: string) { let org: Organization = null; if (Utils.isGuid(id)) { - org = await this.organizationService.get(id); + org = await this.organizationService.getFromState(id); } else if (id.trim() !== "") { let orgs = await this.organizationService.getAll(); orgs = CliUtils.searchOrganizations(orgs, id); diff --git a/apps/cli/src/commands/import.command.ts b/apps/cli/src/commands/import.command.ts index 6fb17fa2cd..fcb2e215bb 100644 --- a/apps/cli/src/commands/import.command.ts +++ b/apps/cli/src/commands/import.command.ts @@ -23,7 +23,7 @@ export class ImportCommand { ): Promise { const organizationId = options.organizationid; if (organizationId != null) { - const organization = await this.organizationService.get(organizationId); + const organization = await this.organizationService.getFromState(organizationId); if (organization == null) { return Response.badRequest( diff --git a/apps/cli/src/commands/list.command.ts b/apps/cli/src/commands/list.command.ts index 250237a787..5322026284 100644 --- a/apps/cli/src/commands/list.command.ts +++ b/apps/cli/src/commands/list.command.ts @@ -163,7 +163,7 @@ export class ListCommand { if (!Utils.isGuid(options.organizationId)) { return Response.badRequest("`" + options.organizationId + "` is not a GUID."); } - const organization = await this.organizationService.get(options.organizationId); + const organization = await this.organizationService.getFromState(options.organizationId); if (organization == null) { return Response.error("Organization not found."); } @@ -196,7 +196,7 @@ export class ListCommand { if (!Utils.isGuid(options.organizationId)) { return Response.badRequest("`" + options.organizationId + "` is not a GUID."); } - const organization = await this.organizationService.get(options.organizationId); + const organization = await this.organizationService.getFromState(options.organizationId); if (organization == null) { return Response.error("Organization not found."); } diff --git a/libs/common/src/abstractions/organization/organization.service.abstraction.ts b/libs/common/src/abstractions/organization/organization.service.abstraction.ts index ebdd3bdf90..3dfeb90cb0 100644 --- a/libs/common/src/abstractions/organization/organization.service.abstraction.ts +++ b/libs/common/src/abstractions/organization/organization.service.abstraction.ts @@ -75,6 +75,11 @@ export abstract class OrganizationService { get: (id: string) => Organization; getByIdentifier: (identifier: string) => Organization; getAll: (userId?: string) => Promise; + /** + * @deprecated For the CLI only + * @param id id of the organization + */ + getFromState: (id: string) => Promise; canManageSponsorships: () => Promise; hasOrganizations: () => boolean; } diff --git a/libs/common/src/services/organization/organization.service.ts b/libs/common/src/services/organization/organization.service.ts index 9d9a7d5734..101069adad 100644 --- a/libs/common/src/services/organization/organization.service.ts +++ b/libs/common/src/services/organization/organization.service.ts @@ -101,6 +101,20 @@ export class OrganizationService implements OrganizationServiceAbstraction { return organizations.find((organization) => organization.id === id); } + /** + * @deprecated For the CLI only + * @param id id of the organization + */ + async getFromState(id: string): Promise { + const organizationsMap = await this.stateService.getOrganizations(); + const organization = organizationsMap[id]; + if (organization == null) { + return null; + } + + return new Organization(organization); + } + getByIdentifier(identifier: string): Organization { const organizations = this._organizations.getValue();