Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ const actions: ActionTree<UserState, RootState> = {
},

async updateCurrentFacility({ dispatch }, facility) {
const previousEComStoreId = getProductStoreId()
const previousProductStoreId = getProductStoreId()
const userProfile = store.getters["user/getUserProfile"]
await useUserStore().getEComStoresByFacility(facility.facilityId);
await useUserStore().getEComStorePreference('SELECTED_BRAND', userProfile.userId);
const preferredStore: any = useUserStore().getCurrentEComStore

if(previousEComStoreId !== preferredStore.productStoreId) {
if(previousProductStoreId !== preferredStore.productStoreId) {
dispatch("getProductStoreSetting", preferredStore.productStoreId)
await useProductIdentificationStore().getIdentificationPref(preferredStore.productStoreId)
.catch((error) => logger.error(error));
Expand Down Expand Up @@ -231,14 +231,14 @@ const actions: ActionTree<UserState, RootState> = {
},

async createProductStoreSetting({ commit }, payload) {
const eComStoreId = getProductStoreId();
const productStoreId = getProductStoreId();
let isSettingExists = false;

let settingValue = false as any;
if(payload.enumId === "BARCODE_IDEN_PREF") settingValue = "internalName"

const params = {
"productStoreId": eComStoreId,
"productStoreId": productStoreId,
"settingTypeEnumId": payload.enumId,
settingValue
}
Expand All @@ -257,7 +257,7 @@ const actions: ActionTree<UserState, RootState> = {
},

async setProductStoreSetting({ commit, dispatch, state }, payload) {
const eComStoreId = getProductStoreId();
const productStoreId = getProductStoreId();
let prefValue = (state.settings as any)[payload.key]

let enumId = "";
Expand Down Expand Up @@ -303,7 +303,7 @@ const actions: ActionTree<UserState, RootState> = {
}

const params = {
"productStoreId": eComStoreId,
"productStoreId": productStoreId,
"settingTypeEnumId": enumId,
"settingValue": payload.key !== "barcodeIdentificationPref" ? JSON.stringify(payload.value) : payload.value
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ function sortListByField(list: any, field = "parentProductName") {
}

const getProductStoreId = () => {
const currentEComStore: any = useUserStore().getCurrentEComStore;
return currentEComStore.productStoreId
const currentProductStore: any = useUserStore().getCurrentEComStore;
return currentProductStore.productStoreId
Comment on lines +187 to +188

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While renaming the variable is a good improvement for consistency, this function can be made more robust. The current implementation will throw a TypeError if useUserStore().getCurrentEComStore returns a nullish value, which can be hard to debug. It's better to handle this case explicitly by checking for the value and throwing a more descriptive error. Additionally, the explicit any type can be removed to rely on type inference, improving type safety.

  const currentProductStore = useUserStore().getCurrentEComStore;
  if (!currentProductStore?.productStoreId) {
    throw new Error("Current product store not found or is missing a productStoreId.");
  }
  return currentProductStore.productStoreId;

};

export { convertIsoToMillis, downloadCsv, jsonToCsv, showToast, hasError, handleDateTimeInput, getCycleCountStats, getDateTime, getDateWithOrdinalSuffix, getDerivedStatusForCount, getFacilityName, getPartyName, getProductIdentificationValue, getProductStoreId, timeFromNow, parseCsv, sortListByField }
Loading