Skip to content

Commit

Permalink
Improved: Updated the logic for fetching contact details of a facilit…
Browse files Browse the repository at this point in the history
…y to use a single action for retrieving address info, contact info, and email address (hotwax#337)
  • Loading branch information
R-Sourabh committed Dec 10, 2024
1 parent 49bb53b commit a95ef7c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 56 deletions.
6 changes: 3 additions & 3 deletions src/components/FacilityAddressModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export default defineComponent({
if(!hasError(resp)) {
postalAddress = this.address
await this.store.dispatch('facility/fetchFacilityContactDetails', { facilityId: this.facilityId })
await this.store.dispatch('facility/fetchFacilityContactDetailsAndTelecom', { facilityId: this.facilityId })
showToast(translate("Facility contact updated successfully."))
} else {
throw resp.data
Expand Down Expand Up @@ -225,7 +225,7 @@ export default defineComponent({
}
if(!hasError(resp)) {
await this.store.dispatch('facility/fetchFacilityTelecomAndEmailAddress', { facilityId: this.facilityId })
await this.store.dispatch('facility/fetchFacilityContactDetailsAndTelecom', { facilityId: this.facilityId })
} else {
throw resp.data
}
Expand Down Expand Up @@ -256,7 +256,7 @@ export default defineComponent({
}
if(!hasError(resp)) {
await this.store.dispatch('facility/fetchFacilityTelecomAndEmailAddress', { facilityId: this.facilityId })
await this.store.dispatch('facility/fetchFacilityContactDetailsAndTelecom', { facilityId: this.facilityId })
} else {
throw resp.data
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/FacilityGeoPointModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default defineComponent({
if(!hasError(resp)) {
geoPoints = this.geoPoint
showToast(translate("Facility latitude and longitude updated successfully."))
await this.store.dispatch('facility/fetchFacilityContactDetails', { facilityId: this.facilityId })
await this.store.dispatch('facility/fetchFacilityContactDetailsAndTelecom', { facilityId: this.facilityId })
} else {
throw resp.data
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/GeoPointPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default defineComponent({
if(!hasError(resp)) {
showToast(translate("Successfully regenerated latitude and longitude for the facility."))
await this.store.dispatch('facility/fetchFacilityContactDetails', { facilityId: this.facilityId })
await this.store.dispatch('facility/fetchFacilityContactDetailsAndTelecom', { facilityId: this.facilityId })
} else {
throw resp.data
}
Expand Down Expand Up @@ -103,7 +103,7 @@ export default defineComponent({
if(!hasError(resp)) {
showToast(translate("Facility latitude and longitude removed successfully."))
await this.store.dispatch('facility/fetchFacilityContactDetails', { facilityId: this.facilityId })
await this.store.dispatch('facility/fetchFacilityContactDetailsAndTelecom', { facilityId: this.facilityId })
} else {
throw resp.data
}
Expand Down
86 changes: 37 additions & 49 deletions src/store/modules/facility/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,70 +227,58 @@ const actions: ActionTree<FacilityState, RootState> = {
commit(types.FACILITY_CURRENT_UPDATED, facility);
},

async fetchFacilityContactDetails({ commit }, payload) {
let postalAddress = {} as any
const params = {
inputFields: {
contactMechPurposeTypeId: 'PRIMARY_LOCATION',
contactMechTypeId: 'POSTAL_ADDRESS',
facilityId: payload.facilityId
},
entityName: "FacilityContactDetailByPurpose",
orderBy: 'fromDate DESC',
filterByDate: 'Y',
fieldList: ['address1', 'address2', 'city', 'contactMechId', 'countryGeoId', 'countryGeoName', 'latitude', 'longitude', 'postalCode', 'stateGeoId', 'stateGeoName', 'toName'],
viewSize: 1
}

try {
const resp = await FacilityService.fetchFacilityContactDetails(params)
if(!hasError(resp)) {
postalAddress = resp.data.docs[0]
postalAddress = {
...postalAddress,
stateProvinceGeoId: postalAddress.stateGeoId
}
delete postalAddress.stateGeoId
} else {
throw resp.data
}
} catch(err) {
logger.error('Failed to fetch the postal address for the facility', err)
}

commit(types.FACILITY_POSTAL_ADDRESS_UPDATED , postalAddress);
},
async fetchFacilityTelecomAndEmailAddress({ commit }, payload) {
const params = {
async fetchFacilityContactDetailsAndTelecom({ commit }, facility) {
let postalAddress = {} as any;
const contactDetails = {} as any;

const payload = {
inputFields: {
contactMechPurposeTypeId: ['PRIMARY_PHONE', 'PRIMARY_EMAIL'],
contactMechPurposeTypeId: ['PRIMARY_PHONE', 'PRIMARY_EMAIL', 'PRIMARY_LOCATION'],
contactMechPurposeTypeId_op: 'in',
contactMechTypeId: ['TELECOM_NUMBER', 'EMAIL_ADDRESS'],
contactMechTypeId: ['TELECOM_NUMBER', 'EMAIL_ADDRESS', 'POSTAL_ADDRESS'],
contactMechTypeId_op: 'in',
facilityId: payload.facilityId
facilityId: facility.facilityId
},
entityName: "FacilityContactDetailByPurpose",
orderBy: 'fromDate DESC',
filterByDate: 'Y',
fieldList: ['contactMechId', 'contactNumber', 'countryCode', 'infoString'],
viewSize: 2
fieldList: ['address1', 'address2', 'city', 'contactMechId', 'contactMechId', 'contactMechTypeId', 'contactNumber', 'countryCode', 'countryGeoId', 'countryGeoName', 'infoString', 'latitude', 'longitude', 'postalCode', 'stateGeoId', 'stateGeoName', 'toName'],
viewSize: 3
}

try {
const resp = await FacilityService.fetchFacilityContactDetails(params)
const resp = await FacilityService.fetchFacilityContactDetails(payload);
if(!hasError(resp)) {
const response = resp.data.docs
const contactDetails = {
telecomNumber: response.find((item: any) => item.infoString === null),
emailAddress: response.find((item: any) => item.infoString !== null)
};

commit(types.FACILITY_TELECOM_AND_EMAIL_ADDRESS_UPDATED , contactDetails);
const docs = resp.data.docs

docs.map((item: any) => {
if(item.contactMechTypeId === "POSTAL_ADDRESS") {
postalAddress = {
...item,
stateProvinceGeoId: item.stateGeoId
}
delete postalAddress.stateGeoId
} else if (item.contactMechTypeId === 'TELECOM_NUMBER') {
contactDetails.telecomNumber = {
contactMechId: item.contactMechId,
contactNumber: item.contactNumber,
countryCode: item.countryCode,
}
} else if (item.contactMechTypeId === 'EMAIL_ADDRESS') {
contactDetails.emailAddress = {
contactMechId: item.contactMechId,
infoString: item.infoString
}
}
})

commit(types.FACILITY_POSTAL_ADDRESS_UPDATED, postalAddress)
commit(types.FACILITY_TELECOM_AND_EMAIL_ADDRESS_UPDATED, contactDetails)
} else {
throw resp.data
}
} catch(err) {
logger.error('Failed to fetch the contact number for the facility', err)
logger.error('Failed to fetch facility contact details and telecom information', err)
}
},

Expand Down
2 changes: 1 addition & 1 deletion src/views/FacilityDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ export default defineComponent({
facilityTypeId: 'VIRTUAL_FACILITY',
facilityTypeId_op: 'notEqual'
})])
await Promise.all([this.store.dispatch('facility/fetchFacilityLocations', { facilityId: this.facilityId }), this.store.dispatch('facility/getFacilityParties', { facilityId: this.facilityId }), this.store.dispatch('facility/fetchFacilityMappings', { facilityId: this.facilityId, facilityIdenTypeIds: Object.keys(this.externalMappingTypes)}), this.store.dispatch('facility/fetchShopifyFacilityMappings', { facilityId: this.facilityId }), this.store.dispatch('facility/getFacilityProductStores', { facilityId: this.facilityId }), this.store.dispatch('util/fetchProductStores'), this.store.dispatch('facility/fetchFacilityContactDetails', { facilityId: this.facilityId }), this.store.dispatch('util/fetchCalendars'), this.store.dispatch('facility/fetchFacilityCalendar', { facilityId: this.facilityId }), this.store.dispatch('facility/fetchFacilityLogins', { facilityId: this.facilityId }), this.store.dispatch('facility/fetchFacilityTelecomAndEmailAddress', { facilityId: this.facilityId })])
await Promise.all([this.store.dispatch('facility/fetchFacilityLocations', { facilityId: this.facilityId }), this.store.dispatch('facility/getFacilityParties', { facilityId: this.facilityId }), this.store.dispatch('facility/fetchFacilityMappings', { facilityId: this.facilityId, facilityIdenTypeIds: Object.keys(this.externalMappingTypes)}), this.store.dispatch('facility/fetchShopifyFacilityMappings', { facilityId: this.facilityId }), this.store.dispatch('facility/getFacilityProductStores', { facilityId: this.facilityId }), this.store.dispatch('util/fetchProductStores'), this.store.dispatch('facility/fetchFacilityContactDetailsAndTelecom', { facilityId: this.facilityId }), this.store.dispatch('util/fetchCalendars'), this.store.dispatch('facility/fetchFacilityCalendar', { facilityId: this.facilityId }), this.store.dispatch('facility/fetchFacilityLogins', { facilityId: this.facilityId })])
this.defaultDaysToShip = this.current.defaultDaysToShip
this.isLoading = false
this.parentFacilityTypeId = this.current.parentFacilityTypeId
Expand Down

0 comments on commit a95ef7c

Please sign in to comment.