From 749edd7e7c6ff05a91b4750b3f6127da4772476b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= <4295266+mediremi@users.noreply.github.com> Date: Tue, 1 Jun 2021 14:23:49 +0100 Subject: [PATCH] fix: obtain datastore values directly instead of from metadata (#57) * refactor: remove unused constant * fix: obtain datastore values directly instead of from metadata --- src/constants/apiUrls.js | 1 - src/utils/api.js | 18 ++++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) delete mode 100644 src/constants/apiUrls.js diff --git a/src/constants/apiUrls.js b/src/constants/apiUrls.js deleted file mode 100644 index c09f901..0000000 --- a/src/constants/apiUrls.js +++ /dev/null @@ -1 +0,0 @@ -export const API_URL = 'https://debug.dhis2.org/dev/api' diff --git a/src/utils/api.js b/src/utils/api.js index 2546840..ba58890 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -1,5 +1,4 @@ import { getInstance } from 'd2' -import { API_URL } from '../constants/apiUrls' export class Cache { constructor() { @@ -64,22 +63,17 @@ class Api { return this.cache.get(namespace, key) } - const result = await this.getMetaData(namespace, key) - const jsonLength = result.value.length + const d2 = await getInstance() + const dataStore = await d2.dataStore.get(namespace, false) + const res = await dataStore.get(key) const value = { - length: jsonLength, - value: JSON.parse(result.value), + value: res, + length: JSON.stringify(res).length, } this.cache.set(namespace, key, value) return value } - getMetaData = async (namespace, key) => { - const d2 = await getInstance() - const response = await d2.dataStore.get(namespace, false) - return response.getMetaData(key) - } - createValue = async (namespace, key, value) => { const d2 = await getInstance() const resName = await d2.dataStore.get(namespace, false) @@ -108,5 +102,5 @@ class Api { } } -const apiInstance = new Api(API_URL) +const apiInstance = new Api() export default apiInstance