Skip to content

Commit

Permalink
feat: complete integrations controller
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed Oct 17, 2022
1 parent 0ddf784 commit ea842b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ export class IntegrationsConfigurationController {
private _environmentVariablesService: IntegrationsConfigurationService
) {}

async upsert(key: string, value: string) {
// Check if key exist as we need create/update
// Can't create configuration key with `___`
await this._credentialsService.upsert(key, value);
async upsert(
group: IntegrationsConfigurationGroup,
key: string,
value: string
) {
if (!this.getService(group).hasKey(key) && this.isKeyAGroupKey(key)) {
throw new Error(
"Group keys can't be created. They should be updated in the plugin settings"
);
}
await this.getService(group).upsert(key, value);
}

async delete(group: IntegrationsConfigurationGroup, key: string) {
Expand All @@ -34,10 +41,13 @@ export class IntegrationsConfigurationController {
}

async list(group: IntegrationsConfigurationGroup) {
// return "XXXXX" for keys
// Order by key

const items = await this.getService(group).list();
if (group === IntegrationsConfigurationGroup.Credentials) {
return Object.fromEntries(
Object.keys(items).map((itemKey) => [itemKey, "XXXXXX"])
);
}
return items;
}

private isKeyAGroupKey(key: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/backend/integrations-configurations/services/_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export abstract class IntegrationsConfigurationService
}

async list() {
return await this._persistenceService.getAllItems();
return await this._persistenceService.getAllAsKeyValuePair();
}

async useGroupValue<T extends Record<string, unknown>>(
Expand Down

0 comments on commit ea842b9

Please sign in to comment.