diff --git a/src/index.ts b/src/index.ts index d81481c..ddb2ae5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import { events, Product, Response, Stock, Order, OrderItem, OrderPart, OPERATOR, User } from './types' import api, { client, getConfig, init, initialise, resetConfig, updateToken, updateInstanceUrl } from './api' import { hasError, isError } from './util' -import { getNotificationEnumIds, getNotificationUserPrefTypeIds, getUserFacilities, fetchProducts, fetchProductsGroupedBy, fetchProductsGroupedByParent, fetchProductsStock, fetchProductsStockAtFacility, getOrderDetails, getProductIdentificationPref, getProfile, logout, removeClientRegistrationToken, setProductIdentificationPref, storeClientRegistrationToken, subscribeTopic, unsubscribeTopic, updateOrderStatus } from './modules' +import { getNotificationEnumIds, getNotificationUserPrefTypeIds, getUserFacilities, fetchProducts, fetchProductsGroupedBy, fetchProductsGroupedByParent, fetchProductsStock, fetchProductsStockAtFacility, getOrderDetails, getProductIdentificationPref, getProfile, logout, removeClientRegistrationToken, setProductIdentificationPref, storeClientRegistrationToken, subscribeTopic, unsubscribeTopic, updateOrderStatus, getUserPreference, setUserPreference } from './modules' export { api, @@ -40,5 +40,7 @@ export { storeClientRegistrationToken, subscribeTopic, unsubscribeTopic, - User + User, + getUserPreference, + setUserPreference, } \ No newline at end of file diff --git a/src/modules/index.ts b/src/modules/index.ts index 22c8623..9f11868 100644 --- a/src/modules/index.ts +++ b/src/modules/index.ts @@ -1,6 +1,6 @@ import { getOrderDetails, updateOrderStatus } from '../modules/order' import { fetchProducts, fetchProductsGroupedBy, fetchProductsGroupedByParent } from '../modules/product' -import { getProductIdentificationPref, getProfile, getUserFacilities, logout, setProductIdentificationPref } from '../modules/user' +import { getProductIdentificationPref, getProfile, getUserFacilities, getUserPreference, logout, setProductIdentificationPref, setUserPreference } from '../modules/user' import { getNotificationEnumIds, getNotificationUserPrefTypeIds, removeClientRegistrationToken, storeClientRegistrationToken, subscribeTopic, unsubscribeTopic } from '../modules/notification' import { fetchProductsStock, fetchProductsStockAtFacility } from '../modules/stock' @@ -22,5 +22,7 @@ export { subscribeTopic, unsubscribeTopic, getUserFacilities, - updateOrderStatus + updateOrderStatus, + getUserPreference, + setUserPreference } \ No newline at end of file diff --git a/src/modules/user/index.ts b/src/modules/user/index.ts index 259cfc2..0e7b02a 100644 --- a/src/modules/user/index.ts +++ b/src/modules/user/index.ts @@ -233,10 +233,51 @@ async function getUserFacilities(token: any, baseURL: string, partyId: string, f } } +async function getUserPreference(token: any, baseURL: string, userPrefTypeId: string): Promise { + try { + const resp = await client({ + url: "service/getUserPreference", + method: "post", + data: { userPrefTypeId }, + baseURL, + headers: { + Authorization: 'Bearer ' + token, + 'Content-Type': 'application/json' + } + }); + if (hasError(resp)) { + throw resp.data + } + return Promise.resolve(resp.data.userPrefValue ? JSON.parse(resp.data.userPrefValue) : {}); + } catch (err) { + return Promise.reject(err) + } +} + +async function setUserPreference(payload: any): Promise { + try { + const resp: any = await api({ + url: "service/setUserPreference", + method: "post", + data: payload + }); + + if (!hasError(resp)) { + return Promise.resolve(resp.data) + } else { + throw resp.data + } + } catch (err) { + return Promise.reject(err) + } +} + export { + getUserFacilities, + getUserPreference, getProductIdentificationPref, getProfile, logout, setProductIdentificationPref, - getUserFacilities + setUserPreference } \ No newline at end of file