Skip to content

Commit

Permalink
Improved: logic to use organization partyId dynamically instead of us…
Browse files Browse the repository at this point in the history
…ing a hardcoded 'company' (#278)
  • Loading branch information
amansinghbais committed Jun 25, 2024
1 parent 792ef41 commit 921aa6f
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 12 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
11 changes: 6 additions & 5 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const actions: ActionTree<UserState, RootState> = {
try {
const {token, oms} = payload;
dispatch("setUserInstanceUrl", oms);

// Getting the permissions list from server
const permissionId = process.env.VUE_APP_PERMISSION_ID;
// Prepare permissions list
Expand All @@ -47,21 +47,22 @@ const actions: ActionTree<UserState, RootState> = {
return Promise.reject(new Error(permissionError));
}
}

const userProfile = await UserService.getUserProfile(token);

/* ---- Guard clauses ends here --- */

setPermissions(appPermissions);
if (userProfile.userTimeZone) {
Settings.defaultZone = userProfile.userTimeZone;
}

// TODO user single mutation
commit(types.USER_INFO_UPDATED, userProfile);
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: ["facilityGroupId", "facilityGroupTypeId", "facilityGroupName", "description"],
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 921aa6f

Please sign in to comment.