Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved: Code by relocating Party-related functionality from the util module to a dedicated module in store and updating PartyService accordingly.(#121) #928

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
13 changes: 13 additions & 0 deletions src/services/PartyService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { api } from '@/adapter';

const fetchPartyInformation = async (query: any): Promise <any> => {
return api({
url: "performFind",
method: "get",
params: query
});
}

export const PartyService = {
fetchPartyInformation
}
9 changes: 0 additions & 9 deletions src/services/UtilService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,6 @@ const fetchCarrierPartyIds = async (query: any): Promise <any> => {
});
}

const fetchPartyInformation = async (query: any): Promise <any> => {
return api({
url: "performFind",
method: "get",
params: query
});
}

const fetchShipmentMethodTypeDesc = async (query: any): Promise <any> => {
return api({
url: "performFind",
Expand Down Expand Up @@ -693,7 +685,6 @@ export const UtilService = {
fetchGiftCardItemPriceInfo,
fetchOrderAdjustments,
fetchOrderShipGroupInfo,
fetchPartyInformation,
fetchPicklistInformation,
fetchProductStores,
fetchRejectReasonEnumTypes,
Expand Down
2 changes: 2 additions & 0 deletions src/store/RootState.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import OrderState from "./modules/order/OrderState";
import UtilState from "./modules/util/UtilState";
import PartyState from "./modules/party/PartyState";
import TransferOrderState from "./modules/transferorder/TransferOrderState";
import CarrierState from "./modules/carrier/CarrierState"
import RejectionState from "./modules/rejection/RejectionState"
Expand All @@ -9,6 +10,7 @@ export default interface RootState {
user: any;
product: any;
util: UtilState;
party: PartyState;
order: OrderState;
transferOrder: TransferOrderState,
carrier: CarrierState,
Expand Down
2 changes: 2 additions & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import productModule from "./modules/product"
import orderModule from "./modules/order"
import transferOrderModule from "./modules/transferorder"
import utilModule from "./modules/util"
import partyModule from "./modules/party"
import stockModule from "./modules/stock"
import carrierModule from "./modules/carrier"
import { setPermissions } from '@/authorization'
Expand Down Expand Up @@ -43,6 +44,7 @@ const store = createStore<RootState>({
'order': orderModule,
'orderLookup': orderLookupModule,
'util': utilModule,
'party': partyModule,
'stock': stockModule,
'transferorder': transferOrderModule,
'carrier': carrierModule,
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/order/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ const actions: ActionTree<OrderState, RootState> = {
}

try {
this.dispatch('util/fetchPartyInformation', carrierPartyIds)
this.dispatch('party/fetchPartyInformation', carrierPartyIds)
const shipmentTrackingCodes = await OrderService.fetchTrackingCodes(shipmentIds)

shipGroups.find((shipGroup: any) => {
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/orderLookup/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const actions: ActionTree<OrderLookupState, RootState> = {
const carriersTrackingInfo = {} as any;
const systemProperties = {} as any;

await this.dispatch('util/fetchPartyInformation', carrierPartyIds);
await this.dispatch('party/fetchPartyInformation', carrierPartyIds);

try {
const resp = await CarrierService.fetchCarrierTrackingUrls({
Expand Down
3 changes: 3 additions & 0 deletions src/store/modules/party/PartyState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default interface PartyState {
partyNames: any
}
61 changes: 61 additions & 0 deletions src/store/modules/party/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { ActionTree } from 'vuex'
import RootState from '@/store/RootState'
import PartyState from './PartyState'
import * as types from './mutation-types'
import { PartyService } from '@/services/PartyService'
import logger from '@/logger'
import { hasError } from '@/adapter'

const actions: ActionTree<PartyState, RootState> = {
async fetchPartyInformation({ commit, state }, partyIds) {
let partyInformation = JSON.parse(JSON.stringify(state.partyNames))
const cachedPartyIds = Object.keys(partyInformation);
const ids = partyIds.filter((partyId: string) => !cachedPartyIds.includes(partyId))

if(!ids.length) return partyInformation;

try {
const payload = {
"inputFields": {
"partyId": ids,
"partyId_op": "in"
},
"fieldList": ["firstName", "middleName", "lastName", "groupName", "partyId"],
"entityName": "PartyNameView",
"viewSize": ids.length
}

const resp = await PartyService.fetchPartyInformation(payload);

if(!hasError(resp)) {
const partyResp = {} as any
resp.data.docs.map((partyInformation: any) => {

let partyName = ''
if(partyInformation.groupName) {
partyName = partyInformation.groupName
} else {
partyName = [partyInformation.firstName, partyInformation.lastName].join(' ')
}

partyResp[partyInformation.partyId] = partyName
})

partyInformation = {
...partyInformation,
...partyResp
}

commit(types.PARTY_NAMES_UPDATED, partyInformation)
} else {
throw resp.data
}
} catch(err) {
logger.error('Error fetching party information', err)
}

return partyInformation;
}
}

export default actions;
11 changes: 11 additions & 0 deletions src/store/modules/party/getters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { GetterTree } from "vuex";
import PartyState from './PartyState'
import RootState from "@/store/RootState";

const getters: GetterTree<PartyState, RootState> = {
getPartyName: (state) => (partyId: string) => {
return state.partyNames[partyId] ? state.partyNames[partyId] : ''
}
}

export default getters;
12 changes: 12 additions & 0 deletions src/store/modules/party/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from 'vuex'
import RootState from '@/store/RootState'
import PartyState from './PartyState'

const partyModule: Module<PartyState, RootState> = {
namespaced: true,
state: {
partyNames: {}
}
}

export default partyModule;
2 changes: 2 additions & 0 deletions src/store/modules/party/mutation-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const SN_PARTY = 'party'
export const PARTY_NAMES_UPDATED = SN_PARTY + '/PARTY_NAMES_UPDATED'
11 changes: 11 additions & 0 deletions src/store/modules/party/mutations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { MutationTree } from "vuex";
import PartyState from './PartyState';
import * as types from './mutation-types'

const mutations: MutationTree<PartyState> = {
[types.PARTY_NAMES_UPDATED] (state, payload) {
state.partyNames = payload
}
}

export default mutations;
2 changes: 1 addition & 1 deletion src/store/modules/transferorder/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ const actions: ActionTree<TransferOrderState, RootState> = {
while(productIds.length) {
productIdBatches.push(productIds.splice(0, batchSize))
}
await Promise.all([productIdBatches.map((productIds) => this.dispatch('product/fetchProducts', { productIds })), this.dispatch('util/fetchPartyInformation', [shipmentCarriers?.[0].carrierPartyId,]), this.dispatch('util/fetchShipmentMethodTypeDesc', [shipmentCarriers?.[0].shipmentMethodTypeId])])
await Promise.all([productIdBatches.map((productIds) => this.dispatch('product/fetchProducts', { productIds })), this.dispatch('party/fetchPartyInformation', [shipmentCarriers?.[0].carrierPartyId,]), this.dispatch('util/fetchShipmentMethodTypeDesc', [shipmentCarriers?.[0].shipmentMethodTypeId])])
}

} catch (err: any) {
Expand Down
1 change: 0 additions & 1 deletion src/store/modules/util/UtilState.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export default interface UtilState {
rejectReasons: [];
partyNames: any;
shipmentMethodTypeDesc: any;
shipmentBoxTypeDesc: any;
facilityTypeDesc: any;
Expand Down
50 changes: 0 additions & 50 deletions src/store/modules/util/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,56 +86,6 @@ const actions: ActionTree<UtilState, RootState> = {
return isApiSuccess
},

async fetchPartyInformation({ commit, state }, partyIds) {
let partyInformation = JSON.parse(JSON.stringify(state.partyNames))
const cachedPartyIds = Object.keys(partyInformation);
const ids = partyIds.filter((partyId: string) => !cachedPartyIds.includes(partyId))

if(!ids.length) return partyInformation;

try {
const payload = {
"inputFields": {
"partyId": ids,
"partyId_op": "in"
},
"fieldList": ["firstName", "middleName", "lastName", "groupName", "partyId"],
"entityName": "PartyNameView",
"viewSize": ids.length
}

const resp = await UtilService.fetchPartyInformation(payload);

if(!hasError(resp)) {
const partyResp = {} as any
resp.data.docs.map((partyInformation: any) => {

let partyName = ''
if(partyInformation.groupName) {
partyName = partyInformation.groupName
} else {
partyName = [partyInformation.firstName, partyInformation.lastName].join(' ')
}

partyResp[partyInformation.partyId] = partyName
})

partyInformation = {
...partyInformation,
...partyResp
}

commit(types.UTIL_PARTY_NAMES_UPDATED, partyInformation)
} else {
throw resp.data
}
} catch(err) {
logger.error('Error fetching party information', err)
}

return partyInformation;
},

async fetchShipmentMethodTypeDesc({ commit, state }, shipmentIds) {
let shipmentMethodTypeDesc = JSON.parse(JSON.stringify(state.shipmentMethodTypeDesc))
const cachedShipmentMethodIds = Object.keys(shipmentMethodTypeDesc);
Expand Down
3 changes: 0 additions & 3 deletions src/store/modules/util/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ const getters: GetterTree <UtilState, RootState> = {
getRejectReasons(state) {
return state.rejectReasons ? state.rejectReasons : []
},
getPartyName: (state) => (partyId: string) => {
return state.partyNames[partyId] ? state.partyNames[partyId] : ''
},
getShipmentMethodDesc: (state) => (shipmentMethodId: string) => {
return state.shipmentMethodTypeDesc[shipmentMethodId] ? state.shipmentMethodTypeDesc[shipmentMethodId] : shipmentMethodId
},
Expand Down
1 change: 0 additions & 1 deletion src/store/modules/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const utilModule: Module<UtilState, RootState> = {
namespaced: true,
state: {
rejectReasons: [],
partyNames: {},
shipmentMethodTypeDesc: {},
shipmentBoxTypeDesc: {},
facilityTypeDesc: {},
Expand Down
1 change: 0 additions & 1 deletion src/store/modules/util/mutation-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export const SN_UTIL = 'util'
export const UTIL_REJECT_REASONS_UPDATED = SN_UTIL + '/REJECT_REASONS_UPDATED'
export const UTIL_PARTY_NAMES_UPDATED = SN_UTIL + '/PARTY_NAMES_UPDATED'
export const UTIL_SHIPMENT_METHODS_UPDATED = SN_UTIL + '/SHIPMENT_METHODS_UPDATED'
export const UTIL_SHIPMENT_BOXES_UPDATED = SN_UTIL + '/SHIPMENT_BOXES_UPDATED'
export const UTIL_FACILITY_TYPE_UPDATED = SN_UTIL + '/FACILITY_TYPE_UPDATED'
Expand Down
3 changes: 0 additions & 3 deletions src/store/modules/util/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ const mutations: MutationTree <UtilState> = {
[types.UTIL_REJECT_REASONS_UPDATED] (state, payload) {
state.rejectReasons = payload
},
[types.UTIL_PARTY_NAMES_UPDATED] (state, payload) {
state.partyNames = payload
},
[types.UTIL_SHIPMENT_METHODS_UPDATED] (state, payload) {
state.shipmentMethodTypeDesc = payload
},
Expand Down
4 changes: 2 additions & 2 deletions src/views/Completed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export default defineComponent({
...mapGetters({
completedOrders: 'order/getCompletedOrders',
getProduct: 'product/getProduct',
getPartyName: 'util/getPartyName',
getPartyName: 'party/getPartyName',
getShipmentMethodDesc: 'util/getShipmentMethodDesc',
getProductStock: 'stock/getProductStock',
productStoreShipmentMethCount: 'util/getProductStoreShipmentMethCount',
Expand Down Expand Up @@ -549,7 +549,7 @@ export default defineComponent({

if(resp.status == 200 && !hasError(resp)) {
this.carrierPartyIds = resp.data.facets.manifestContentIdFacet.buckets
this.store.dispatch('util/fetchPartyInformation', this.carrierPartyIds.map((carrierPartyId) => carrierPartyId.val.split('/')[0]))
this.store.dispatch('party/fetchPartyInformation', this.carrierPartyIds.map((carrierPartyId) => carrierPartyId.val.split('/')[0]))
} else {
throw resp.data
}
Expand Down
4 changes: 2 additions & 2 deletions src/views/OrderDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ export default defineComponent({
order: "order/getCurrent",
rejectReasonOptions: 'util/getRejectReasonOptions',
userPreference: 'user/getUserPreference',
getPartyName: 'util/getPartyName',
getPartyName: 'party/getPartyName',
getfacilityTypeDesc: 'util/getFacilityTypeDesc',
getPaymentMethodDesc: 'util/getPaymentMethodDesc',
getStatusDesc: 'util/getStatusDesc',
Expand Down Expand Up @@ -1530,7 +1530,7 @@ export default defineComponent({

if(resp.status == 200 && !hasError(resp)) {
this.carrierPartyIds = resp.data.facets.manifestContentIdFacet.buckets
this.store.dispatch('util/fetchPartyInformation', this.carrierPartyIds.map((carrierPartyId) => carrierPartyId.val.split('/')[0]))
this.store.dispatch('party/fetchPartyInformation', this.carrierPartyIds.map((carrierPartyId) => carrierPartyId.val.split('/')[0]))
} else {
throw resp.data
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/TransferShipmentReview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
productIdentificationPref: 'user/getProductIdentificationPref',
productStoreShipmentMethCount: 'util/getProductStoreShipmentMethCount',
getShipmentMethodDesc: 'util/getShipmentMethodDesc',
getPartyName: 'util/getPartyName',
getPartyName: 'party/getPartyName',
}),
},
methods: {
Expand Down
Loading