Skip to content

Commit

Permalink
Improved: used OMS methods for setting and getting user prefs
Browse files Browse the repository at this point in the history
  • Loading branch information
k2maan committed Oct 4, 2023
1 parent c74d8ef commit 79bb9bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 37 deletions.
33 changes: 0 additions & 33 deletions src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,37 +47,6 @@ const setUserTimeZone = async (payload: any): Promise <any> => {
});
}

const getUserPreference = async (token: any): Promise<any> => {
const baseURL = store.getters['user/getBaseUrl'];
try {
const resp = await client({
url: "service/getUserPreference",
method: "post",
data: {
'userPrefTypeId': 'BOPIS_PREFERENCE'
},
baseURL,
headers: {
Authorization: 'Bearer ' + token,
'Content-Type': 'application/json'
}
});
if (hasError(resp)) {
return Promise.reject(resp.data);
}
return Promise.resolve(resp.data.userPrefValue ? JSON.parse(resp.data.userPrefValue) : {});
} catch(error: any) {
return Promise.reject(error)
}
}
const setUserPreference = async (payload: any): Promise<any> => {
return api({
url: "service/setUserPreference",
method: "post",
data: payload
});
}

const getCurrentEComStore = async (token: any, facilityId: any): Promise<any> => {

// If the facilityId is not provided, it may be case of user not associated with any facility or the logout
Expand Down Expand Up @@ -228,8 +197,6 @@ export const UserService = {
getCurrentEComStore,
getRerouteFulfillmentConfig,
setUserTimeZone,
getUserPreference,
setUserPreference,
getUserPermissions,
getUserProfile,
updateRerouteFulfillmentConfig
Expand Down
15 changes: 11 additions & 4 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import UserState from './UserState'
import * as types from './mutation-types'
import { showToast } from '@/utils'
import { Settings } from 'luxon';
import { hasError, updateInstanceUrl, updateToken, resetConfig } from '@/adapter'
import {
getUserPreference,
hasError,
resetConfig,
setUserPreference,
updateInstanceUrl,
updateToken
} from '@/adapter'
import {
getServerPermissionsFromRules,
prepareAppPermissions,
Expand All @@ -19,7 +26,7 @@ const actions: ActionTree<UserState, RootState> = {
/**
* Login user and return token
*/
async login ({ commit, dispatch }, payload) {
async login ({ commit, dispatch, getters }, payload) {
try {
const {token, oms} = payload;
dispatch("setUserInstanceUrl", oms);
Expand Down Expand Up @@ -62,7 +69,7 @@ const actions: ActionTree<UserState, RootState> = {
// TODO Use a separate API for getting facilities, this should handle user like admin accessing the app
const currentFacility = userProfile.facilities.length > 0 ? userProfile.facilities[0] : {};
const currentEComStore = await UserService.getCurrentEComStore(token, currentFacility?.facilityId);
const userPreference = await UserService.getUserPreference(token)
const userPreference = await getUserPreference(token, getters['getBaseUrl'], 'BOPIS_PREFERENCE')

/* ---- Guard clauses ends here --- */

Expand Down Expand Up @@ -142,7 +149,7 @@ const actions: ActionTree<UserState, RootState> = {

setUserPreference( {state, commit }, payload){
commit(types.USER_PREFERENCE_UPDATED, payload)
UserService.setUserPreference({
setUserPreference({
'userPrefTypeId': 'BOPIS_PREFERENCE',
'userPrefValue': JSON.stringify(state.preference)
});
Expand Down

0 comments on commit 79bb9bc

Please sign in to comment.