From 8da7dad19ed454831b63d51058dd22550b9ac10c Mon Sep 17 00:00:00 2001 From: Patryk Niedźwiedziński Date: Thu, 28 Nov 2019 10:36:12 +0100 Subject: Add database connection --- pages/punktacja.vue | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'pages/punktacja.vue') diff --git a/pages/punktacja.vue b/pages/punktacja.vue index 5f810ed..c263e5e 100644 --- a/pages/punktacja.vue +++ b/pages/punktacja.vue @@ -11,7 +11,18 @@ import RankingList from '~/components/Ranking/RankingList' const FAUNA_KEY = 'fnADeP_U0uACC4Hruw9JvjexNsvB-V-QjI3wr8yH' const b64encodedSecret = Buffer.from(FAUNA_KEY + ':').toString('base64') -const FAUNA_REF = '250230903625744898' +const query = ` +{ + getPoints{data {points troop{name}}} +}` +const URL = 'https://graphql.fauna.com/graphql' +const FETCH_OPTIONS = { + method: 'POST', + headers: { + Authorization: `Basic ${b64encodedSecret}` + }, + body: JSON.stringify({ query }) +} export default { components: { @@ -26,11 +37,13 @@ export default { this.getScores() }, methods: { - getScores() { - this.scores = [ - { troop: 'Toop 1', points: 1 }, - { troop: 'Troop 2', points: 2 } - ] + async getScores() { + const r = await fetch(URL, FETCH_OPTIONS) + const { data } = await r.json() + this.scores = data.getPoints.data.map(({ points, troop }) => ({ + troop: troop.name, + points + })) } } } -- cgit 1.4.1