Voegt boodschappenlijsten, productbeheer, realtime synchronisatie en browsercache-updates toe. Herstelt login- en sessiegedrag en maakt database-seeding herhaalbaar.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
44 lines
985 B
JavaScript
44 lines
985 B
JavaScript
require("dotenv").config();
|
|
|
|
const db = require("../config/database");
|
|
|
|
const categories = [
|
|
["Groente", "🥬"],
|
|
["Fruit", "🍎"],
|
|
["Zuivel", "🥛"],
|
|
["Brood", "🍞"],
|
|
["Dranken", "🥤"],
|
|
["Huishouden", "🧻"]
|
|
];
|
|
|
|
const products = [
|
|
["Melk", "Zuivel"],
|
|
["Bananen", "Fruit"],
|
|
["Brood", "Brood"],
|
|
["Koffie", "Dranken"],
|
|
["WC papier", "Huishouden"]
|
|
];
|
|
|
|
const insertCategory = db.prepare(`
|
|
INSERT OR IGNORE INTO categories (name, icon) VALUES (?, ?)
|
|
`);
|
|
|
|
const insertProduct = db.prepare(`
|
|
INSERT OR IGNORE INTO products (name, category_id) VALUES (?, ?)
|
|
`);
|
|
|
|
db.transaction(() => {
|
|
for (const category of categories) {
|
|
insertCategory.run(category);
|
|
}
|
|
|
|
for (const [name, categoryName] of products) {
|
|
const category = db.prepare(
|
|
"SELECT id FROM categories WHERE name = ?"
|
|
).get(categoryName);
|
|
insertProduct.run(name, category.id);
|
|
}
|
|
})();
|
|
|
|
console.log("Seed voltooid.");
|