Skip to content

Commit

Permalink
Merge pull request #73 from k2maan/preference-services
Browse files Browse the repository at this point in the history
Implemented: services to set and get user preferences
  • Loading branch information
ravilodhi authored Oct 6, 2023
2 parents 3b8b9c6 + a5c9702 commit caee0fb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -40,5 +40,7 @@ export {
storeClientRegistrationToken,
subscribeTopic,
unsubscribeTopic,
User
User,
getUserPreference,
setUserPreference,
}
6 changes: 4 additions & 2 deletions src/modules/index.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -22,5 +22,7 @@ export {
subscribeTopic,
unsubscribeTopic,
getUserFacilities,
updateOrderStatus
updateOrderStatus,
getUserPreference,
setUserPreference
}
43 changes: 42 additions & 1 deletion src/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,51 @@ async function getUserFacilities(token: any, baseURL: string, partyId: string, f
}
}

async function getUserPreference(token: any, baseURL: string, userPrefTypeId: string): Promise<any> {
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<any> {
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
}

0 comments on commit caee0fb

Please sign in to comment.