diff --git a/src/components/FacilityAddressModal.vue b/src/components/FacilityAddressModal.vue index 03c88f6..cafa946 100644 --- a/src/components/FacilityAddressModal.vue +++ b/src/components/FacilityAddressModal.vue @@ -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 @@ -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 } @@ -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 } diff --git a/src/components/FacilityGeoPointModal.vue b/src/components/FacilityGeoPointModal.vue index 51cd9ac..9b97f10 100644 --- a/src/components/FacilityGeoPointModal.vue +++ b/src/components/FacilityGeoPointModal.vue @@ -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 } diff --git a/src/components/GeoPointPopover.vue b/src/components/GeoPointPopover.vue index 196236e..cd7bb57 100644 --- a/src/components/GeoPointPopover.vue +++ b/src/components/GeoPointPopover.vue @@ -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 } @@ -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 } diff --git a/src/store/modules/facility/actions.ts b/src/store/modules/facility/actions.ts index eb81b25..98de53f 100644 --- a/src/store/modules/facility/actions.ts +++ b/src/store/modules/facility/actions.ts @@ -227,70 +227,58 @@ const actions: ActionTree = { 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) } }, diff --git a/src/views/FacilityDetails.vue b/src/views/FacilityDetails.vue index 6b58b13..8b86f08 100644 --- a/src/views/FacilityDetails.vue +++ b/src/views/FacilityDetails.vue @@ -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