From e2cdd60b1be4caa7325292505a0146ee8c9ad5cb Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Tue, 9 Jul 2024 11:06:48 +0530 Subject: [PATCH] Improved: logic to fetch organizationPartyId from db instead of hardcoding it (#245) --- src/services/UserService.ts | 8 +++++-- src/services/UtilService.ts | 9 ++++++++ src/store/modules/user/actions.ts | 1 + 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/CreateUser.vue | 5 +++-- src/views/UserDetails.vue | 5 +++-- 11 files changed, 59 insertions(+), 7 deletions(-) diff --git a/src/services/UserService.ts b/src/services/UserService.ts index bdcc657..c9a75d9 100644 --- a/src/services/UserService.ts +++ b/src/services/UserService.ts @@ -359,9 +359,11 @@ const deletePartyRole = async (payload: any): Promise => { } const createCommercePartyRelationshipFrom = async (payload: any): Promise => { + const organizationPartyId = store.getters['util/getOrganizationPartyId']; + payload = { ...payload, - "partyIdFrom": "COMPANY", + "partyIdFrom": organizationPartyId, "roleTypeIdFrom": "INTERNAL_ORGANIZATIO", "partyRelationshipTypeId": "OWNER", "statusId": "ACCOUNT_CREATED", @@ -508,6 +510,8 @@ const isUserLoginIdAlreadyExists = async(username: string): Promise => { } const finishSetup = async (payload: any): Promise => { + const organizationPartyId = store.getters['util/getOrganizationPartyId']; + try { const selectedUser = payload.selectedUser; const selectedTemplate = payload.selectedTemplate; @@ -528,7 +532,7 @@ const finishSetup = async (payload: any): Promise => { "requirePasswordChange": payload.formData.requirePasswordChange ? "Y" : "N", "enabled": "Y", "userPrefTypeId": "ORGANIZATION_PARTY", - "userPrefValue": "COMPANY" + "userPrefValue": organizationPartyId }); if (!hasError(resp)) { addUserToSecurityGroup({ diff --git a/src/services/UtilService.ts b/src/services/UtilService.ts index 63d7d62..bf23d86 100644 --- a/src/services/UtilService.ts +++ b/src/services/UtilService.ts @@ -60,8 +60,17 @@ const getShopifyConfigs = async (): Promise => { }); } +const fetchOrganizationPartyId = async (payload: any): Promise => { + return api({ + url: "performFind", + method: "POST", + data: payload + }) +} + export const UtilService = { fetchFacilities, + fetchOrganizationPartyId, fetchProductStores, getSecurityGroups, getShopifyConfigs, diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index 2e441ff..23fdd70 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -72,6 +72,7 @@ const actions: ActionTree = { commit(types.USER_INFO_UPDATED, userProfile); commit(types.USER_PERMISSIONS_UPDATED, appPermissions); commit(types.USER_TOKEN_CHANGED, { newToken: token }) + this.dispatch('util/fetchOrganizationPartyId') const partyId = router.currentRoute.value.query.partyId if (partyId) { diff --git a/src/store/modules/util/UtilState.ts b/src/store/modules/util/UtilState.ts index f585f05..da1cc68 100644 --- a/src/store/modules/util/UtilState.ts +++ b/src/store/modules/util/UtilState.ts @@ -5,4 +5,5 @@ export default interface UtilState { classificationSecurityGroups: any[]; facilities: any[]; shopifyShops: any[]; + 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 4962c3a..a521d63 100644 --- a/src/store/modules/util/actions.ts +++ b/src/store/modules/util/actions.ts @@ -194,6 +194,32 @@ const actions: ActionTree = { commit(types.UTIL_PRODUCT_STORES_UPDATED, stores) }, + 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) + }, + updateSecurityGroup({commit}, payload) { commit(types.UTIL_SECURITY_GROUPS_UPDATED, payload) }, @@ -202,6 +228,7 @@ const actions: ActionTree = { commit(types.UTIL_FACILITIES_UPDATED, []) commit(types.UTIL_SECURITY_GROUPS_UPDATED, []); commit(types.UTIL_PRODUCT_STORES_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 4add2dc..0e080e8 100644 --- a/src/store/modules/util/getters.ts +++ b/src/store/modules/util/getters.ts @@ -23,6 +23,9 @@ const getters: GetterTree = { }, getShopifyShops(state) { return state.shopifyShops; + }, + 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 f3b7445..4c1ec21 100644 --- a/src/store/modules/util/index.ts +++ b/src/store/modules/util/index.ts @@ -13,7 +13,8 @@ const utilModule: Module = { securityGroups: [], classificationSecurityGroups: [], facilities: [], - shopifyShops: [] + shopifyShops: [], + organizationPartyId: "" }, getters, actions, diff --git a/src/store/modules/util/mutation-types.ts b/src/store/modules/util/mutation-types.ts index 176b370..de465f9 100644 --- a/src/store/modules/util/mutation-types.ts +++ b/src/store/modules/util/mutation-types.ts @@ -5,3 +5,4 @@ export const UTIL_SECURITY_GROUPS_UPDATED = SN_UTIL + '/SECURITY_GROUPS_UPDATED' export const UTIL_FACILITIES_UPDATED = SN_UTIL + '/FACILITIES_UPDATED' export const UTIL_SHOPIFY_SHOPS_UPDATED = SN_UTIL + '/SHOPIFY_SHOPS_UPDATED' export const UTIL_CLASSIFICATION_SECURITY_GROUPS_UPDATED = SN_UTIL + '/CLASSIFICATION_SECURITY_GROUPS_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 5d2c04e..c3b1450 100644 --- a/src/store/modules/util/mutations.ts +++ b/src/store/modules/util/mutations.ts @@ -19,6 +19,9 @@ const mutations: MutationTree = { state.shopifyShops = payload },[types.UTIL_CLASSIFICATION_SECURITY_GROUPS_UPDATED](state, payload) { state.classificationSecurityGroups = 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/CreateUser.vue b/src/views/CreateUser.vue index c3f85cb..0ada9cd 100644 --- a/src/views/CreateUser.vue +++ b/src/views/CreateUser.vue @@ -115,7 +115,8 @@ export default defineComponent({ }, computed: { ...mapGetters({ - facilities: 'util/getFacilities' + facilities: 'util/getFacilities', + organizationPartyId: 'util/getOrganizationPartyId' }) }, data() { @@ -194,7 +195,7 @@ export default defineComponent({ const payload = { ...this.formData, partyTypeId, - "partyIdFrom": "COMPANY", + "partyIdFrom": this.organizationPartyId, "roleTypeIdFrom": "INTERNAL_ORGANIZATIO", "roleTypeIdTo": "APPLICATION_USER", "partyRelationshipTypeId": "EMPLOYMENT", diff --git a/src/views/UserDetails.vue b/src/views/UserDetails.vue index 83ce238..26f82b6 100644 --- a/src/views/UserDetails.vue +++ b/src/views/UserDetails.vue @@ -492,7 +492,8 @@ export default defineComponent({ securityGroups: 'util/getSecurityGroups', userProfile: 'user/getUserProfile', baseUrl: 'user/getBaseUrl', - shopifyShops: 'util/getShopifyShops' + shopifyShops: 'util/getShopifyShops', + organizationPartyId: 'util/getOrganizationPartyId' }) }, props: ['partyId'], @@ -724,7 +725,7 @@ export default defineComponent({ userLoginId: this.username, enabled: 'Y', userPrefTypeId: 'ORGANIZATION_PARTY', - userPrefValue: 'COMPANY', + userPrefValue: this.organizationPartyId, }) if (!hasError(resp)) { await this.store.dispatch("user/getSelectedUserDetails", { partyId: this.partyId, isFetchRequired: true });