Added foreign rep tables response and data

This commit is contained in:
Alexis
2023-05-02 19:38:28 +02:00
parent 17914d337b
commit 61b1b2d953
2 changed files with 236 additions and 3 deletions

View File

@@ -49,7 +49,7 @@ app.use('/rep', async (req, res) => {
const closestCity = await (await fetch( const closestCity = await (await fetch(
`https://geo.api.gouv.fr/communes?lat=${lat}&lon=${lon}` `https://geo.api.gouv.fr/communes?lat=${lat}&lon=${lon}`
)).json(); )).json();
codeDepartement = closestCity[0]?.codeDepartement let codeDepartement = closestCity[0]?.codeDepartement
// Usually means we're out of France // Usually means we're out of France
if (!codeDepartement) { if (!codeDepartement) {
@@ -65,6 +65,26 @@ app.use('/rep', async (req, res) => {
const countryName = gaData.results.find((addr) => addr.types.find((type) => type === "country"))?.formatted_address const countryName = gaData.results.find((addr) => addr.types.find((type) => type === "country"))?.formatted_address
// From country name, get the associated rep // From country name, get the associated rep
const foreignLookupTable = require('./rep-lookup-foreign')
let circoForeign
// foreignLookupTable.forEach((value, index) => {
// if (value.includes(countryName)) {
// circoForeign = index
// }
// });
for (const [key, value] of Object.entries(foreignLookupTable)) {
if (value.includes(countryName)) {
circoForeign = key
}
}
// If a code is found, send the associated file containing the representant data
const repFile = readFileSync(join(__dirname, `public/reps/${lookupTable[circoForeign]}.json`), 'utf-8')
res.end(repFile)
return
} else { } else {
// If not in a valid country, ends req // If not in a valid country, ends req
res.status(400).json({ res.status(400).json({
@@ -73,13 +93,12 @@ app.use('/rep', async (req, res) => {
return return
} }
} catch (err) { } catch (err) {
console.log(err)
res.status(500).json({ res.status(500).json({
"message": "Une erreur est survenue à cause de l'API Google Maps. Nous vous recommandez de réessayer plus tard." "message": "Une erreur est survenue à cause de l'API Google Maps. Nous vous recommandez de réessayer plus tard."
}); });
return return
} }
} }
// Changes dep code to format of filenames on server, ie "075" // Changes dep code to format of filenames on server, ie "075"

214
rep-lookup-foreign.js Normal file
View File

@@ -0,0 +1,214 @@
'use strict';
module.exports = {
"099-01": [
"Canada",
"United States",
],
"099-02": [
"Belize",
"Costa Rica",
"Guatemala",
"Honduras",
"Mexico",
"Nicaragua",
"Panama",
"Salvador",
"Bolivia",
"Colombia",
"Ecuador",
"Peru",
"Venezuela",
"Brazil",
"Guyana",
"Suriname",
"Argentina",
"Chile",
"Paraguay",
"Uruguay",
"Antigua and Barbuda",
"The Bahamas",
"Barbados",
"Cuba",
"Dominican Republic",
"Dominica",
"Grenada",
"Haiti",
"Jamaica",
"St Kitts and Nevis",
"St Lucia",
"St Vincent and the Grenadines",
"Trinidad and Tobago",
],
"099-03": [
"Ireland",
"United Kingdom",
"Denmark",
"Estonia",
"Finland",
"Iceland",
"Latvia",
"Lituania",
"Norway",
"Sweden",
],
"099-04": [
"Belgium",
"Netherlands",
"Luxembourg",
],
"099-05": [
"Andorra",
"Spain",
"Monaco",
"Portugal",
],
"099-06": [
"Liechtenstein",
"Switzerland",
],
"099-07": [
"Germany",
"Albania",
"Austria",
"Bosnia and Herzegovina",
"Bulgaria",
"Croatia",
"Hungary",
"North Macedonia",
"Poland",
"Romania",
"Serbia and Montenegro",
"Slovenia",
"Czechia",
"Slovakia",
],
"099-08": [
"Italia",
"Malta",
"San Marino",
"Holy See",
"Cyprus",
"Greece",
"Turkey",
"Israel"
],
"099-09": [
"Algeria",
"Morocco",
"Libya",
"Tunisia",
"Burkina Faso",
"Mali",
"Niger",
"Mauritania",
"Cabo Verde",
"The Gambia",
"Guinea",
"Guinea-Bissau",
"Senegal",
"Sierra Leone",
"Ivory Coast",
"Liberia",
],
"099-10": [
"Bostwana",
"Lesotho",
"Malawi",
"Mozambique",
"Namibia",
"Swaziland",
"Zambia",
"Zimbabwe",
"Comoros",
"Madagascar",
"Mauritius",
"Seychelles",
"Egypt",
"Sudan",
"Djibouti",
"Eritrea",
"Ethiopia",
"Somalia",
"Burundi",
"Kenya",
"Uganda",
"Rwanda",
"Tanzania",
"Benign",
"Ghana",
"Nigeria",
"Togo",
"Cameroon",
"Central African Republic",
"Chad",
"Gabon",
"Equatorial Guinea",
"São Tomé and Príncipe",
"Angola",
"Congolese",
"Democratic Republic of Congo",
"Iraq",
"Jordan",
"Lebanon",
"Syria",
"Saudi Arabia",
"Bahrain",
"United Arab Emirates",
"Kuwait",
"Oman",
"Qatar",
"Yemen",
],
"099-11": [
"Armenia",
"Azerbaijan",
"Belarus",
"Georgia",
"Kazakhstan",
"Kyrgyzstan",
"Moldova",
"Uzbekistan",
"Russia",
"Tajikistan",
"Turkmenistan",
"Ukraine",
"Afghani",
"Bangladeshi",
"India",
"Iran",
"Maldives",
"Nepal",
"Pakistan",
"Sri Lanka",
"China",
"South Korea",
"Japan",
"Mongolia",
"Burma",
"Brunei",
"Cambodia",
"Indonesia",
"Laos",
"Malaysia",
"Palau",
"Philippines",
"Singapore",
"Thailand",
"East Timor",
"Vietnam",
"Australia",
"Fiji",
"Kiribati",
"Marshall",
"Micronesia",
"Nauru",
"New Zealand",
"Papua New Guinea",
"Solomon",
"Samoa",
"Tonga",
"Tuvalu",
"Vanuatu",
],
}