Skip to content

Commit

Permalink
Merge pull request #279 from amansinghbais/278-organization-partyId
Browse files Browse the repository at this point in the history
Improved: logic to use organization partyId dynamically instead of using a hardcoded 'company' (#278)
  • Loading branch information
ravilodhi authored Jul 9, 2024
2 parents 792ef41 + c3fe533 commit 9f6f538
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/components/CreateVirtualFacilityModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default defineComponent({
computed: {
...mapGetters({
virtualFacilities: 'facility/getVirtualFacilities',
organizationPartyId: 'util/getOrganizationPartyId'
})
},
data() {
Expand Down Expand Up @@ -120,7 +121,7 @@ export default defineComponent({
const payload = {
...this.formData,
facilityTypeId: 'VIRTUAL_FACILITY',
ownerPartyId: "COMPANY"
ownerPartyId: this.organizationPartyId
}
const resp = await FacilityService.createVirtualFacility(payload);
Expand Down
7 changes: 5 additions & 2 deletions src/services/FacilityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import logger from '@/logger';
import { DateTime } from 'luxon';
import { prepareOrderQuery } from '@/utils/solrHelper';
import { UserService } from './UserService';
import store from '@/store';

const createFacilityPostalAddress = async (payload: any): Promise<any> => {
return api({
Expand Down Expand Up @@ -671,6 +672,8 @@ const deleteFacilityGroup = async (payload: any): Promise<any> => {
}

const createFacilityLogin = async (payload: any): Promise <any> => {
const organizationPartyId = store.getters['util/getOrganizationPartyId'];

try {
//Create role type if not exists. This is required for associating facility login user to facility.
if (!await UserService.isRoleTypeExists("FAC_LOGIN")) {
Expand All @@ -686,7 +689,7 @@ const createFacilityLogin = async (payload: any): Promise <any> => {
const params = {
"groupName": payload.facilityName,
"partyTypeId": "PARTY_GROUP",
"partyIdFrom": "COMPANY",
"partyIdFrom": organizationPartyId,
"roleTypeIdFrom": "INTERNAL_ORGANIZATIO", // not a typo
"roleTypeIdTo": "APPLICATION_USER",
"partyRelationshipTypeId": "EMPLOYMENT"
Expand All @@ -706,7 +709,7 @@ const createFacilityLogin = async (payload: any): Promise <any> => {
"requirePasswordChange": "N",
"enabled": "Y",
"userPrefTypeId": "ORGANIZATION_PARTY",
"userPrefValue": "COMPANY"
"userPrefValue": organizationPartyId
});
if (hasError(resp)) {
throw resp.data;
Expand Down
9 changes: 9 additions & 0 deletions src/services/UtilService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ const fetchInventoryGroups = async (payload: any): Promise<any> => {
})
}

const fetchOrganizationPartyId = async (payload: any): Promise<any> => {
return api({
url: "performFind",
method: "POST",
data: payload
})
}

export const UtilService = {
fetchCalendars,
fetchCalendarWeekTimings,
Expand All @@ -130,6 +138,7 @@ export const UtilService = {
fetchFacilityTypes,
fetchInventoryGroups,
fetchLocationTypes,
fetchOrganizationPartyId,
fetchProductStores,
fetchShopifyShop,
fetchStates,
Expand Down
2 changes: 1 addition & 1 deletion src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const state: any = {
}

const persistState = createPersistedState({
paths: ['user'],
paths: ['user', 'util.organizationPartyId'],
fetchBeforeUse: true
})

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 @@ -62,6 +62,7 @@ const actions: ActionTree<UserState, RootState> = {
commit(types.USER_PERMISSIONS_UPDATED, appPermissions);
commit(types.USER_TOKEN_CHANGED, { newToken: token })
updateToken(token)
this.dispatch('util/fetchOrganizationPartyId')

const productStoreId = router.currentRoute.value?.query?.productStoreId
if (productStoreId) {
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 @@ -10,4 +10,5 @@ export default interface UtilState {
states: any;
shopifyShopForProductStore: any;
inventoryGroups: [];
organizationPartyId: string;
}
27 changes: 27 additions & 0 deletions src/store/modules/util/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,32 @@ const actions: ActionTree<UtilState, RootState> = {
commit(types.UTIL_INVENTORY_GROUP_UPDATED, inventoryGroups)
},

async fetchOrganizationPartyId({ commit }) {
let partyId = ""

const params = {
entityName: "PartyRole",
inputFields: {
roleTypeId: 'INTERNAL_ORGANIZATIO'
},
noConditionFind: 'Y',
fieldList: ["partyId"],
viewSize: 1
}

try {
const resp = await UtilService.fetchOrganizationPartyId(params)
if (!hasError(resp)) {
partyId = resp.data.docs[0]?.partyId
} else {
throw resp.data
}
} catch (error) {
logger.error(error)
}
commit(types.UTIL_ORGANIZATION_PARTY_ID_UPDATED, partyId)
},

clearUtilState({ commit }) {
commit(types.UTIL_PRODUCT_STORES_UPDATED, [])
commit(types.UTIL_FACILITY_TYPES_UPDATED, [])
Expand All @@ -368,6 +394,7 @@ const actions: ActionTree<UtilState, RootState> = {
commit(types.UTIL_EXTERNAL_MAPPING_TYPES_UPDATED, {})
commit(types.UTIL_SHOPIFY_SHOP_UPDATED, [])
commit(types.UTIL_INVENTORY_GROUP_UPDATED, [])
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 @@ -38,6 +38,9 @@ const getters: GetterTree<UtilState, RootState> = {
},
getInventoryGroups(state) {
return state.inventoryGroups;
},
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 @@ -18,7 +18,8 @@ const utilModule: Module<UtilState, RootState> = {
countries: [],
states: {},
shopifyShopForProductStore: {},
inventoryGroups: []
inventoryGroups: [],
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 @@ -10,3 +10,4 @@ export const UTIL_PARTY_ROLES_UPDATED = SN_UTIL + '/PARTY_ROLES_UPDATED'
export const UTIL_STATES_UPDATED = SN_UTIL + '/STATES_UPDATED'
export const UTIL_SHOPIFY_SHOP_UPDATED = SN_UTIL + '/SHOPIFY_SHOP_UPDATED'
export const UTIL_INVENTORY_GROUP_UPDATED = SN_UTIL + '/INVENTORY_GROUP_UPDATED'
export const UTIL_ORGANIZATION_PARTY_ID_UPDATED = SN_UTIL + '/ORGANIZATION_PARTY_ID_UPDATED'
3 changes: 3 additions & 0 deletions src/store/modules/util/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const mutations: MutationTree<UtilState> = {
},
[types.UTIL_INVENTORY_GROUP_UPDATED](state, payload) {
state.inventoryGroups = payload
},
[types.UTIL_ORGANIZATION_PARTY_ID_UPDATED](state, payload) {
state.organizationPartyId = payload
}
}
export default mutations;
5 changes: 3 additions & 2 deletions src/views/CreateFacility.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ export default defineComponent({
},
computed: {
...mapGetters({
facilityTypes: "util/getFacilityTypes"
facilityTypes: "util/getFacilityTypes",
organizationPartyId: "util/getOrganizationPartyId"
})
},
data() {
Expand Down Expand Up @@ -162,7 +163,7 @@ export default defineComponent({
const payload = {
...this.formData,
facilityTypeId: this.selectedFacilityTypeId,
ownerPartyId: "COMPANY"
ownerPartyId: this.organizationPartyId
}
const resp = await FacilityService.createFacility(payload);
Expand Down

0 comments on commit 9f6f538

Please sign in to comment.