Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try a space #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions codelab-final-state/firestore.rules
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
2 changes: 1 addition & 1 deletion codelab-final-state/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions codelab-final-state/functions/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] });
}
Expand Down Expand Up @@ -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 });

Expand Down
2 changes: 1 addition & 1 deletion codelab-final-state/public/js/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions codelab-final-state/public/js/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?");
}
Expand Down Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions codelab-initial-state/functions/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] });
}
Expand Down Expand Up @@ -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 });

Expand Down
2 changes: 1 addition & 1 deletion codelab-initial-state/public/js/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions codelab-initial-state/public/js/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?");
}
Expand Down Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -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);
}
Expand Down
14 changes: 7 additions & 7 deletions steps/index.lab.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 });

Expand Down Expand Up @@ -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 });

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down