feature/app now receives exchange rates from API
This commit is contained in:
1 parent
f3a1a2191a
commit
a173b8c70c
6 files changed
+167
-8
No files matched your search
@@ -40,6 +40,7 @@ async function initDatabase() {
|
|||||||
// For any collection, init here
|
// For any collection, init here
|
||||||
users = await getCollection(db, "users");
|
users = await getCollection(db, "users");
|
||||||
plans = await getCollection(db, "plans");
|
plans = await getCollection(db, "plans");
|
||||||
|
currencies = await getCollection(db, "currencies");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** ROUTINGS ***/
|
/*** ROUTINGS ***/
|
||||||
|
|||||||
@@ -0,0 +1,132 @@
|
|||||||
|
{
|
||||||
|
"countries": [
|
||||||
|
{
|
||||||
|
"country": "United States",
|
||||||
|
"currency_abbreviation": "USD"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Eurozone",
|
||||||
|
"currency_abbreviation": "EUR"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "United Kingdom",
|
||||||
|
"currency_abbreviation": "GBP"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Japan",
|
||||||
|
"currency_abbreviation": "JPY"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Switzerland",
|
||||||
|
"currency_abbreviation": "CHF"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Canada",
|
||||||
|
"currency_abbreviation": "CAD"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Australia",
|
||||||
|
"currency_abbreviation": "AUD"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "China",
|
||||||
|
"currency_abbreviation": "CNY"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "India",
|
||||||
|
"currency_abbreviation": "INR"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Russia",
|
||||||
|
"currency_abbreviation": "RUB"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Brazil",
|
||||||
|
"currency_abbreviation": "BRL"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Mexico",
|
||||||
|
"currency_abbreviation": "MXN"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "South Korea",
|
||||||
|
"currency_abbreviation": "KRW"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Indonesia",
|
||||||
|
"currency_abbreviation": "IDR"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Bulgaria",
|
||||||
|
"currency_abbreviation": "BGN"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Czech Republic",
|
||||||
|
"currency_abbreviation": "CZK"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Denmark",
|
||||||
|
"currency_abbreviation": "DKK"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Hong Kong",
|
||||||
|
"currency_abbreviation": "HKD"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Hungary",
|
||||||
|
"currency_abbreviation": "HUF"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Israel",
|
||||||
|
"currency_abbreviation": "ILS"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Iceland",
|
||||||
|
"currency_abbreviation": "ISK"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Malaysia",
|
||||||
|
"currency_abbreviation": "MYR"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Norway",
|
||||||
|
"currency_abbreviation": "NOK"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "New Zealand",
|
||||||
|
"currency_abbreviation": "NZD"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Philippines",
|
||||||
|
"currency_abbreviation": "PHP"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Poland",
|
||||||
|
"currency_abbreviation": "PLN"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Romania",
|
||||||
|
"currency_abbreviation": "RON"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Sweden",
|
||||||
|
"currency_abbreviation": "SEK"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Singapore",
|
||||||
|
"currency_abbreviation": "SGD"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Thailand",
|
||||||
|
"currency_abbreviation": "THB"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "Turkey",
|
||||||
|
"currency_abbreviation": "TRY"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "South Africa",
|
||||||
|
"currency_abbreviation": "ZAR"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
function convert(from) {
|
||||||
|
fetch(`https://api.frankfurter.dev/v1/latest?base=${from}`)
|
||||||
|
.then((resp) => resp.json())
|
||||||
|
.then((data) => {
|
||||||
|
console.log(data);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,24 +1,43 @@
|
|||||||
|
async function diffCountries() {
|
||||||
|
const res = await fetch("/static/json/countries.json");
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
return data.countries;
|
||||||
|
}
|
||||||
|
|
||||||
function getLocation() {
|
function getLocation() {
|
||||||
if (navigator.geolocation) {
|
if (navigator.geolocation) {
|
||||||
navigator.geolocation.getCurrentPosition(success, error);
|
navigator.geolocation.getCurrentPosition(success, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function success(position) {
|
async function success(position) {
|
||||||
const { latitude, longitude } = position.coords;
|
const { latitude, longitude } = position.coords;
|
||||||
|
let countryCurrency;
|
||||||
|
|
||||||
fetch("api/location" , {
|
const countries = await diffCountries();
|
||||||
|
|
||||||
|
const res = await fetch("api/location" , {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ latitude, longitude })
|
body: JSON.stringify({ latitude, longitude })
|
||||||
}).then(res => res.json())
|
});
|
||||||
.then(data => {
|
|
||||||
console.log(data.results[0].formatted_address);
|
const data = await res.json();
|
||||||
})
|
|
||||||
|
countries.forEach(country => {
|
||||||
|
if (country.country === data.results[0].formatted_address) {
|
||||||
|
countryCurrency = country.currency_abbreviation;
|
||||||
|
|
||||||
|
convert(countryCurrency);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function error(err) {
|
function error(err) {
|
||||||
console.error("Geolocation error: ", err);
|
console.error("Geolocation error: ", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLocation();
|
||||||
Whitespace-only changes.
@@ -1,11 +1,11 @@
|
|||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
<div class="fixed bottom-0 left-0 z-50 hidden lg:block w-full h-16 bg-gray-100 dark:bg-gray-800 border-t border-gray-200 dark:border-gray-700 p-6 text-center text-gray-500 dark:text-gray-400 text-sm">
|
<div class="fixed bottom-0 left-0 z-50 hidden lg:block w-full h-16 bg-gray-100 dark:bg-gray-800 border-t border-gray-200 dark:border-gray-700 p-6 text-center text-gray-500 dark:text-gray-400 text-sm">
|
||||||
<div class="container mx-auto">
|
<div class="container mx-auto">
|
||||||
<p>© 2025 RCalculator. All rights reserved.</p>
|
<p>© 2025 RCalculator. All rights reserved.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
<script src="/static/scripts/exchangeRate.js"></script>
|
||||||
<script src="/static/scripts/geolocation.js"></script>
|
<script src="/static/scripts/geolocation.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in new issue
Block a user