Skip to content

Commit

Permalink
Implemented: state in util module to store carrier specific information(
Browse files Browse the repository at this point in the history
  • Loading branch information
ymaheshwari1 committed Dec 10, 2024
1 parent ae113bf commit 601d538
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/store/modules/util/UtilState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export default interface UtilState {
shippingMethods: object;
facilityGroups: object;
isOmsConnectionExist: boolean | undefined;
statuses: any
statuses: any;
carriers: any;
}
72 changes: 72 additions & 0 deletions src/store/modules/util/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,78 @@ const actions: ActionTree<UtilState, RootState> = {
commit(types.UTIL_STATUSES_UPDATED, statuses)
},

async fetchCarrierInformation({ commit, state }, carrierIds: Array<any>) {
let carriers = JSON.parse(JSON.stringify(state.carriers))
const carrierPartyIds = carrierIds.filter((id: any) => !carriers[id])

if(!carrierPartyIds.length) {
return;
}

const payload = {
inputFields: {
partyId: carrierIds,
partyId_op: "in"
},
distinct: "Y",
viewSize: carrierIds.length,
entityName: "PartyNameView",
}

try {
const resp = await UtilService.getCarrierInformation(payload);

if(!hasError(resp) && resp.data.docs?.length) {
// Using only groupName as we will always pass carrier id, that only has groupName with it
carriers = resp.data.docs.reduce((carriers: any, carrier: any) => {
carriers[carrier.partyId] = {
name: carrier.groupName
}
return carriers
}, carriers)
}
} catch(err) {
logger.error(err)
}

const deliveryDaysPayload = {
inputFields: {
partyId: carrierIds,
partyId_op: "in",
roleTypeId: "CARRIER",
deliveryDays_op: "not-empty"
},
distinct: "Y",
viewSize: 200,
entityName: "CarrierShipmentMethod",
}

try {
const resp = await UtilService.getCarrierDeliveryDays(deliveryDaysPayload);

if(!hasError(resp) && resp.data.docs?.length) {
carriers = resp.data.docs.reduce((carriers: any, carrier: any) => {
if(carriers[carrier.partyId]["deliveryDays"]) {
carriers[carrier.partyId]["deliveryDays"] = {
...carriers[carrier.partyId]["deliveryDays"],
[carrier.shipmentMethodTypeId]: carrier.deliveryDays
}
} else {
carriers[carrier.partyId]["deliveryDays"] = {
[carrier.shipmentMethodTypeId]: carrier.deliveryDays
}
}

return carriers
}, carriers)
}
} catch(err) {
logger.error(err)
}

commit(types.UTIL_CARRIERS_UPDATED, carriers)
},

async clearUtilState({ commit }) {
commit(types.UTIL_CLEARED)
},
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 @@ -20,6 +20,9 @@ const getters: GetterTree<UtilState, RootState> = {
},
getStatusDesc: (state) => (id: any) => {
return state.statuses[id]?.description ? state.statuses[id]?.description : id
},
getCarriers(state) {
return state.carriers
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const utilModule: Module<UtilState, RootState> = {
shippingMethods: {},
facilityGroups: {},
isOmsConnectionExist: undefined,
statuses: {}
statuses: {},
carriers: {}
},
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 @@ -5,4 +5,5 @@ export const UTIL_SHIPPING_METHOD_UPDATED = SN_UTIL + "/SHIPPING_METHOD_UPDATED"
export const UTIL_FACILITY_GROUP_UPDATED = SN_UTIL + "/FACILITY_GROUP_UPDATED"
export const UTIL_OMS_CONNECTION_STATUS_UPDATED = SN_UTIL + "/OMS_CONNECTION_STATUS_UPDATED"
export const UTIL_STATUSES_UPDATED = SN_UTIL + "/STATUSES_UPDATED"
export const UTIL_CARRIERS_UPDATED = SN_UTIL + "/CARRIERS_UPDATED"
export const UTIL_CLEARED = SN_UTIL + "/CLEARED"
4 changes: 4 additions & 0 deletions src/store/modules/util/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ const mutations: MutationTree<UtilState> = {
state.facilityGroups = {}
state.isOmsConnectionExist = undefined
state.statuses = {}
state.carriers = {}
},
[types.UTIL_STATUSES_UPDATED](state, payload) {
state.statuses = payload
},
[types.UTIL_CARRIERS_UPDATED](state, payload) {
state.carriers = payload
}
}
export default mutations;

0 comments on commit 601d538

Please sign in to comment.