dzcode-io / leblad

A JS library providing a list of Algerian administrative areas with many useful APIs.
https://www.npmjs.com/package/@dzcode-io/leblad
MIT License
63 stars 20 forks source link

Fix: Do not search for wilaya by zip code if it's invalid #24

Closed Fcmam5 closed 4 years ago

Fcmam5 commented 4 years ago

In Algeria all ZIP codes are numeric in a form of WILAYA_CODE_XXXX. For example Oran city's code is 31, and it provinces have codes like 31000, 310094 ...

In this line :

https://github.com/dzcode-io/leblad/blob/5837b9e613b414acf84d4bc8f4b9d0b567f84dbc/src/api/getWilayaByZipCode.js#L18

We are directly looking for the given zip code even if it's not a valid number. I suggest at least checking if the parameter is a number before searching.

Fcmam5 commented 4 years ago

@xxKeefer this could be an issue you can work on 😄 !

InternetRamen commented 4 years ago

Hey! This seems interesting. Could my friend @makeBread and I get assigned this?

InternetRamen commented 4 years ago

Or could I work with @xxKeefer ?

Fcmam5 commented 4 years ago

@InternetRamen it would be great if you create a validation method (isValidZipCode) and export it like we did with isValidWilayaCode se we can either use it internally or as a utility function. see isValidWilayaCode.

xxKeefer commented 4 years ago

Hey @Fcmam5 I did a bit a of research as I'm not familiar with the Algerian postal system (i'm from Australia :D) it looks like the function getWilayaByZipCode takes a number, my research tells me that some of the zip codes like those with Adrar have a leading zero in the zip code. Does that mean that say if were looking at the zip code for Abani for example ('01027') its looking to receive the number 1027?

Fcmam5 commented 4 years ago

Hey @Fcmam5 I did a bit a of research as I'm not familiar with the Algerian postal system (i'm from Australia :D) it looks like the function getWilayaByZipCode takes a number, my research tells me that some of the zip codes like those with Adrar have a leading zero in the zip code. Does that mean that say if were looking at the zip code for Abani for example ('01027') its looking to receive the number 1027?

Yes it make sense! So, the first two digits refers to the Wilaya (city code), and for Adrar it's 01 with the leading zero. But I think that we still need to verify if it's a valid number at least (even though the parameter can be a string).

So we'd expect:

Maybe we can for that only using Number.isNaN().


Glad to have you here helping us @xxKeefer ! That's an honour that our project reached Australia 😄 !

InternetRamen commented 4 years ago

@InternetRamen it would be great if you create a validation method (isValidZipCode) and export it like we did with isValidWilayaCode se we can either use it internally or as a utility function. see isValidWilayaCode.

Thank you for responding. I will try to create the method.

Fcmam5 commented 4 years ago

@InternetRamen @xxKeefer already started working on it in #26, would you help us there?

InternetRamen commented 4 years ago

@Fcmam5 Got it

Fcmam5 commented 4 years ago

@Fcmam5 Got it

@InternetRamen I just created #27 , I'll add a description there, that one should be a bit challenging as well 😄

InternetRamen commented 4 years ago

@Fcmam5 I'll try my best! Thanks for the opportunity.