Skip to content

Instantly share code, notes, and snippets.

@Mistic92
Created October 21, 2018 18:16
Show Gist options
  • Save Mistic92/23bd38c5fc2f0f1b76c33c51a0c9fb95 to your computer and use it in GitHub Desktop.
Save Mistic92/23bd38c5fc2f0f1b76c33c51a0c9fb95 to your computer and use it in GitHub Desktop.
Example of building carousel on AoG v2 with Firestore
const admin = require('firebase-admin');
admin.initializeApp({
projectId: "XXXXXX"
}
);
const db = admin.firestore();
async function buildItemsCarousel() {
let carouselItems = {};
await getItems().then(function (querySnapshot) {
querySnapshot.forEach((doc, index) => {
let item = doc.data();
console.log("item: " + item.toString() + " index: " + index);
let itemDetails = {
synonyms: synonymMap[index],
title: item.name,
// description: item.description,
image: new Image({
url: item.photo_url,
alt: item.photo_alt,
}),
};
carouselItems[doc.id] = itemDetails;
});
});
return new Carousel({
items: carouselItems
});
}
async function getItems() {
const itemsRef = db.collection("items");
return itemsRef.where("enabled", "==", true).get();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment