From a173b8c70cb5ef3bf3eab9beef29b11fda7d3ad9 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Tue, 6 May 2025 17:02:37 -0700 Subject: [PATCH 01/10] feature/app now receives exchange rates from API --- app.js | 1 + src/public/json/countries.json | 132 +++++++++++++++++++++++++++++ src/public/scripts/exchangeRate.js | 7 ++ src/public/scripts/geolocation.js | 31 +++++-- src/util/currencies.js | 0 src/views/partials/footer.ejs | 4 +- 6 files changed, 167 insertions(+), 8 deletions(-) create mode 100644 src/public/json/countries.json create mode 100644 src/public/scripts/exchangeRate.js create mode 100644 src/util/currencies.js diff --git a/app.js b/app.js index 0310bf1..ce48655 100644 --- a/app.js +++ b/app.js @@ -40,6 +40,7 @@ async function initDatabase() { // For any collection, init here users = await getCollection(db, "users"); plans = await getCollection(db, "plans"); + currencies = await getCollection(db, "currencies"); } /*** ROUTINGS ***/ diff --git a/src/public/json/countries.json b/src/public/json/countries.json new file mode 100644 index 0000000..039a74c --- /dev/null +++ b/src/public/json/countries.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/src/public/scripts/exchangeRate.js b/src/public/scripts/exchangeRate.js new file mode 100644 index 0000000..61cad77 --- /dev/null +++ b/src/public/scripts/exchangeRate.js @@ -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); + }); +} \ No newline at end of file diff --git a/src/public/scripts/geolocation.js b/src/public/scripts/geolocation.js index ebe001b..74e5652 100644 --- a/src/public/scripts/geolocation.js +++ b/src/public/scripts/geolocation.js @@ -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() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(success, error); } } -function success(position) { +async function success(position) { const { latitude, longitude } = position.coords; + let countryCurrency; - fetch("api/location" , { + const countries = await diffCountries(); + + const res = await fetch("api/location" , { method: "POST", headers: { "Content-Type": "application/json" }, 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) { console.error("Geolocation error: ", err); } + +getLocation(); \ No newline at end of file diff --git a/src/util/currencies.js b/src/util/currencies.js new file mode 100644 index 0000000..e69de29 diff --git a/src/views/partials/footer.ejs b/src/views/partials/footer.ejs index 0c2379c..ed0882c 100644 --- a/src/views/partials/footer.ejs +++ b/src/views/partials/footer.ejs @@ -1,11 +1,11 @@ - + \ No newline at end of file From 5bbfde312720808ca1073109c587a65890c69bf7 Mon Sep 17 00:00:00 2001 From: Joaquin Paredes Date: Tue, 6 May 2025 18:13:31 -0700 Subject: [PATCH 02/10] feature/improved data gathering from API --- src/public/scripts/exchangeRate.js | 11 +++++------ src/public/scripts/geolocation.js | 2 +- src/util/currencies.js | 6 ++++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/public/scripts/exchangeRate.js b/src/public/scripts/exchangeRate.js index 61cad77..8d6e08f 100644 --- a/src/public/scripts/exchangeRate.js +++ b/src/public/scripts/exchangeRate.js @@ -1,7 +1,6 @@ -function convert(from) { - fetch(`https://api.frankfurter.dev/v1/latest?base=${from}`) - .then((resp) => resp.json()) - .then((data) => { - console.log(data); - }); +async function convert(from) { + const res = await fetch(`https://api.frankfurter.dev/v1/latest?base=${from}`); + const data = await res.json(); + + return data; } \ No newline at end of file diff --git a/src/public/scripts/geolocation.js b/src/public/scripts/geolocation.js index 74e5652..e5c55b8 100644 --- a/src/public/scripts/geolocation.js +++ b/src/public/scripts/geolocation.js @@ -40,4 +40,4 @@ function error(err) { console.error("Geolocation error: ", err); } -getLocation(); \ No newline at end of file +//getLocation(); \ No newline at end of file diff --git a/src/util/currencies.js b/src/util/currencies.js index e69de29..8eb4ec3 100644 --- a/src/util/currencies.js +++ b/src/util/currencies.js @@ -0,0 +1,6 @@ +const { getCollection } = require('./src/database/connection'); + +async function saveExchangeRates() { + const { currencies } = getCollection(); + await currencies.insertMany(convert()); +} \ No newline at end of file From 1652d05fcd8af1cdba429365d8c8a9fd0c3d694f Mon Sep 17 00:00:00 2001 From: Joaquin Date: Tue, 6 May 2025 18:15:32 -0700 Subject: [PATCH 03/10] feature/push to pull --- src/public/scripts/geolocation.js | 2 +- src/util/currencies.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/public/scripts/geolocation.js b/src/public/scripts/geolocation.js index 74e5652..e5c55b8 100644 --- a/src/public/scripts/geolocation.js +++ b/src/public/scripts/geolocation.js @@ -40,4 +40,4 @@ function error(err) { console.error("Geolocation error: ", err); } -getLocation(); \ No newline at end of file +//getLocation(); \ No newline at end of file diff --git a/src/util/currencies.js b/src/util/currencies.js index e69de29..0519ecb 100644 --- a/src/util/currencies.js +++ b/src/util/currencies.js @@ -0,0 +1 @@ + \ No newline at end of file From 17f11c85df33858db943abeecd4c4166d01a37e0 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Tue, 6 May 2025 21:26:45 -0700 Subject: [PATCH 04/10] feature/improved the getting of rates --- app.js | 18 +++--------- src/public/scripts/exchangeRate.js | 6 ---- src/public/scripts/geolocation.js | 37 +++++------------------- src/router/user.js | 13 +++++++++ src/{public/json => util}/countries.json | 0 src/util/currencies.js | 6 ---- src/util/exchangeRate.js | 18 ++++++++++++ src/views/home.ejs | 2 ++ src/views/partials/footer.ejs | 2 -- 9 files changed, 44 insertions(+), 58 deletions(-) delete mode 100644 src/public/scripts/exchangeRate.js rename src/{public/json => util}/countries.json (100%) delete mode 100644 src/util/currencies.js create mode 100644 src/util/exchangeRate.js diff --git a/app.js b/app.js index ce48655..f8504dd 100644 --- a/app.js +++ b/app.js @@ -6,12 +6,11 @@ const path = require('path'); const joi = require('joi'); require('dotenv').config(); - const app = express(); const port = process.env.PORT || 3000; -const mongoURI = process.env.mongoURI || "mongodb://localhost:27017/"; -const database = process.env.database || "knoldus"; // Database name +const mongoURI = process.env.mongoURI; +const database = process.env.database; // Database name const secret = process.env.secret || "123-secret-xyz"; /*** Sessions ***/ @@ -34,13 +33,14 @@ app.use(express.json()); const { connectMongo, getCollection } = require("./src/database/connection"); let users; +let rates; async function initDatabase() { const db = await connectMongo(mongoURI, database); // For any collection, init here users = await getCollection(db, "users"); plans = await getCollection(db, "plans"); - currencies = await getCollection(db, "currencies"); + rates = await getCollection(db, "rates"); } /*** ROUTINGS ***/ @@ -72,16 +72,6 @@ app.get('/aboutUs', (req, res) => { return res.status(status.Ok); }); -app.post('/api/location', async (req,res) => { - const { latitude, longitude } = req.body; - - const response = await fetch(`https://maps.googleapis.com/maps/api/geocode/json?latlng=${latitude},${longitude}&result_type=country&key=${process.env.geolocation_api}`); - - const data = await response.json(); - - res.json(data); -}); - // Initialize database and start app initDatabase().then(() => { console.log("Successfully connected to MongoDB"); diff --git a/src/public/scripts/exchangeRate.js b/src/public/scripts/exchangeRate.js deleted file mode 100644 index 8d6e08f..0000000 --- a/src/public/scripts/exchangeRate.js +++ /dev/null @@ -1,6 +0,0 @@ -async function convert(from) { - const res = await fetch(`https://api.frankfurter.dev/v1/latest?base=${from}`); - const data = await res.json(); - - return data; -} \ No newline at end of file diff --git a/src/public/scripts/geolocation.js b/src/public/scripts/geolocation.js index e5c55b8..e4a48e2 100644 --- a/src/public/scripts/geolocation.js +++ b/src/public/scripts/geolocation.js @@ -1,43 +1,20 @@ -async function diffCountries() { - const res = await fetch("/static/json/countries.json"); - const data = await res.json(); - - return data.countries; -} - function getLocation() { if (navigator.geolocation) { - navigator.geolocation.getCurrentPosition(success, error); + navigator.geolocation.getCurrentPosition(getLatestExchange, error); } } -async function success(position) { - const { latitude, longitude } = position.coords; - let countryCurrency; - - const countries = await diffCountries(); - - const res = await fetch("api/location" , { - method: "POST", - headers: { - "Content-Type": "application/json" - }, - body: JSON.stringify({ latitude, longitude }) - }); - +async function getLatestExchange(position) { + let lat = position.coords.latitude; + let lon = position.coords.longitude; + const res = await fetch(`/exRates/${lat}/${lon}`); const data = await res.json(); - countries.forEach(country => { - if (country.country === data.results[0].formatted_address) { - countryCurrency = country.currency_abbreviation; - - convert(countryCurrency); - } - }); + console.log(data); } function error(err) { console.error("Geolocation error: ", err); } -//getLocation(); \ No newline at end of file +getLocation(); \ No newline at end of file diff --git a/src/router/user.js b/src/router/user.js index 9daa7cb..60bf114 100644 --- a/src/router/user.js +++ b/src/router/user.js @@ -1,4 +1,5 @@ const status = require("../util/statuses"); +const getRates = require("../util/exchangeRate"); const bcrypt = require('bcrypt'); const joi = require("joi"); const salt = 12; @@ -222,5 +223,17 @@ module.exports = (middleware, users, plans) => { }); }); + router.get("/exRates/:lat/:lon", async (req, res) => { + if (!req.session.rates || Object.keys(req.session.rates).length == 0) { + const response = await fetch(`https://maps.googleapis.com/maps/api/geocode/json?latlng=${req.params.lat},${req.params.lon}&result_type=country&key=${process.env.geolocation_api}`); + const data = await response.json(); + + let country = data.results[0].formatted_address; + req.session.rates = await getRates(country); + } + + return res.status(status.Ok).send({ rates: req.session.rates }); + }) + return router; }; diff --git a/src/public/json/countries.json b/src/util/countries.json similarity index 100% rename from src/public/json/countries.json rename to src/util/countries.json diff --git a/src/util/currencies.js b/src/util/currencies.js deleted file mode 100644 index 712720d..0000000 --- a/src/util/currencies.js +++ /dev/null @@ -1,6 +0,0 @@ -const { getCollection } = require('./src/database/connection'); - -async function saveExchangeRates() { - const { currencies } = getCollection(); - await currencies.insertMany(convert()); -} diff --git a/src/util/exchangeRate.js b/src/util/exchangeRate.js new file mode 100644 index 0000000..6313988 --- /dev/null +++ b/src/util/exchangeRate.js @@ -0,0 +1,18 @@ +const countries = require("./countries.json").countries; + +async function getRates(country) { + let abbr; + countries.forEach(c => { + if (c.country === country) { + abbr = c.currency_abbreviation; + } + }); + + const res = await fetch(`https://api.frankfurter.dev/v1/latest?base=${abbr}`); + const data = await res.json(); + let rates = data.rates; + + return rates; +} + +module.exports = getRates; \ No newline at end of file diff --git a/src/views/home.ejs b/src/views/home.ejs index 3637163..b3b69e7 100644 --- a/src/views/home.ejs +++ b/src/views/home.ejs @@ -11,5 +11,7 @@ <% } %> + + <%- include("./partials/navBar") %> <%- include("./partials/footer") %> diff --git a/src/views/partials/footer.ejs b/src/views/partials/footer.ejs index ed0882c..ef5e262 100644 --- a/src/views/partials/footer.ejs +++ b/src/views/partials/footer.ejs @@ -5,7 +5,5 @@ - - \ No newline at end of file From 2ad43139defd3a5f1c311f8281db7c3a1dd23679 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Wed, 7 May 2025 13:06:22 -0700 Subject: [PATCH 05/10] merged dev and added some challenge 1 functionality --- .vscode/settings.json | 4 + app.js | 2 - src/public/scripts/geolocation.js | 4 +- src/public/scripts/header.js | 0 src/public/svgs/assets.svg | 4 + src/public/svgs/dashboard.svg | 3 + src/public/svgs/flags/AUD.svg | 8 + src/public/svgs/flags/BRL.svg | 45 ++++ src/public/svgs/flags/CAD.svg | 4 + src/public/svgs/flags/CNY.svg | 11 + src/public/svgs/flags/GBP.svg | 7 + src/public/svgs/flags/INR.svg | 25 ++ src/public/svgs/flags/JPY.svg | 11 + src/public/svgs/flags/MXN.svg | 382 +++++++++++++++++++++++++++++ src/public/svgs/flags/RUB.svg | 5 + src/public/svgs/flags/USD.svg | 9 + src/public/svgs/more.svg | 3 + src/public/svgs/plans.svg | 3 + src/router/user.js | 8 +- src/util/exchangeRate.js | 2 +- src/views/dashboard.ejs | 184 +++++++------- src/views/home.ejs | 16 -- src/views/partials/fileHeader.ejs | 2 +- src/views/partials/footer.ejs | 2 +- src/views/partials/header.ejs | 28 ++- src/views/partials/headerStart.ejs | 2 +- src/views/partials/navBar.ejs | 17 +- 27 files changed, 656 insertions(+), 135 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 src/public/scripts/header.js create mode 100644 src/public/svgs/assets.svg create mode 100644 src/public/svgs/dashboard.svg create mode 100644 src/public/svgs/flags/AUD.svg create mode 100644 src/public/svgs/flags/BRL.svg create mode 100644 src/public/svgs/flags/CAD.svg create mode 100644 src/public/svgs/flags/CNY.svg create mode 100644 src/public/svgs/flags/GBP.svg create mode 100644 src/public/svgs/flags/INR.svg create mode 100644 src/public/svgs/flags/JPY.svg create mode 100644 src/public/svgs/flags/MXN.svg create mode 100644 src/public/svgs/flags/RUB.svg create mode 100644 src/public/svgs/flags/USD.svg create mode 100644 src/public/svgs/more.svg create mode 100644 src/public/svgs/plans.svg delete mode 100644 src/views/home.ejs diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c8a7ed4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "editor.fontFamily": "Monocraft", + "editor.fontLigatures": true +} \ No newline at end of file diff --git a/app.js b/app.js index fc5dbb2..1945cac 100644 --- a/app.js +++ b/app.js @@ -33,14 +33,12 @@ app.use(express.json()); const { connectMongo, getCollection } = require("./src/database/connection"); let users; -let rates; async function initDatabase() { const db = await connectMongo(mongoURI, database); // For any collection, init here users = await getCollection(db, "users"); plans = await getCollection(db, "plans"); - rates = await getCollection(db, "rates"); } /*** ROUTINGS ***/ diff --git a/src/public/scripts/geolocation.js b/src/public/scripts/geolocation.js index e4a48e2..4bdf42a 100644 --- a/src/public/scripts/geolocation.js +++ b/src/public/scripts/geolocation.js @@ -15,6 +15,4 @@ async function getLatestExchange(position) { function error(err) { console.error("Geolocation error: ", err); -} - -getLocation(); \ No newline at end of file +} \ No newline at end of file diff --git a/src/public/scripts/header.js b/src/public/scripts/header.js new file mode 100644 index 0000000..e69de29 diff --git a/src/public/svgs/assets.svg b/src/public/svgs/assets.svg new file mode 100644 index 0000000..824466d --- /dev/null +++ b/src/public/svgs/assets.svg @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/src/public/svgs/dashboard.svg b/src/public/svgs/dashboard.svg new file mode 100644 index 0000000..e10e231 --- /dev/null +++ b/src/public/svgs/dashboard.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/public/svgs/flags/AUD.svg b/src/public/svgs/flags/AUD.svg new file mode 100644 index 0000000..96e8076 --- /dev/null +++ b/src/public/svgs/flags/AUD.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/public/svgs/flags/BRL.svg b/src/public/svgs/flags/BRL.svg new file mode 100644 index 0000000..fe1d416 --- /dev/null +++ b/src/public/svgs/flags/BRL.svg @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/public/svgs/flags/CAD.svg b/src/public/svgs/flags/CAD.svg new file mode 100644 index 0000000..c9b23b4 --- /dev/null +++ b/src/public/svgs/flags/CAD.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/public/svgs/flags/CNY.svg b/src/public/svgs/flags/CNY.svg new file mode 100644 index 0000000..10d3489 --- /dev/null +++ b/src/public/svgs/flags/CNY.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/public/svgs/flags/GBP.svg b/src/public/svgs/flags/GBP.svg new file mode 100644 index 0000000..7991383 --- /dev/null +++ b/src/public/svgs/flags/GBP.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/public/svgs/flags/INR.svg b/src/public/svgs/flags/INR.svg new file mode 100644 index 0000000..bc47d74 --- /dev/null +++ b/src/public/svgs/flags/INR.svg @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/public/svgs/flags/JPY.svg b/src/public/svgs/flags/JPY.svg new file mode 100644 index 0000000..cc1c181 --- /dev/null +++ b/src/public/svgs/flags/JPY.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/public/svgs/flags/MXN.svg b/src/public/svgs/flags/MXN.svg new file mode 100644 index 0000000..5a67d62 --- /dev/null +++ b/src/public/svgs/flags/MXN.svg @@ -0,0 +1,382 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/public/svgs/flags/RUB.svg b/src/public/svgs/flags/RUB.svg new file mode 100644 index 0000000..cf24301 --- /dev/null +++ b/src/public/svgs/flags/RUB.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/public/svgs/flags/USD.svg b/src/public/svgs/flags/USD.svg new file mode 100644 index 0000000..9cfd0c9 --- /dev/null +++ b/src/public/svgs/flags/USD.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/public/svgs/more.svg b/src/public/svgs/more.svg new file mode 100644 index 0000000..d0b697f --- /dev/null +++ b/src/public/svgs/more.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/src/public/svgs/plans.svg b/src/public/svgs/plans.svg new file mode 100644 index 0000000..70fb205 --- /dev/null +++ b/src/public/svgs/plans.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/router/user.js b/src/router/user.js index e5cb2fa..35ef92b 100644 --- a/src/router/user.js +++ b/src/router/user.js @@ -11,7 +11,7 @@ module.exports = (middleware, users, plans) => { router.use(middleware); router.get('/home', async (req, res) => { - res.render('dashboard', { user: req.user }); + res.render('dashboard', { user: req.user, location: req.session.country, countriesRates: req.session.rates }); return res.status(status.Ok); }); @@ -270,8 +270,10 @@ module.exports = (middleware, users, plans) => { const response = await fetch(`https://maps.googleapis.com/maps/api/geocode/json?latlng=${req.params.lat},${req.params.lon}&result_type=country&key=${process.env.geolocation_api}`); const data = await response.json(); - let country = data.results[0].formatted_address; - req.session.rates = await getRates(country); + country = data.results[0].formatted_address; + let results = await getRates(country); + req.session.rates = results.exRates; + req.session.country = results.abbreviation; } return res.status(status.Ok).send({ rates: req.session.rates }); diff --git a/src/util/exchangeRate.js b/src/util/exchangeRate.js index 6313988..2f5658d 100644 --- a/src/util/exchangeRate.js +++ b/src/util/exchangeRate.js @@ -12,7 +12,7 @@ async function getRates(country) { const data = await res.json(); let rates = data.rates; - return rates; + return { exRates: rates, abbreviation: abbr }; } module.exports = getRates; \ No newline at end of file diff --git a/src/views/dashboard.ejs b/src/views/dashboard.ejs index e4c9b36..be866a1 100644 --- a/src/views/dashboard.ejs +++ b/src/views/dashboard.ejs @@ -1,100 +1,98 @@ <%- include("./partials/fileHeader") %> - <%- include("./partials/header") %> +<%- include("./partials/header") %> -
-

Welcome: <%= user.name %>

- -
- - - Create new plan - -
- -
-
- -
- - - -
-

- Retirement goal

-

- $53k

-
-
-

- Make this percent bar or graph or something  than last - week -

-
+
+

Welcome: <%= user.name %>

+ +
+ + Create new plan +
+ +
+
+ +
+ + + +
+

+ Retirement goal

+

+ $53k

-
-
-

- Retirement goal

-

- $53k

-
-
-

- Make this percent bar or graph or something  than last - week -

-
+
+

+ Make this percent bar or graph or something  than lastweek +

+
+
+
+

+ Retirement goal

+

+ $53k

+
+
+

+ Make this percent bar or graph or something  than last + week +

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + +
- - - - - - - - - - - - - - - - - - - - - - - -
-
-
-

- Retirement goal

-

- $53k

-
-
-

- Make this percent bar or graph or something  than last - week -

-
-
-
-
+
+
+

+ Retirement goal

+

+ $53k

+
+
+

+ Make this percent bar or graph or something  than last + week +

+
+
+
-
-
-
+
+
+
+
- <%- include("./partials/navBar") %> - <%- include("./partials/footer") %> + + + +<%- include("./partials/navBar") %> +<%- include("./partials/footer") %> \ No newline at end of file diff --git a/src/views/home.ejs b/src/views/home.ejs deleted file mode 100644 index 8969d97..0000000 --- a/src/views/home.ejs +++ /dev/null @@ -1,16 +0,0 @@ -<%- include("./partials/fileHeader") %> -<%- include("./partials/header") %> - -
- Welcome: <%= user.email %> - The Dashboard Page - <% if(user.authenticated) { %> - <%= user.email %> - <%= user.errMessage %> - <% } %> -
- - - -<%- include("./partials/navBar") %> -<%- include("./partials/footer") %> diff --git a/src/views/partials/fileHeader.ejs b/src/views/partials/fileHeader.ejs index 35b60ed..b15b69c 100644 --- a/src/views/partials/fileHeader.ejs +++ b/src/views/partials/fileHeader.ejs @@ -7,4 +7,4 @@ RCalculator - \ No newline at end of file + \ No newline at end of file diff --git a/src/views/partials/footer.ejs b/src/views/partials/footer.ejs index d72156e..110cbe0 100644 --- a/src/views/partials/footer.ejs +++ b/src/views/partials/footer.ejs @@ -1,6 +1,6 @@