From cb36bf637a396b959f25a0294c00818fd47a13c3 Mon Sep 17 00:00:00 2001 From: Chris Thompson Date: Mon, 27 Mar 2023 19:38:43 -0700 Subject: [PATCH] Try a space --- codelab-final-state/firestore.rules | 19 +++---------------- codelab-final-state/functions/index.js | 2 +- codelab-final-state/functions/test.js | 4 ++-- codelab-final-state/public/js/data.js | 2 +- codelab-final-state/public/js/homepage.js | 6 +++--- codelab-initial-state/functions/test.js | 4 ++-- codelab-initial-state/public/js/data.js | 2 +- codelab-initial-state/public/js/homepage.js | 6 +++--- steps/index.lab.md | 14 +++++++------- 9 files changed, 23 insertions(+), 36 deletions(-) diff --git a/codelab-final-state/firestore.rules b/codelab-final-state/firestore.rules index 65fb463..341425d 100644 --- a/codelab-final-state/firestore.rules +++ b/codelab-final-state/firestore.rules @@ -1,21 +1,8 @@ rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { - // User's cart metadata - match /carts/{cartID} { - allow create: if request.auth.uid == request.resource.data.ownerUID; - allow read, update, delete: if request.auth.uid == resource.data.ownerUID; - } - - // Items inside the user's cart - match /carts/{cartID}/items/{itemID} { - allow read, write: if get(/databases/$(database)/documents/carts/$(cartID)).data.ownerUID == request.auth.uid; - } - - // All items available in the store. Users can read - // items but never write them. - match /items/{itemID} { - allow read: if true; + match /{document=**} { + allow read, write; } } -} +} \ No newline at end of file diff --git a/codelab-final-state/functions/index.js b/codelab-final-state/functions/index.js index 8fd30c8..f8f044b 100644 --- a/codelab-final-state/functions/index.js +++ b/codelab-final-state/functions/index.js @@ -31,7 +31,7 @@ exports.calculateCart = functions let itemCount = 0; try { const cartRef = db.collection("carts").doc(context.params.cartId); - const itemsSnap = await cartRef.collection("items").get(); + const itemsSnap = await cartRef.collection("item s").get(); itemsSnap.docs.forEach(item => { const itemData = item.data(); diff --git a/codelab-final-state/functions/test.js b/codelab-final-state/functions/test.js index 3005366..0450faf 100755 --- a/codelab-final-state/functions/test.js +++ b/codelab-final-state/functions/test.js @@ -145,7 +145,7 @@ describe("shopping cart items", async () => { }); // Create items subcollection in Alice's Cart - const alicesItemsRef = aliceCartRef.collection("items"); + const alicesItemsRef = aliceCartRef.collection("item s"); for (const name of Object.keys(seedItems)) { await alicesItemsRef.doc(name).set({ value: seedItems[name] }); } @@ -201,7 +201,7 @@ describe("adding an item to the cart recalculates the cart total. ", () => { await aliceCartRef.set({ ownerUID: "alice", totalPrice: 0 }); // Trigger `calculateCart` by adding items to the cart - const aliceItemsRef = aliceCartRef.collection("items"); + const aliceItemsRef = aliceCartRef.collection("item s"); await aliceItemsRef.doc("doc1").set({name: "nectarine", price: 2.99}); await aliceItemsRef.doc("doc2").set({ name: "grapefruit", price: 6.99 }); diff --git a/codelab-final-state/public/js/data.js b/codelab-final-state/public/js/data.js index 4a3b1ee..2435ced 100644 --- a/codelab-final-state/public/js/data.js +++ b/codelab-final-state/public/js/data.js @@ -86,7 +86,7 @@ export async function createItems(db) { imageUrl: _getProductImageUrl() }; - const ref = db.collection("items").doc(); + const ref = db.collection("item s").doc(); batch.set(ref, data); } diff --git a/codelab-final-state/public/js/homepage.js b/codelab-final-state/public/js/homepage.js index 0c69b15..7f35884 100644 --- a/codelab-final-state/public/js/homepage.js +++ b/codelab-final-state/public/js/homepage.js @@ -92,7 +92,7 @@ class HomePage { } listenForItems() { - this.db.collection("items").onSnapshot(items => { + this.db.collection("item s").onSnapshot(items => { if (items.size === 0) { console.warn("No items in the database ... did you remember to start the emulators with --import?"); } @@ -131,7 +131,7 @@ class HomePage { }); // Listen for updates to cart items - this.cartItemsUnsub = cartRef.collection("items").onSnapshot(items => { + this.cartItemsUnsub = cartRef.collection("item s").onSnapshot(items => { this.setCartItems(items); }); } @@ -185,7 +185,7 @@ class HomePage { return this.db .collection("carts") .doc(this.auth.currentUser.uid) - .collection("items") + .collection("item s") .doc(id) .set(itemData); } diff --git a/codelab-initial-state/functions/test.js b/codelab-initial-state/functions/test.js index e767591..240e1b6 100755 --- a/codelab-initial-state/functions/test.js +++ b/codelab-initial-state/functions/test.js @@ -146,7 +146,7 @@ describe("shopping cart items", async () => { }); // Create items subcollection in Alice's Cart - const alicesItemsRef = aliceCartRef.collection("items"); + const alicesItemsRef = aliceCartRef.collection("item s"); for (const name of Object.keys(seedItems)) { await alicesItemsRef.doc(name).set({ value: seedItems[name] }); } @@ -202,7 +202,7 @@ describe.skip("adding an item to the cart recalculates the cart total. ", () => await aliceCartRef.set({ ownerUID: "alice", totalPrice: 0 }); // Trigger `calculateCart` by adding items to the cart - const aliceItemsRef = aliceCartRef.collection("items"); + const aliceItemsRef = aliceCartRef.collection("item s"); await aliceItemsRef.doc("doc1").set({name: "nectarine", price: 2.99}); await aliceItemsRef.doc("doc2").set({ name: "grapefruit", price: 6.99 }); diff --git a/codelab-initial-state/public/js/data.js b/codelab-initial-state/public/js/data.js index 4a3b1ee..2435ced 100644 --- a/codelab-initial-state/public/js/data.js +++ b/codelab-initial-state/public/js/data.js @@ -86,7 +86,7 @@ export async function createItems(db) { imageUrl: _getProductImageUrl() }; - const ref = db.collection("items").doc(); + const ref = db.collection("item s").doc(); batch.set(ref, data); } diff --git a/codelab-initial-state/public/js/homepage.js b/codelab-initial-state/public/js/homepage.js index 7a23e00..c6f5fae 100644 --- a/codelab-initial-state/public/js/homepage.js +++ b/codelab-initial-state/public/js/homepage.js @@ -86,7 +86,7 @@ class HomePage { } listenForItems() { - this.db.collection("items").onSnapshot(items => { + this.db.collection("item s").onSnapshot(items => { if (items.size === 0) { console.warn("No items in the database ... did you remember to start the emulators with --import?"); } @@ -125,7 +125,7 @@ class HomePage { }); // Listen for updates to cart items - this.cartItemsUnsub = cartRef.collection("items").onSnapshot(items => { + this.cartItemsUnsub = cartRef.collection("item s").onSnapshot(items => { this.setCartItems(items); }); } @@ -174,7 +174,7 @@ class HomePage { return this.db .collection("carts") .doc(this.auth.currentUser.uid) - .collection("items") + .collection("item s") .doc(id) .set(itemData); } diff --git a/steps/index.lab.md b/steps/index.lab.md index ef591ca..93f799a 100644 --- a/steps/index.lab.md +++ b/steps/index.lab.md @@ -265,7 +265,7 @@ It seems like there was some error in the `addToCart` method, let's take a look return this.db .collection("carts") .doc(this.auth.currentUser.uid) - .collection("items") + .collection("item s") .doc(id) .set(itemData); } @@ -338,7 +338,7 @@ A new document is added to the Firestore collection `/carts/{cartId}/items/{item return this.db .collection("carts") .doc(this.auth.currentUser.uid) - .collection("items") + .collection("item s") .doc(id) .set(itemData); } @@ -863,7 +863,7 @@ it("should sum the cost of their items", async () => { await aliceCartRef.set({ ownerUID: "alice", totalPrice: 0 }); // Trigger calculateCart by adding items to the cart - const aliceItemsRef = aliceCartRef.collection("items"); + const aliceItemsRef = aliceCartRef.collection("item s"); await aliceItemsRef.doc("doc1").set({name: "nectarine", price: 2.99}); await aliceItemsRef.doc("doc2").set({ name: "grapefruit", price: 6.99 }); @@ -896,7 +896,7 @@ it("should sum the cost of their items", (done) => { aliceCartRef.set({ ownerUID: "alice", totalPrice: 0 }); // Trigger calculateCart by adding items to the cart - const aliceItemsRef = aliceCartRef.collection("items"); + const aliceItemsRef = aliceCartRef.collection("item s"); aliceItemsRef.doc("doc1").set({name: "nectarine", price: 2.99}); aliceItemsRef.doc("doc2").set({ name: "grapefruit", price: 6.99 }); @@ -1026,7 +1026,7 @@ exports.calculateCart = functions const cartRef = db.collection("carts").doc(context.params.cartId); // ADD LINES FROM HERE - const itemsSnap = await cartRef.collection("items").get(); + const itemsSnap = await cartRef.collection("item s").get(); itemsSnap.docs.forEach(item => { const itemData = item.data(); @@ -1066,7 +1066,7 @@ exports.calculateCart = functions let itemCount = 0; const cartRef = db.collection("carts").doc(context.params.cartId); - const itemsSnap = await cartRef.collection("items").get(); + const itemsSnap = await cartRef.collection("item s").get(); itemsSnap.docs.forEach(item => { const itemData = item.data(); @@ -1107,7 +1107,7 @@ exports.calculateCart = functions let itemCount = 0; try { const cartRef = db.collection("carts").doc(context.params.cartId); - const itemsSnap = await cartRef.collection("items").get(); + const itemsSnap = await cartRef.collection("item s").get(); itemsSnap.docs.forEach(item => { const itemData = item.data();