GraphQL collections (#1536)
This commit is contained in:
@@ -1108,7 +1108,7 @@ describe("FirebaseInstance", () => {
|
||||
|
||||
signInUser()
|
||||
|
||||
await expect(fb.writeCollections([])).resolves.toBeUndefined()
|
||||
await expect(fb.writeCollections([], "collections")).resolves.toBeUndefined()
|
||||
})
|
||||
|
||||
test("rejects for non-authenticated request", async () => {
|
||||
@@ -1116,7 +1116,7 @@ describe("FirebaseInstance", () => {
|
||||
|
||||
signOutUser()
|
||||
|
||||
await expect(fb.writeCollections([])).rejects.toBeDefined()
|
||||
await expect(fb.writeCollections([], "collections")).rejects.toBeDefined()
|
||||
})
|
||||
|
||||
test("stores data on firestore with proper structure", async () => {
|
||||
@@ -1124,7 +1124,7 @@ describe("FirebaseInstance", () => {
|
||||
|
||||
signInUser()
|
||||
|
||||
await fb.writeCollections([])
|
||||
await fb.writeCollections([], "collections")
|
||||
|
||||
const doc = (
|
||||
await mocksdk
|
||||
@@ -1152,7 +1152,7 @@ describe("FirebaseInstance", () => {
|
||||
|
||||
signInUser()
|
||||
|
||||
await fb.writeCollections([])
|
||||
await fb.writeCollections([], "collections")
|
||||
|
||||
const doc = (
|
||||
await mocksdk
|
||||
|
||||
@@ -35,6 +35,7 @@ export class FirebaseInstance {
|
||||
this.currentHistory = []
|
||||
this.currentGraphqlHistory = []
|
||||
this.currentCollections = []
|
||||
this.currentGraphqlCollections = []
|
||||
this.currentEnvironments = []
|
||||
|
||||
this.app.auth().onAuthStateChanged((user) => {
|
||||
@@ -133,6 +134,21 @@ export class FirebaseInstance {
|
||||
}
|
||||
})
|
||||
|
||||
this.usersCollection
|
||||
.doc(this.currentUser.uid)
|
||||
.collection("collectionsGraphql")
|
||||
.onSnapshot((collectionsRef) => {
|
||||
const collections = []
|
||||
collectionsRef.forEach((doc) => {
|
||||
const collection = doc.data()
|
||||
collection.id = doc.id
|
||||
collections.push(collection)
|
||||
})
|
||||
if (collections.length > 0) {
|
||||
this.currentGraphqlCollections = collections[0].collection
|
||||
}
|
||||
})
|
||||
|
||||
this.usersCollection
|
||||
.doc(this.currentUser.uid)
|
||||
.collection("environments")
|
||||
@@ -319,7 +335,7 @@ export class FirebaseInstance {
|
||||
}
|
||||
}
|
||||
|
||||
async writeCollections(collection) {
|
||||
async writeCollections(collection, flag) {
|
||||
const cl = {
|
||||
updatedOn: new Date(),
|
||||
author: this.currentUser.uid,
|
||||
@@ -329,11 +345,7 @@ export class FirebaseInstance {
|
||||
}
|
||||
|
||||
try {
|
||||
await this.usersCollection
|
||||
.doc(this.currentUser.uid)
|
||||
.collection("collections")
|
||||
.doc("sync")
|
||||
.set(cl)
|
||||
await this.usersCollection.doc(this.currentUser.uid).collection(flag).doc("sync").set(cl)
|
||||
} catch (e) {
|
||||
console.error("error updating", cl, e)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user