Skip to content

Commit

Permalink
Merge pull request #32 from amansinghbais/#31
Browse files Browse the repository at this point in the history
Implemented: logic to use organization partyId dynamically instead of using a hardcoded 'COMPANY' (#31)
  • Loading branch information
ymaheshwari1 authored Jul 10, 2024
2 parents 088ce3b + b769210 commit 97aa7b8
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/services/UtilService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,19 @@ const fetchShipmentMethodTypes = async (payload: any): Promise <any> => {
});
}

const fetchOrganization = async (payload: any): Promise<any> => {
return api({
url: "organizations",
method: "get",
params: payload
})
}

export const UtilService = {
fetchDBICCountries,
fetchEnums,
fetchFacilityGroups,
fetchOperatingCountries,
fetchOrganization,
fetchShipmentMethodTypes
}
2 changes: 2 additions & 0 deletions src/store/RootState.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export default interface RootState {
user: any;
util: any;
productStore: any;
}
3 changes: 2 additions & 1 deletion src/store/modules/productStore/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProductStoreState, RootState> = {

Expand Down Expand Up @@ -91,7 +92,7 @@ const actions: ActionTree<ProductStoreState, RootState> = {
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;
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const actions: ActionTree<UserState, RootState> = {
}
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")
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/util/UtilState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export default interface UtilState {
dbicCountries: any;
productIdentifiers: any;
shipmentMethodTypes: any;
organizationPartyId: string;
}
21 changes: 21 additions & 0 deletions src/store/modules/util/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,29 @@ const actions: ActionTree<UtilState, RootState> = {
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, "")
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/store/modules/util/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const getters: GetterTree <UtilState, RootState> = {
},
getShipmentMethodTypes(state) {
return state.shipmentMethodTypes;
},
getOrganizationPartyId(state) {
return state.organizationPartyId;
}
}
export default getters;
3 changes: 2 additions & 1 deletion src/store/modules/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const utilModule: Module<UtilState, RootState> = {
operatingCountries: [],
dbicCountries: {},
productIdentifiers: [],
shipmentMethodTypes: []
shipmentMethodTypes: [],
organizationPartyId: ""
},
getters,
actions,
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/util/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 3 additions & 0 deletions src/store/modules/util/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const mutations: MutationTree <UtilState> = {
state.dbicCountries = {}
state.productIdentifiers = []
state.shipmentMethodTypes = []
},
[types.UTIL_ORGANIZATION_PARTY_ID_UPDATED](state, payload) {
state.organizationPartyId = payload
}
}
export default mutations;

0 comments on commit 97aa7b8

Please sign in to comment.