Skip to content

Commit

Permalink
Merge pull request #246 from amansinghbais/#245
Browse files Browse the repository at this point in the history
Improved: logic to fetch organizationPartyId from db instead of hardcoding it (#245)
  • Loading branch information
ymaheshwari1 authored Jul 9, 2024
2 parents f58c799 + e2cdd60 commit 3bfd4e3
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,11 @@ const deletePartyRole = async (payload: any): Promise <any> => {
}

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

payload = {
...payload,
"partyIdFrom": "COMPANY",
"partyIdFrom": organizationPartyId,
"roleTypeIdFrom": "INTERNAL_ORGANIZATIO",
"partyRelationshipTypeId": "OWNER",
"statusId": "ACCOUNT_CREATED",
Expand Down Expand Up @@ -508,6 +510,8 @@ const isUserLoginIdAlreadyExists = async(username: string): Promise<any> => {
}

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

try {
const selectedUser = payload.selectedUser;
const selectedTemplate = payload.selectedTemplate;
Expand All @@ -528,7 +532,7 @@ const finishSetup = async (payload: any): Promise <any> => {
"requirePasswordChange": payload.formData.requirePasswordChange ? "Y" : "N",
"enabled": "Y",
"userPrefTypeId": "ORGANIZATION_PARTY",
"userPrefValue": "COMPANY"
"userPrefValue": organizationPartyId
});
if (!hasError(resp)) {
addUserToSecurityGroup({
Expand Down
9 changes: 9 additions & 0 deletions src/services/UtilService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,17 @@ const getShopifyConfigs = async (): Promise <any> => {
});
}

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

export const UtilService = {
fetchFacilities,
fetchOrganizationPartyId,
fetchProductStores,
getSecurityGroups,
getShopifyConfigs,
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 @@ -72,6 +72,7 @@ const actions: ActionTree<UserState, RootState> = {
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) {
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 @@ -5,4 +5,5 @@ export default interface UtilState {
classificationSecurityGroups: any[];
facilities: any[];
shopifyShops: any[];
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 @@ -194,6 +194,32 @@ const actions: ActionTree<UtilState, RootState> = {
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)
},
Expand All @@ -202,6 +228,7 @@ const actions: ActionTree<UtilState, RootState> = {
commit(types.UTIL_FACILITIES_UPDATED, [])
commit(types.UTIL_SECURITY_GROUPS_UPDATED, []);
commit(types.UTIL_PRODUCT_STORES_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 @@ -23,6 +23,9 @@ const getters: GetterTree<UtilState, RootState> = {
},
getShopifyShops(state) {
return state.shopifyShops;
},
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 @@ -13,7 +13,8 @@ const utilModule: Module<UtilState, RootState> = {
securityGroups: [],
classificationSecurityGroups: [],
facilities: [],
shopifyShops: []
shopifyShops: [],
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 @@ -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'
3 changes: 3 additions & 0 deletions src/store/modules/util/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const mutations: MutationTree<UtilState> = {
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;
5 changes: 3 additions & 2 deletions src/views/CreateUser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ export default defineComponent({
},
computed: {
...mapGetters({
facilities: 'util/getFacilities'
facilities: 'util/getFacilities',
organizationPartyId: 'util/getOrganizationPartyId'
})
},
data() {
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions src/views/UserDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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 });
Expand Down

0 comments on commit 3bfd4e3

Please sign in to comment.