diff --git a/src/lib/dataStore/useDataStore.ts b/src/lib/dataStore/useDataStore.ts index 8af42c47..d2c9870a 100644 --- a/src/lib/dataStore/useDataStore.ts +++ b/src/lib/dataStore/useDataStore.ts @@ -1,10 +1,4 @@ -import { - FetchError, - useDataEngine, - useDataMutation, - useDataQuery, -} from '@dhis2/app-runtime' -import { useMemo } from 'react' +import { useDataEngine } from '@dhis2/app-runtime' import { useQuery, useMutation, @@ -23,12 +17,7 @@ type GetMutationTypeUnion = { } type UpdateMutationTypeUnion = GetMutationTypeUnion<'update'> type UpdateMutation = Extract -type CreateMutation = Extract> type UpdateMutationData = UpdateMutation['data'] -// type UpdateMutation = { type: 'update' | 'replace' | 'json-patch'; /* other properties */ }; -// type DeleteMutation = { type: 'delete'; /* other properties */ }; - -//type Mutation = UpdateMutation | DeleteMutation; type DataStoreOptions = { namespace: string @@ -36,10 +25,6 @@ type DataStoreOptions = { global?: boolean } -type WrapInResult = { - result: TResult -} - type ObjectResult = Record const createBoundQueryFn = @@ -71,17 +56,6 @@ export const queryCreators = { id: `${namespace}/${key}`, }, }), - createKey: ({ - namespace, - global, - key, - data, - }: SetValuesOptions): CreateMutation => ({ - resource: `${getDataStoreResource(global)}/${namespace}/${key}`, - type: 'create', - // engine enforces data to be an object with keys, but can actually store any JSON-value - data: data as CreateMutation['data'], - }), setValues: ({ namespace, global, @@ -149,23 +123,7 @@ export const useMutateDataStoreValues = (options: ValuesOptions) => { global: mergedOptions.global, data, }) - try { - return await engine.mutate(mutation) - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } catch (error: any) { - // if namespace or key does not exist, create it - if (error.details?.httpStatusCode === 404) { - const mut = queryCreators.createKey({ - namespace: mergedOptions.namespace, - key: mergedOptions.key, - global: mergedOptions.global, - data, - }) - return engine.mutate(mut) - } else { - throw error - } - } + return await engine.mutate(mutation) } const mutation = useMutation({ mutationFn,