From 80a4a62db3d7057686e33b6ce5aeb32367a82d11 Mon Sep 17 00:00:00 2001 From: R-Sourabh Date: Thu, 7 Nov 2024 11:05:06 +0530 Subject: [PATCH] Improved: improved the postal code check on facilityDetails page & removed the unnecessary string literals(#320) --- src/components/FacilityGeoPointModal.vue | 8 ++------ src/components/GeoPointPopover.vue | 9 +++------ src/views/AddFacilityAddress.vue | 8 ++------ src/views/FacilityDetails.vue | 2 +- 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/components/FacilityGeoPointModal.vue b/src/components/FacilityGeoPointModal.vue index da8c79d..75e01d6 100644 --- a/src/components/FacilityGeoPointModal.vue +++ b/src/components/FacilityGeoPointModal.vue @@ -101,11 +101,11 @@ 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 query = postalCode.startsWith('0') ? `${postalCode} OR ${postalCode.substring(1)}` : postalCode; const payload = { json: { params: { - q: 'postcode: ' + query + q: `postcode: ${query}` } } } @@ -115,10 +115,6 @@ export default defineComponent({ if(!hasError(resp) && resp.data.response.docs.length > 0) { const result = resp.data.response.docs[0] - - if (postalCode.startsWith('0') && result.postcode !== postalCode.substring(1)) { - throw new Error(); - } this.geoPoint.latitude = result.latitude; this.geoPoint.longitude = result.longitude; } else { diff --git a/src/components/GeoPointPopover.vue b/src/components/GeoPointPopover.vue index 8bee828..196236e 100644 --- a/src/components/GeoPointPopover.vue +++ b/src/components/GeoPointPopover.vue @@ -49,23 +49,20 @@ export default defineComponent({ try { const postalCode = this.postalAddress.postalCode; - const query = postalCode.startsWith('0') ? postalCode + ' OR ' + postalCode.substring(1) : postalCode; + const query = postalCode.startsWith('0') ? `${postalCode} OR ${postalCode.substring(1)}` : postalCode; resp = await UtilService.generateLatLong({ json: { params: { - q: 'postcode: ' + query + 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(); - } + if(generatedLatLong.latitude && generatedLatLong.longitude) { resp = await FacilityService.updateFacilityPostalAddress({ ...this.postalAddress, facilityId: this.facilityId, diff --git a/src/views/AddFacilityAddress.vue b/src/views/AddFacilityAddress.vue index b376bfd..1c1188e 100644 --- a/src/views/AddFacilityAddress.vue +++ b/src/views/AddFacilityAddress.vue @@ -201,12 +201,12 @@ export default defineComponent({ }, async generateLatLong() { const postalCode = this.formData.postalCode; - const query = postalCode.startsWith('0') ? postalCode + ' OR ' + postalCode.substring(1) : postalCode; + const query = postalCode.startsWith('0') ? `${postalCode} OR ${postalCode.substring(1)}` : postalCode; const payload = { json: { params: { - q: 'postcode: ' + query + q: `postcode: ${query}` } } } @@ -214,10 +214,6 @@ 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 285c309..bf111f8 100644 --- a/src/views/FacilityDetails.vue +++ b/src/views/FacilityDetails.vue @@ -1211,7 +1211,7 @@ export default defineComponent({ if(!hasError(resp)) { const postalCode = this.postalAddress.postalCode const fetchedPostcode = resp.data.response.docs[0].postcode - this.isRegenerationRequired = !(postalCode.startsWith('0') ? postalCode.substring(1) === fetchedPostcode : postalCode === fetchedPostcode); + this.isRegenerationRequired = !(postalCode.startsWith('0') ? postalCode.substring(1) === fetchedPostcode || postalCode === fetchedPostcode : postalCode === fetchedPostcode); } else { throw resp.data }