From 98e04ecd630ce057e71dd81e220b7bc8b5ce1f8d Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 11 Oct 2020 18:37:41 +0200 Subject: [PATCH 1/2] Return object renamed from wins --> highscore. --- api/lottery.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/lottery.js b/api/lottery.js index eaf6815..bdd9032 100644 --- a/api/lottery.js +++ b/api/lottery.js @@ -120,7 +120,7 @@ const byName = (req, res) => { .then(highscore => res.send({ message: `Lottery winnings for name: ${ name }.`, name: highscore.name, - wins: highscore.wins + highscore: highscore.wins })) } From f44402cf031c9a2441dd9161184176fd869e190e Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 11 Oct 2020 18:38:21 +0200 Subject: [PATCH 2/2] Function squased w/ merging, re-added. --- src/api.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/api.js b/src/api.js index e747b1f..2e0a9e2 100644 --- a/src/api.js +++ b/src/api.js @@ -345,6 +345,19 @@ const historyByDate = (date) => { }); } +const getWinnerByName = (name) => { + const encodedName = encodeURIComponent(name) + const url = new URL(`/api/lottery/by-name/${name}`, BASE_URL); + + return fetch(url.href).then(resp => { + if (resp.ok) { + return resp.json(); + } else { + return handleErrors(resp); + } + }) +} + export { statistics, colorStatistics, @@ -377,5 +390,6 @@ export { getAmIWinner, postWineChosen, historyAll, - historyByDate + historyByDate, + getWinnerByName };