-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
51 lines (42 loc) · 1.6 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import axios from 'axios';
import { RESOURCE_URL } from './utilities/constants.js';
class CountryRegion {
blob = null;
_getBlob = async () => {
return this.blob ??= await axios.get(`${RESOURCE_URL}`);
}
getCountries = async () =>
(await this._getBlob()).data.map(item => {
return {
name: item?.country?.name,
id: item?.country?.id
}
});
getCountry = async (id) => {
const country = (await this._getBlob())
.data.find(item => item?.country?.id == id);
if (!country) return null;
return {
name: country?.country?.name,
id: country?.country?.id
}
}
getStates = async (countryId) =>
(await this._getBlob())
.data.find(item => item?.country?.id == countryId)
?.country?.states ?? null;
getState = async (countryId, stateId) =>
(await this._getBlob())
.data.find(item => item?.country?.id == countryId)
?.country?.states?.find(item => item?.id == stateId) ?? null;
getLGAs = async (countryId, stateId) =>
(await this._getBlob())
.data.find(item => item?.country?.id == countryId)
?.country?.states?.find(item => item?.id == stateId)?.locals ?? null;
getLGA = async (countryId, stateId, lgaId) =>
(await this._getBlob())
.data.find(item => item?.country?.id == countryId)
.country?.states.find(item => item?.id == stateId)
?.locals?.find(item => item?.id == lgaId) ?? null;
}
export default CountryRegion;