about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPatryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>2019-11-28 10:36:12 +0100
committerPatryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>2019-11-28 10:36:12 +0100
commit8da7dad19ed454831b63d51058dd22550b9ac10c (patch)
tree22e5f94070867453a16ec7c53329d3e0a941e7e3
parentfbdce0b0a1cefb88c6bac247db04af25a43c284f (diff)
downloadpuszcza-8da7dad19ed454831b63d51058dd22550b9ac10c.tar.gz
puszcza-8da7dad19ed454831b63d51058dd22550b9ac10c.zip
Add database connection
-rw-r--r--assets/punktacja.gql13
-rw-r--r--pages/punktacja.vue25
2 files changed, 32 insertions, 6 deletions
diff --git a/assets/punktacja.gql b/assets/punktacja.gql
new file mode 100644
index 0000000..3a6a9fa
--- /dev/null
+++ b/assets/punktacja.gql
@@ -0,0 +1,13 @@
+type Troop {
+  name: String
+}
+
+type Points {
+  troop: Troop
+  points: Int
+}
+
+type Query {
+  getPoints: [Points!]
+  getTroopByName(name: String!): [Troop!]
+}
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
+      }))
     }
   }
 }