Skip to content

Commit

Permalink
improve variable and method names for retrieving dataStores
Browse files Browse the repository at this point in the history
  • Loading branch information
eperedo committed Sep 4, 2024
1 parent 36c40cf commit 36e769a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/data/common/D2ApiDataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ export class D2ApiDataStore {
this.api = getD2APiFromInstance(instance);
}

async getDataStore(filter: { namespaces?: string[] }): Promise<DataStore[]> {
async getDataStores(filter: { namespaces?: string[] }): Promise<DataStore[]> {
const response = await this.api.request<string[]>({ method: "get", url: "/dataStore" }).getData();
const namespacesWithKeys = await this.getAllKeysFromNamespaces(
filter.namespaces
? response
: DataStoreMetadata.getDataStoreIds(filter.namespaces || []).map(ns => {
? DataStoreMetadata.getDataStoreIds(filter.namespaces || []).map(ns => {
const [namespace] = ns.split(DataStoreMetadata.NS_SEPARATOR);
return namespace;
})
: response
);
return namespacesWithKeys;
}
Expand Down
8 changes: 4 additions & 4 deletions src/data/metadata/MetadataD2ApiRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class MetadataD2ApiRepository implements MetadataRepository {
);

if (dataStoreIds.length > 0) {
metadataPackage.dataStores = await d2ApiDataStore.getDataStore({ namespaces: ids });
metadataPackage.dataStores = await d2ApiDataStore.getDataStores({ namespaces: ids });
}
const dataStoresMetadata = await this.getDataStoresMetadata(ids);
const responseWithDataStores = { ...metadataPackage, ...dataStoresMetadata } as T;
Expand All @@ -112,8 +112,8 @@ export class MetadataD2ApiRepository implements MetadataRepository {
const dataStoreIds = DataStoreMetadata.getDataStoreIds(ids);
if (dataStoreIds.length === 0) return {};

const result = await d2ApiDataStore.getDataStore({ namespaces: dataStoreIds });
return { dataStores: result };
const dataStores = await d2ApiDataStore.getDataStores({ namespaces: dataStoreIds });
return { dataStores: dataStores };
}

@cache()
Expand All @@ -125,7 +125,7 @@ export class MetadataD2ApiRepository implements MetadataRepository {
const options = { type, fields, filter, order, page, pageSize, rootJunction };
if (type === "dataStores") {
const d2ApiDataStore = new D2ApiDataStore(this.instance);
const response = await d2ApiDataStore.getDataStore({ namespaces: [] });
const response = await d2ApiDataStore.getDataStores({ namespaces: undefined });
// Hardcoded pagination since DHIS2 does not support pagination for namespaces
return { objects: response, pager: { page: 1, total: response.length, pageSize: 100 } };
} else {
Expand Down

0 comments on commit 36e769a

Please sign in to comment.