Skip to content

Commit

Permalink
[PS-1841] Fix org-* commands for CLI (#4013)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
justindbaur committed Nov 8, 2022
1 parent 30f7282 commit c1b25f4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/cli/src/commands/get.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/commands/import.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ImportCommand {
): Promise<Response> {
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(
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/src/commands/list.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down Expand Up @@ -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.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ export abstract class OrganizationService {
get: (id: string) => Organization;
getByIdentifier: (identifier: string) => Organization;
getAll: (userId?: string) => Promise<Organization[]>;
/**
* @deprecated For the CLI only
* @param id id of the organization
*/
getFromState: (id: string) => Promise<Organization>;
canManageSponsorships: () => Promise<boolean>;
hasOrganizations: () => boolean;
}
14 changes: 14 additions & 0 deletions libs/common/src/services/organization/organization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Organization> {
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();

Expand Down

0 comments on commit c1b25f4

Please sign in to comment.