Created
October 21, 2018 18:16
-
-
Save Mistic92/23bd38c5fc2f0f1b76c33c51a0c9fb95 to your computer and use it in GitHub Desktop.
Example of building carousel on AoG v2 with Firestore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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