Revert "Feature: Add territory-to-country mapping for 50+ dependent territories"
This reverts commit 7798179376.
This commit is contained in:
@@ -18,81 +18,21 @@ export interface CountryData {
|
||||
export class WorldBankService {
|
||||
private apiUrl = 'https://api.worldbank.org/v2/country';
|
||||
|
||||
// Map territories to their parent countries for World Bank API
|
||||
private territoryMapping: { [key: string]: string } = {
|
||||
'AX': 'FI', // Åland Islands → Finland
|
||||
'AW': 'NL', // Aruba → Netherlands
|
||||
'BL': 'FR', // Saint Barthélemy → France
|
||||
'BQ': 'NL', // Caribbean Netherlands → Netherlands
|
||||
'CW': 'NL', // Curaçao → Netherlands
|
||||
'GF': 'FR', // French Guiana → France
|
||||
'GL': 'DK', // Greenland → Denmark
|
||||
'GP': 'FR', // Guadeloupe → France
|
||||
'GG': 'GB', // Guernsey → United Kingdom
|
||||
'IM': 'GB', // Isle of Man → United Kingdom
|
||||
'JE': 'GB', // Jersey → United Kingdom
|
||||
'MF': 'FR', // Saint Martin → France
|
||||
'MQ': 'FR', // Martinique → France
|
||||
'NC': 'FR', // New Caledonia → France
|
||||
'PF': 'FR', // French Polynesia → France
|
||||
'PM': 'FR', // Saint Pierre and Miquelon → France
|
||||
'PR': 'US', // Puerto Rico → United States
|
||||
'RE': 'FR', // Réunion → France
|
||||
'SJ': 'NO', // Svalbard and Jan Mayen → Norway
|
||||
'SX': 'NL', // Sint Maarten → Netherlands
|
||||
'TF': 'FR', // French Southern Territories → France
|
||||
'VI': 'US', // U.S. Virgin Islands → United States
|
||||
'WF': 'FR', // Wallis and Futuna → France
|
||||
'YT': 'FR', // Mayotte → France
|
||||
'EH': 'MA', // Western Sahara → Morocco (disputed, using Morocco)
|
||||
'FK': 'GB', // Falkland Islands → United Kingdom
|
||||
'FO': 'DK', // Faroe Islands → Denmark
|
||||
'GI': 'GB', // Gibraltar → United Kingdom
|
||||
'GS': 'GB', // South Georgia → United Kingdom
|
||||
'GU': 'US', // Guam → United States
|
||||
'HM': 'AU', // Heard Island → Australia
|
||||
'AS': 'US', // American Samoa → United States
|
||||
'BM': 'GB', // Bermuda → United Kingdom
|
||||
'BV': 'NO', // Bouvet Island → Norway
|
||||
'IO': 'GB', // British Indian Ocean Territory → United Kingdom
|
||||
'KY': 'GB', // Cayman Islands → United Kingdom
|
||||
'CX': 'AU', // Christmas Island → Australia
|
||||
'CC': 'AU', // Cocos Islands → Australia
|
||||
'CK': 'NZ', // Cook Islands → New Zealand
|
||||
'MS': 'GB', // Montserrat → United Kingdom
|
||||
'NF': 'AU', // Norfolk Island → Australia
|
||||
'NU': 'NZ', // Niue → New Zealand
|
||||
'PN': 'GB', // Pitcairn Islands → United Kingdom
|
||||
'SH': 'GB', // Saint Helena → United Kingdom
|
||||
'TC': 'GB', // Turks and Caicos → United Kingdom
|
||||
'TK': 'NZ', // Tokelau → New Zealand
|
||||
'UM': 'US', // U.S. Minor Outlying Islands → United States
|
||||
'VG': 'GB', // British Virgin Islands → United Kingdom
|
||||
};
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
getCountryData(countryCode: string): Observable<CountryData> {
|
||||
// Check if this is a territory - if so, use parent country
|
||||
const actualCode = this.territoryMapping[countryCode] || countryCode;
|
||||
const url = `${this.apiUrl}/${actualCode}?format=json`;
|
||||
const url = `${this.apiUrl}/${countryCode}?format=json`;
|
||||
|
||||
return this.http.get<any>(url).pipe(
|
||||
map(response => {
|
||||
// Check if API returned an error message
|
||||
if (response[0]?.message) {
|
||||
throw new Error(`World Bank API: ${response[0].message[0].value}`);
|
||||
}
|
||||
|
||||
const country = response[1][0];
|
||||
|
||||
// If this was a territory lookup, customize the name
|
||||
let displayName = country.name || 'N/A';
|
||||
if (countryCode !== actualCode) {
|
||||
displayName = `${this.getTerritoryName(countryCode)} (data from ${country.name})`;
|
||||
}
|
||||
|
||||
return {
|
||||
name: displayName,
|
||||
name: country.name || 'N/A',
|
||||
capital: country.capitalCity || 'N/A',
|
||||
region: country.region?.value || 'N/A',
|
||||
incomeLevel: country.incomeLevel?.value || 'N/A',
|
||||
@@ -102,10 +42,11 @@ export class WorldBankService {
|
||||
}),
|
||||
catchError(error => {
|
||||
console.error(`Failed to fetch data for ${countryCode}:`, error);
|
||||
// Return placeholder data instead of failing completely
|
||||
return of({
|
||||
name: `Territory: ${countryCode}`,
|
||||
name: `Country Code: ${countryCode}`,
|
||||
capital: 'Data not available',
|
||||
region: 'Not in World Bank database',
|
||||
region: 'Not available in World Bank API',
|
||||
incomeLevel: 'N/A',
|
||||
longitude: 'N/A',
|
||||
latitude: 'N/A'
|
||||
@@ -113,26 +54,4 @@ export class WorldBankService {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private getTerritoryName(code: string): string {
|
||||
const names: { [key: string]: string } = {
|
||||
'AX': 'Åland Islands', 'AW': 'Aruba', 'BL': 'Saint Barthélemy',
|
||||
'BQ': 'Caribbean Netherlands', 'CW': 'Curaçao', 'GF': 'French Guiana',
|
||||
'GL': 'Greenland', 'GP': 'Guadeloupe', 'GG': 'Guernsey',
|
||||
'IM': 'Isle of Man', 'JE': 'Jersey', 'MF': 'Saint Martin',
|
||||
'MQ': 'Martinique', 'NC': 'New Caledonia', 'PF': 'French Polynesia',
|
||||
'PM': 'Saint Pierre and Miquelon', 'PR': 'Puerto Rico', 'RE': 'Réunion',
|
||||
'SJ': 'Svalbard and Jan Mayen', 'SX': 'Sint Maarten', 'TF': 'French Southern Territories',
|
||||
'VI': 'U.S. Virgin Islands', 'WF': 'Wallis and Futuna', 'YT': 'Mayotte',
|
||||
'EH': 'Western Sahara', 'FK': 'Falkland Islands', 'FO': 'Faroe Islands',
|
||||
'GI': 'Gibraltar', 'GS': 'South Georgia', 'GU': 'Guam',
|
||||
'HM': 'Heard Island', 'AS': 'American Samoa', 'BM': 'Bermuda',
|
||||
'BV': 'Bouvet Island', 'IO': 'British Indian Ocean Territory', 'KY': 'Cayman Islands',
|
||||
'CX': 'Christmas Island', 'CC': 'Cocos Islands', 'CK': 'Cook Islands',
|
||||
'MS': 'Montserrat', 'NF': 'Norfolk Island', 'NU': 'Niue',
|
||||
'PN': 'Pitcairn Islands', 'SH': 'Saint Helena', 'TC': 'Turks and Caicos',
|
||||
'TK': 'Tokelau', 'UM': 'U.S. Minor Outlying Islands', 'VG': 'British Virgin Islands'
|
||||
};
|
||||
return names[code] || code;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user