Skip to content

Commit

Permalink
Improved: improved the postal code check on facilityDetails page & re…
Browse files Browse the repository at this point in the history
…moved the unnecessary string literals(#320)
  • Loading branch information
R-Sourabh committed Nov 7, 2024
1 parent b0867d5 commit 80a4a62
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
8 changes: 2 additions & 6 deletions src/components/FacilityGeoPointModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
}
}
}
Expand All @@ -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 {
Expand Down
9 changes: 3 additions & 6 deletions src/components/GeoPointPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions src/views/AddFacilityAddress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,19 @@ 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}`
}
}
}
try {
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 {
Expand Down
2 changes: 1 addition & 1 deletion src/views/FacilityDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 80a4a62

Please sign in to comment.