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: seperated partyname from util module by creating party module(#121) #401

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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({
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve indentation.

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 @@ -280,14 +280,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 @@ -349,7 +341,6 @@ export const UtilService = {
fetchCarrierPartyIds,
fetchDefaultShipmentBox,
fetchFacilityTypeInformation,
fetchPartyInformation,
fetchPicklistInformation,
fetchRejectReasons,
fetchShipmentBoxTypeDesc,
Expand Down
60 changes: 60 additions & 0 deletions src/store/modules/party/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { partyService } from "@/services/PartyService"
import { ActionTree } from "vuex"
import partyState from "./partyState"
import RootState from "@/store/RootState"
import * as types from './mutation-type'
import { hasError } from '@/adapter'
import logger from "@/logger"

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.PRTY_PARTY_NAMES_UPDATED, partyInformation)
} else {
throw resp.data
}
} catch(err) {
logger.error('Error fetching party information', err)
}

return partyInformation;
},
}
export default actions;
10 changes: 10 additions & 0 deletions src/store/modules/party/getters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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;
17 changes: 17 additions & 0 deletions src/store/modules/party/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import actions from './actions'
import getters from './getters'
import mutations from './mutations'
import { Module } from 'vuex'
import RootState from '@/store/RootState'
import partyState from './partyState'

const partyModule: Module<partyState, RootState> = {
namespaced: true,
state: {
partyNames: {},
},
getters,
actions,
mutations
}
export default partyModule
2 changes: 2 additions & 0 deletions src/store/modules/party/mutation-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const SN_PRTY = 'party'
export const PRTY_PARTY_NAMES_UPDATED = SN_PRTY + '/PARTY_NAMES_UPDATED'
10 changes: 10 additions & 0 deletions src/store/modules/party/mutations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { MutationTree } from 'vuex'
import * as types from './mutation-type'
import partyState from './partyState'

const mutations: MutationTree <partyState> = {
[types.PRTY_PARTY_NAMES_UPDATED] (state, payload) {
state.partyNames = payload
},
}
export default mutations;
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;
}
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 @@ -34,56 +34,6 @@ const actions: ActionTree<UtilState, RootState> = {
commit(types.UTIL_REJECT_REASONS_UPDATED, rejectReasons)
},

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
Loading