From b0def40288ca900098f5870effa37fc1f0992e90 Mon Sep 17 00:00:00 2001 From: R-Sourabh Date: Tue, 5 Nov 2024 15:35:24 +0530 Subject: [PATCH] Fixed: Zip codes starting with 0 now generate the latitude and longitude correctly(#320) --- src/components/FacilityGeoPointModal.vue | 12 +++++++++--- src/components/GeoPointPopover.vue | 10 ++++++++-- src/views/AddFacilityAddress.vue | 9 ++++++++- src/views/FacilityDetails.vue | 4 +++- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/components/FacilityGeoPointModal.vue b/src/components/FacilityGeoPointModal.vue index da348f09..74978cca 100644 --- a/src/components/FacilityGeoPointModal.vue +++ b/src/components/FacilityGeoPointModal.vue @@ -100,10 +100,12 @@ export default defineComponent({ }, async generateLatLong() { this.isGeneratingLatLong = true + const postalCode = this.geoPoint.postalCode; + const query = postalCode.startsWith('0') ? `${postalCode} OR ${postalCode.substring(1)}` : `${postalCode}`; const payload = { json: { params: { - q: `postcode: ${this.geoPoint.postalCode}` + q: `postcode: ${query}` } } } @@ -113,8 +115,12 @@ export default defineComponent({ if(!hasError(resp) && resp.data.response.docs.length > 0) { const result = resp.data.response.docs[0] - this.geoPoint.latitude = result.latitude - this.geoPoint.longitude = result.longitude + + if (postalCode.startsWith('0') && result.postcode !== postalCode.substring(1)) { + throw new Error(); + } + this.geoPoint.latitude = result.latitude; + this.geoPoint.longitude = result.longitude; } else { throw resp.data } diff --git a/src/components/GeoPointPopover.vue b/src/components/GeoPointPopover.vue index dc659a82..2a938e4a 100644 --- a/src/components/GeoPointPopover.vue +++ b/src/components/GeoPointPopover.vue @@ -48,18 +48,24 @@ export default defineComponent({ emitter.emit('presentLoader') try { + const postalCode = this.postalAddress.postalCode; + const query = postalCode.startsWith('0') ? `${postalCode} OR ${postalCode.substring(1)}` : postalCode; + resp = await UtilService.generateLatLong({ json: { params: { - q: `postcode: ${this.postalAddress.postalCode}` + q: `postcode: ${query}` } } }) if(!hasError(resp) && resp.data.response.docs.length > 0) { generatedLatLong = resp.data.response.docs[0] - if(generatedLatLong.latitude && generatedLatLong.longitude) { + if (postalCode.startsWith('0') && generatedLatLong.postcode !== postalCode.substring(1)) { + throw new Error(); + } + resp = await FacilityService.updateFacilityPostalAddress({ ...this.postalAddress, facilityId: this.facilityId, diff --git a/src/views/AddFacilityAddress.vue b/src/views/AddFacilityAddress.vue index 64ca0378..cba4cf3a 100644 --- a/src/views/AddFacilityAddress.vue +++ b/src/views/AddFacilityAddress.vue @@ -200,10 +200,13 @@ export default defineComponent({ if(this.contactNumber) this.saveTelecomNumber() }, async generateLatLong() { + const postalCode = this.formData.postalCode; + const query = postalCode.startsWith('0') ? `${postalCode} OR ${postalCode.substring(1)}` : `${postalCode}`; + const payload = { json: { params: { - q: `postcode: ${this.formData.postalCode}` + q: `postcode: ${query}` } } } @@ -211,6 +214,10 @@ export default defineComponent({ const resp = await UtilService.generateLatLong(payload) if (!hasError(resp)) { const result = resp.data.response.docs[0] + + if (postalCode.startsWith('0') && result.postcode !== postalCode.substring(1)) { + throw new Error(); + } this.formData.latitude = result.latitude this.formData.longitude = result.longitude } else { diff --git a/src/views/FacilityDetails.vue b/src/views/FacilityDetails.vue index 7b6fe695..285c3092 100644 --- a/src/views/FacilityDetails.vue +++ b/src/views/FacilityDetails.vue @@ -1209,7 +1209,9 @@ export default defineComponent({ const resp = await UtilService.generateLatLong(payload) if(!hasError(resp)) { - this.isRegenerationRequired = !(this.postalAddress.postalCode === resp.data.response.docs[0].postcode) + const postalCode = this.postalAddress.postalCode + const fetchedPostcode = resp.data.response.docs[0].postcode + this.isRegenerationRequired = !(postalCode.startsWith('0') ? postalCode.substring(1) === fetchedPostcode : postalCode === fetchedPostcode); } else { throw resp.data }