From e87a59b1e64f9bb513f8c0bb724e060c3bd3ed1d Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 9 Oct 2020 00:55:47 +0200 Subject: [PATCH] Helper func for lottery/by-name. --- src/api.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/api.js b/src/api.js index 05145b9..2733701 100644 --- a/src/api.js +++ b/src/api.js @@ -333,6 +333,19 @@ const historyAll = () => { }); } +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, @@ -364,5 +377,6 @@ export { finishedDraw, getAmIWinner, postWineChosen, - historyAll + historyAll, + getWinnerByName };