diff --git a/src/services/UtilService.ts b/src/services/UtilService.ts index 3731354..6ef0958 100644 --- a/src/services/UtilService.ts +++ b/src/services/UtilService.ts @@ -40,10 +40,19 @@ const fetchShipmentMethodTypes = async (payload: any): Promise => { }); } +const fetchOrganization = async (payload: any): Promise => { + return api({ + url: "organizations", + method: "get", + params: payload + }) +} + export const UtilService = { fetchDBICCountries, fetchEnums, fetchFacilityGroups, fetchOperatingCountries, + fetchOrganization, fetchShipmentMethodTypes } \ No newline at end of file diff --git a/src/store/RootState.ts b/src/store/RootState.ts index d3f55f7..96d542e 100644 --- a/src/store/RootState.ts +++ b/src/store/RootState.ts @@ -1,3 +1,5 @@ export default interface RootState { user: any; + util: any; + productStore: any; } \ No newline at end of file diff --git a/src/store/modules/productStore/actions.ts b/src/store/modules/productStore/actions.ts index 12ccc83..ae9cb0e 100644 --- a/src/store/modules/productStore/actions.ts +++ b/src/store/modules/productStore/actions.ts @@ -5,6 +5,7 @@ import * as types from "./mutation-types" import { hasError } from "@/utils" import logger from "@/logger" import { ProductStoreService } from "@/services/ProductStoreService" +import store from "@/store" const actions: ActionTree = { @@ -91,7 +92,7 @@ const actions: ActionTree = { let company = {}; try { - const resp = await ProductStoreService.fetchCompany({ partyId: process.env.VUE_APP_COMPANY_PARTY_ID }); + const resp = await ProductStoreService.fetchCompany({ partyId: store.state.util.organizationPartyId }); if(!hasError(resp)) { company = resp.data; diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index bdca980..3758526 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -38,6 +38,7 @@ const actions: ActionTree = { } commit(types.USER_TOKEN_CHANGED, { newToken: api_key }) commit(types.USER_INFO_UPDATED, userProfile); + this.dispatch('util/fetchOrganizationPartyId'); emitter.emit("dismissLoader") } catch (err: any) { emitter.emit("dismissLoader") diff --git a/src/store/modules/util/UtilState.ts b/src/store/modules/util/UtilState.ts index cc5cc55..79bd87e 100644 --- a/src/store/modules/util/UtilState.ts +++ b/src/store/modules/util/UtilState.ts @@ -4,4 +4,5 @@ export default interface UtilState { dbicCountries: any; productIdentifiers: any; shipmentMethodTypes: any; + organizationPartyId: string; } \ No newline at end of file diff --git a/src/store/modules/util/actions.ts b/src/store/modules/util/actions.ts index b3cb204..fa1bd2e 100644 --- a/src/store/modules/util/actions.ts +++ b/src/store/modules/util/actions.ts @@ -95,8 +95,29 @@ const actions: ActionTree = { commit(types.UTIL_SHIPMENT_METHOD_TYPES_UPDATED, shipmentMethodTypes) }, + async fetchOrganizationPartyId({ commit }) { + let partyId = "" + + try { + const resp = await UtilService.fetchOrganization({ + roleTypeId: 'INTERNAL_ORGANIZATIO', + pageSize: 1 + }) + + if(!hasError(resp)) { + partyId = resp.data[0]?.partyId + } else { + throw resp.data + } + } catch (error) { + logger.error(error) + } + commit(types.UTIL_ORGANIZATION_PARTY_ID_UPDATED, partyId) + }, + async clearUtilState({ commit }) { commit(types.UTIL_CLEARED) + commit(types.UTIL_ORGANIZATION_PARTY_ID_UPDATED, "") } } diff --git a/src/store/modules/util/getters.ts b/src/store/modules/util/getters.ts index 4f7d0e6..6cb3c03 100644 --- a/src/store/modules/util/getters.ts +++ b/src/store/modules/util/getters.ts @@ -17,6 +17,9 @@ const getters: GetterTree = { }, getShipmentMethodTypes(state) { return state.shipmentMethodTypes; + }, + getOrganizationPartyId(state) { + return state.organizationPartyId; } } export default getters; \ No newline at end of file diff --git a/src/store/modules/util/index.ts b/src/store/modules/util/index.ts index 5a0518a..4f4aabd 100644 --- a/src/store/modules/util/index.ts +++ b/src/store/modules/util/index.ts @@ -12,7 +12,8 @@ const utilModule: Module = { operatingCountries: [], dbicCountries: {}, productIdentifiers: [], - shipmentMethodTypes: [] + shipmentMethodTypes: [], + organizationPartyId: "" }, getters, actions, diff --git a/src/store/modules/util/mutation-types.ts b/src/store/modules/util/mutation-types.ts index f16b5ab..8d48782 100644 --- a/src/store/modules/util/mutation-types.ts +++ b/src/store/modules/util/mutation-types.ts @@ -4,4 +4,5 @@ export const UTIL_OPERATING_COUNTRIES_UPDATED = SN_UTIL + "/OPERATING_COUNTRIES_ export const UTIL_DBIC_COUNTRIES_UPDATED = SN_UTIL + "/DBIC_COUNTRIES_UPDATED" export const UTIL_PRODUCT_IDENTIFIERS_UPDATED = SN_UTIL + "/PRODUCT_IDENTIFIERS_UPDATED" export const UTIL_SHIPMENT_METHOD_TYPES_UPDATED = SN_UTIL + "/SHIPMENT_METHOD_TYPES_UPDATED" +export const UTIL_ORGANIZATION_PARTY_ID_UPDATED = SN_UTIL + '/ORGANIZATION_PARTY_ID_UPDATED' export const UTIL_CLEARED = SN_UTIL + "/CLEARED" \ No newline at end of file diff --git a/src/store/modules/util/mutations.ts b/src/store/modules/util/mutations.ts index b82f81a..e85404f 100644 --- a/src/store/modules/util/mutations.ts +++ b/src/store/modules/util/mutations.ts @@ -25,6 +25,9 @@ const mutations: MutationTree = { state.dbicCountries = {} state.productIdentifiers = [] state.shipmentMethodTypes = [] + }, + [types.UTIL_ORGANIZATION_PARTY_ID_UPDATED](state, payload) { + state.organizationPartyId = payload } } export default mutations; \ No newline at end of file