in backend/index.ts [121:223]
function initFirestoreCollection() {
const oldProducts = [
"Apples",
"Bananas",
"Milk",
"Whole Wheat Bread",
"Eggs",
"Cheddar Cheese",
"Whole Chicken",
"Rice",
"Black Beans",
"Bottled Water",
"Apple Juice",
"Cola",
"Coffee Beans",
"Green Tea",
"Watermelon",
"Broccoli",
"Jasmine Rice",
"Yogurt",
"Beef",
"Shrimp",
"Walnuts",
"Sunflower Seeds",
"Fresh Basil",
"Cinnamon",
];
// iterate over product names
// add "old" products to firestore - all added between 1 month and 12 months ago
// (none of these should show up in the new products list.)
for (let i = 0; i < oldProducts.length; i++) {
const oldProduct = {
name: oldProducts[i],
price: Math.floor(Math.random() * 10) + 1,
quantity: Math.floor(Math.random() * 500) + 1,
imgfile:
"product-images/" +
oldProducts[i].replace(/\s/g, "").toLowerCase() +
".png",
// generate a random timestamp at least 3 months ago (but not more than 12 months ago)
timestamp: new Date(
Date.now() - Math.floor(Math.random() * 31536000000) - 7776000000
),
actualdateadded: new Date(Date.now()),
};
console.log(
"⬆️ Adding (or updating) product in firestore: " + oldProduct.name
);
addOrUpdateFirestore(oldProduct);
}
// Add recent products (force add last 7 days)
const recentProducts = [
"Parmesan Crisps",
"Pineapple Kombucha",
"Maple Almond Butter",
"Mint Chocolate Cookies",
"White Chocolate Caramel Corn",
"Acai Smoothie Packs",
"Smores Cereal",
"Peanut Butter and Jelly Cups",
];
for (let j = 0; j < recentProducts.length; j++) {
const recent = {
name: recentProducts[j],
price: Math.floor(Math.random() * 10) + 1,
quantity: Math.floor(Math.random() * 100) + 1,
imgfile:
"product-images/" +
recentProducts[j].replace(/\s/g, "").toLowerCase() +
".png",
timestamp: new Date(
Date.now() - Math.floor(Math.random() * 518400000) + 1
),
actualdateadded: new Date(Date.now()),
};
console.log("🆕 Adding (or updating) product in firestore: " + recent.name);
addOrUpdateFirestore(recent);
}
// add recent products that are out of stock (To test demo query- only want to show in stock items.)
const recentProductsOutOfStock = ["Wasabi Party Mix", "Jalapeno Seasoning"];
for (let k = 0; k < recentProductsOutOfStock.length; k++) {
const oosProduct = {
name: recentProductsOutOfStock[k],
price: Math.floor(Math.random() * 10) + 1,
quantity: 0,
imgfile:
"product-images/" +
recentProductsOutOfStock[k].replace(/\s/g, "").toLowerCase() +
".png",
timestamp: new Date(
Date.now() - Math.floor(Math.random() * 518400000) + 1
),
actualdateadded: new Date(Date.now()),
};
console.log(
"😱 Adding (or updating) out of stock product in firestore: " +
oosProduct.name
);
addOrUpdateFirestore(oosProduct);
}
}