about summary refs log tree commit diff
path: root/pages
diff options
context:
space:
mode:
Diffstat (limited to 'pages')
-rw-r--r--pages/punktacja.vue25
1 files changed, 19 insertions, 6 deletions
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
+      }))
     }
   }
 }