Skip to content

Commit fb3b187

Browse files
authored
Fix: Switch to restcountries v3 API and use common country name (#158)
1 parent efe065d commit fb3b187

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

scripts/init-countries.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ async function main () {
4848
try {
4949
const countryPromises = countries.data.map((country, index) => {
5050
const text = 'INSERT INTO country(id, country_id, name, code, region, subregion, lat, long) VALUES($1, $2, $3, $4, $5, $6, $7, $8)'
51-
let code = country.alpha2Code
51+
let code = country.cca2
5252
if (!code) {
53-
code = country.alpha3Code
53+
code = country.cca3
5454
}
5555

5656
let lat, long = ''
@@ -62,8 +62,8 @@ async function main () {
6262

6363
const region = country.region || "unknown region"
6464
const subregion = country.subregion || "unknown subregion"
65-
66-
return client.query(text, [index, index, country.name, code, region, subregion, lat, long])
65+
let name = country.name["common"]
66+
return client.query(text, [index, index, name, code, region, subregion, lat, long])
6767
})
6868

6969
await Promise.all(countryPromises)
@@ -112,7 +112,7 @@ async function main () {
112112
}
113113

114114
async function getCountries () {
115-
return axios.get('https://restcountries.com/v2/all')
115+
return axios.get('https://restcountries.com/v3/all')
116116
}
117117

118118
async function getCities () {

0 commit comments

Comments
 (0)