From 921aa6f7c3bb966f12de57d8244b22aee9a45bc0 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Tue, 25 Jun 2024 15:27:52 +0530 Subject: [PATCH 1/3] Improved: logic to use organization partyId dynamically instead of using a hardcoded 'company' (#278) --- src/components/CreateVirtualFacilityModal.vue | 3 ++- src/services/FacilityService.ts | 7 +++-- src/services/UtilService.ts | 9 +++++++ src/store/index.ts | 2 +- src/store/modules/user/actions.ts | 11 ++++---- src/store/modules/util/UtilState.ts | 1 + src/store/modules/util/actions.ts | 27 +++++++++++++++++++ src/store/modules/util/getters.ts | 3 +++ src/store/modules/util/index.ts | 3 ++- src/store/modules/util/mutation-types.ts | 1 + src/store/modules/util/mutations.ts | 3 +++ src/views/CreateFacility.vue | 5 ++-- 12 files changed, 63 insertions(+), 12 deletions(-) diff --git a/src/components/CreateVirtualFacilityModal.vue b/src/components/CreateVirtualFacilityModal.vue index b4e9d395..175f79b9 100644 --- a/src/components/CreateVirtualFacilityModal.vue +++ b/src/components/CreateVirtualFacilityModal.vue @@ -81,6 +81,7 @@ export default defineComponent({ computed: { ...mapGetters({ virtualFacilities: 'facility/getVirtualFacilities', + organizationPartyId: 'util/getOrganizationPartyID' }) }, data() { @@ -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); diff --git a/src/services/FacilityService.ts b/src/services/FacilityService.ts index b1478f24..2fb72848 100644 --- a/src/services/FacilityService.ts +++ b/src/services/FacilityService.ts @@ -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 => { return api({ @@ -671,6 +672,8 @@ const deleteFacilityGroup = async (payload: any): Promise => { } const createFacilityLogin = async (payload: any): Promise => { + 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")) { @@ -686,7 +689,7 @@ const createFacilityLogin = async (payload: any): Promise => { const params = { "groupName": payload.facilityName, "partyTypeId": "PARTY_GROUP", - "partyIdFrom": "COMPANY", + "partyIdFrom": organizationPartyID, "roleTypeIdFrom": "INTERNAL_ORGANIZATIO", // not a typo "roleTypeIdTo": "APPLICATION_USER", "partyRelationshipTypeId": "EMPLOYMENT" @@ -706,7 +709,7 @@ const createFacilityLogin = async (payload: any): Promise => { "requirePasswordChange": "N", "enabled": "Y", "userPrefTypeId": "ORGANIZATION_PARTY", - "userPrefValue": "COMPANY" + "userPrefValue": organizationPartyID }); if (hasError(resp)) { throw resp.data; diff --git a/src/services/UtilService.ts b/src/services/UtilService.ts index 3365e2eb..e16b80ed 100644 --- a/src/services/UtilService.ts +++ b/src/services/UtilService.ts @@ -121,6 +121,14 @@ const fetchInventoryGroups = async (payload: any): Promise => { }) } +const fetchOrganizationPartyId = async (payload: any): Promise => { + return api({ + url: "performFind", + method: "POST", + data: payload + }) +} + export const UtilService = { fetchCalendars, fetchCalendarWeekTimings, @@ -130,6 +138,7 @@ export const UtilService = { fetchFacilityTypes, fetchInventoryGroups, fetchLocationTypes, + fetchOrganizationPartyId, fetchProductStores, fetchShopifyShop, fetchStates, diff --git a/src/store/index.ts b/src/store/index.ts index f8bc8d21..302307e0 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -20,7 +20,7 @@ const state: any = { } const persistState = createPersistedState({ - paths: ['user'], + paths: ['user', 'util.organizationPartyID'], fetchBeforeUse: true }) diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index 31006eca..38f812e0 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -21,7 +21,7 @@ const actions: ActionTree = { 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 @@ -47,21 +47,22 @@ const actions: ActionTree = { 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) { diff --git a/src/store/modules/util/UtilState.ts b/src/store/modules/util/UtilState.ts index d981221f..647ce28b 100644 --- a/src/store/modules/util/UtilState.ts +++ b/src/store/modules/util/UtilState.ts @@ -10,4 +10,5 @@ export default interface UtilState { states: any; shopifyShopForProductStore: any; inventoryGroups: []; + organizationPartyID: string; } \ No newline at end of file diff --git a/src/store/modules/util/actions.ts b/src/store/modules/util/actions.ts index ce9c9cf1..1dde5307 100644 --- a/src/store/modules/util/actions.ts +++ b/src/store/modules/util/actions.ts @@ -359,6 +359,32 @@ const actions: ActionTree = { 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, []) @@ -368,6 +394,7 @@ const actions: ActionTree = { 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, "") }, } diff --git a/src/store/modules/util/getters.ts b/src/store/modules/util/getters.ts index 97bc9dce..b99f4a5c 100644 --- a/src/store/modules/util/getters.ts +++ b/src/store/modules/util/getters.ts @@ -38,6 +38,9 @@ const getters: GetterTree = { }, getInventoryGroups(state) { return state.inventoryGroups; + }, + getOrganizationPartyID(state) { + return state.organizationPartyID; } } export default getters; \ No newline at end of file diff --git a/src/store/modules/util/index.ts b/src/store/modules/util/index.ts index 267ce2a5..d4cd1bd7 100644 --- a/src/store/modules/util/index.ts +++ b/src/store/modules/util/index.ts @@ -18,7 +18,8 @@ const utilModule: Module = { countries: [], states: {}, shopifyShopForProductStore: {}, - inventoryGroups: [] + inventoryGroups: [], + organizationPartyID: "" }, getters, actions, diff --git a/src/store/modules/util/mutation-types.ts b/src/store/modules/util/mutation-types.ts index 66285aa7..312f6f0f 100644 --- a/src/store/modules/util/mutation-types.ts +++ b/src/store/modules/util/mutation-types.ts @@ -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' diff --git a/src/store/modules/util/mutations.ts b/src/store/modules/util/mutations.ts index e22ea15c..517cdca5 100644 --- a/src/store/modules/util/mutations.ts +++ b/src/store/modules/util/mutations.ts @@ -43,6 +43,9 @@ const mutations: MutationTree = { }, [types.UTIL_INVENTORY_GROUP_UPDATED](state, payload) { state.inventoryGroups = payload + }, + [types.UTIL_ORGANIZATION_PARTY_ID_UPDATED](state, payload) { + state.organizationPartyID = payload } } export default mutations; \ No newline at end of file diff --git a/src/views/CreateFacility.vue b/src/views/CreateFacility.vue index 6d7999a2..7cbe6b44 100644 --- a/src/views/CreateFacility.vue +++ b/src/views/CreateFacility.vue @@ -98,7 +98,8 @@ export default defineComponent({ }, computed: { ...mapGetters({ - facilityTypes: "util/getFacilityTypes" + facilityTypes: "util/getFacilityTypes", + organizationPartyId: "util/getOrganizationPartyID" }) }, data() { @@ -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); From 666c69611b5b32ccbb1716de910321e6568a6aef Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Tue, 25 Jun 2024 15:37:54 +0530 Subject: [PATCH 2/3] Improved: added fieldlist for fetching organization and reverted the unused changes (#278) --- src/store/modules/user/actions.ts | 10 +++++----- src/store/modules/util/actions.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index 38f812e0..d950d621 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -21,7 +21,7 @@ const actions: ActionTree = { 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 @@ -47,16 +47,16 @@ const actions: ActionTree = { 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); diff --git a/src/store/modules/util/actions.ts b/src/store/modules/util/actions.ts index 1dde5307..ceaec87a 100644 --- a/src/store/modules/util/actions.ts +++ b/src/store/modules/util/actions.ts @@ -368,7 +368,7 @@ const actions: ActionTree = { roleTypeId: 'INTERNAL_ORGANIZATIO' }, noConditionFind: 'Y', - // fieldList: ["facilityGroupId", "facilityGroupTypeId", "facilityGroupName", "description"], + fieldList: ["partyId"], viewSize: 1 } From c3fe5332b6a9877ca7350a29d13428c69a691415 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Tue, 9 Jul 2024 10:55:44 +0530 Subject: [PATCH 3/3] Improved: letter casing in method and variable for organization party id (#278) --- src/components/CreateVirtualFacilityModal.vue | 2 +- src/services/FacilityService.ts | 6 +++--- src/store/index.ts | 2 +- src/store/modules/util/UtilState.ts | 2 +- src/store/modules/util/getters.ts | 4 ++-- src/store/modules/util/index.ts | 2 +- src/store/modules/util/mutations.ts | 2 +- src/views/CreateFacility.vue | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/CreateVirtualFacilityModal.vue b/src/components/CreateVirtualFacilityModal.vue index 175f79b9..59f34757 100644 --- a/src/components/CreateVirtualFacilityModal.vue +++ b/src/components/CreateVirtualFacilityModal.vue @@ -81,7 +81,7 @@ export default defineComponent({ computed: { ...mapGetters({ virtualFacilities: 'facility/getVirtualFacilities', - organizationPartyId: 'util/getOrganizationPartyID' + organizationPartyId: 'util/getOrganizationPartyId' }) }, data() { diff --git a/src/services/FacilityService.ts b/src/services/FacilityService.ts index 2fb72848..6fc03b63 100644 --- a/src/services/FacilityService.ts +++ b/src/services/FacilityService.ts @@ -672,7 +672,7 @@ const deleteFacilityGroup = async (payload: any): Promise => { } const createFacilityLogin = async (payload: any): Promise => { - const organizationPartyID = store.getters['util/getOrganizationPartyID']; + const organizationPartyId = store.getters['util/getOrganizationPartyId']; try { //Create role type if not exists. This is required for associating facility login user to facility. @@ -689,7 +689,7 @@ const createFacilityLogin = async (payload: any): Promise => { const params = { "groupName": payload.facilityName, "partyTypeId": "PARTY_GROUP", - "partyIdFrom": organizationPartyID, + "partyIdFrom": organizationPartyId, "roleTypeIdFrom": "INTERNAL_ORGANIZATIO", // not a typo "roleTypeIdTo": "APPLICATION_USER", "partyRelationshipTypeId": "EMPLOYMENT" @@ -709,7 +709,7 @@ const createFacilityLogin = async (payload: any): Promise => { "requirePasswordChange": "N", "enabled": "Y", "userPrefTypeId": "ORGANIZATION_PARTY", - "userPrefValue": organizationPartyID + "userPrefValue": organizationPartyId }); if (hasError(resp)) { throw resp.data; diff --git a/src/store/index.ts b/src/store/index.ts index 302307e0..249ad7ad 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -20,7 +20,7 @@ const state: any = { } const persistState = createPersistedState({ - paths: ['user', 'util.organizationPartyID'], + paths: ['user', 'util.organizationPartyId'], fetchBeforeUse: true }) diff --git a/src/store/modules/util/UtilState.ts b/src/store/modules/util/UtilState.ts index 647ce28b..b5cb574e 100644 --- a/src/store/modules/util/UtilState.ts +++ b/src/store/modules/util/UtilState.ts @@ -10,5 +10,5 @@ export default interface UtilState { states: any; shopifyShopForProductStore: any; inventoryGroups: []; - organizationPartyID: string; + organizationPartyId: string; } \ No newline at end of file diff --git a/src/store/modules/util/getters.ts b/src/store/modules/util/getters.ts index b99f4a5c..f04d9ccc 100644 --- a/src/store/modules/util/getters.ts +++ b/src/store/modules/util/getters.ts @@ -39,8 +39,8 @@ const getters: GetterTree = { getInventoryGroups(state) { return state.inventoryGroups; }, - getOrganizationPartyID(state) { - return state.organizationPartyID; + getOrganizationPartyId(state) { + return state.organizationPartyId; } } export default getters; \ No newline at end of file diff --git a/src/store/modules/util/index.ts b/src/store/modules/util/index.ts index d4cd1bd7..bb12ce82 100644 --- a/src/store/modules/util/index.ts +++ b/src/store/modules/util/index.ts @@ -19,7 +19,7 @@ const utilModule: Module = { states: {}, shopifyShopForProductStore: {}, inventoryGroups: [], - organizationPartyID: "" + organizationPartyId: "" }, getters, actions, diff --git a/src/store/modules/util/mutations.ts b/src/store/modules/util/mutations.ts index 517cdca5..27d20b67 100644 --- a/src/store/modules/util/mutations.ts +++ b/src/store/modules/util/mutations.ts @@ -45,7 +45,7 @@ const mutations: MutationTree = { state.inventoryGroups = payload }, [types.UTIL_ORGANIZATION_PARTY_ID_UPDATED](state, payload) { - state.organizationPartyID = payload + state.organizationPartyId = payload } } export default mutations; \ No newline at end of file diff --git a/src/views/CreateFacility.vue b/src/views/CreateFacility.vue index 7cbe6b44..0f12eecb 100644 --- a/src/views/CreateFacility.vue +++ b/src/views/CreateFacility.vue @@ -99,7 +99,7 @@ export default defineComponent({ computed: { ...mapGetters({ facilityTypes: "util/getFacilityTypes", - organizationPartyId: "util/getOrganizationPartyID" + organizationPartyId: "util/getOrganizationPartyId" }) }, data() {