sanamare/prisma/seed.ts
Claude 6c784e8a30
Sanamare Shop: Grundgerüst, Storefront, Kasse, Zahlungen, Admin-Anfang
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SvuGvHpbAQ4syfuLuRvutL
2026-10-19 13:11:20 +00:00

112 lines
7.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Grunddaten: Rollen, Inhaber-Zugang, Zahlungs- und Versandarten, Rechtsseiten, Beispielkatalog.
import { PrismaClient } from "@prisma/client";
import bcrypt from "bcryptjs";
import { ALL_PERMISSIONS } from "../src/lib/permissions";
import { PAYMENT_DEFINITIONS } from "../src/lib/payments/catalog";
const db = new PrismaClient();
async function main() {
const owner = await db.role.upsert({
where: { name: "Inhaber" },
create: { name: "Inhaber", description: "Voller Zugriff auf alles, kann nicht eingeschränkt werden.", permissions: ALL_PERMISSIONS, isSystem: true },
update: { permissions: ALL_PERMISSIONS, isSystem: true },
});
await db.role.upsert({
where: { name: "Shop-Manager" },
create: {
name: "Shop-Manager",
description: "Bestellungen, Katalog, Kunden und Inhalte – ohne Team, Rollen und Zahlungszugänge.",
permissions: ["dashboard.view", "orders.view", "orders.edit", "orders.refund", "products.view", "products.edit", "products.delete", "categories.edit", "stock.edit", "customers.view", "customers.edit", "coupons.edit", "newsletter.view", "content.edit", "appearance.edit", "shipping.edit"],
},
update: {},
});
await db.role.upsert({
where: { name: "Versand" },
create: { name: "Versand", description: "Sieht Bestellungen und trägt Versand und Sendungsnummern ein.", permissions: ["dashboard.view", "orders.view", "orders.edit", "products.view", "stock.edit"] },
update: {},
});
await db.role.upsert({
where: { name: "Redaktion" },
create: { name: "Redaktion", description: "Pflegt Produkttexte, Seiten und die Startseite.", permissions: ["dashboard.view", "products.view", "products.edit", "content.edit", "appearance.edit"] },
update: {},
});
const email = (process.env.ADMIN_EMAIL ?? "admin@sanamare.de").toLowerCase();
const password = process.env.ADMIN_PASSWORD ?? "sanamare-admin";
const existing = await db.user.findUnique({ where: { email } });
if (!existing) {
await db.user.create({ data: { email, firstName: "Max", lastName: "", passwordHash: await bcrypt.hash(password, 12), roleId: owner.id } });
console.log(`Inhaber-Zugang angelegt: ${email}`);
}
for (const [i, def] of PAYMENT_DEFINITIONS.entries()) {
await db.paymentMethod.upsert({
where: { code: def.code },
create: {
code: def.code,
name: def.defaultName,
description: def.defaultDescription,
sort: i,
enabled: def.provider === "manual" && def.code !== "cod",
loggedInOnly: def.code === "invoice",
fee: def.code === "cod" ? 700 : 0,
config: def.defaultConfig ?? {},
},
update: {},
});
}
if ((await db.shippingMethod.count()) === 0) {
await db.shippingMethod.createMany({
data: [
{ name: "Standardversand (DHL)", description: "Lieferung in 2–4 Werktagen, klimaneutral.", price: 495, freeFrom: 8000, countries: ["DE"], sort: 0 },
{ name: "Expressversand", description: "Lieferung am nächsten Werktag bei Bestellung bis 14 Uhr.", price: 1290, freeFrom: 0, countries: ["DE"], sort: 1 },
{ name: "Versand EU", description: "Lieferung in 4–7 Werktagen.", price: 1290, freeFrom: 15000, countries: ["AT", "CH", "NL", "BE", "LU", "FR", "IT", "ES", "DK", "PL"], sort: 2 },
],
});
}
const pages = [
{ slug: "versand", title: "Versand & Lieferung", showInFooter: "service", content: "## Lieferzeit\nWir liefern innerhalb Deutschlands in 2–4 Werktagen.\n\n## Versandkosten\nKostenloser Versand ab 80 €. Darunter berechnen wir 4,95 €." },
{ slug: "rueckgabe", title: "Rückgabe", showInFooter: "service", content: "Du kannst innerhalb von 30 Tagen zurückgeben. Schreib uns eine kurze Nachricht, wir schicken dir ein Rücksendeetikett." },
{ slug: "kontakt", title: "Kontakt", showInFooter: "service", content: "Du erreichst uns Mo–Fr von 9 bis 18 Uhr.\n\nE-Mail: [hallo@sanamare.de](mailto:hallo@sanamare.de)" },
{ slug: "ueber-uns", title: "Über uns", showInFooter: "company", content: "Sanamare ist ein Pilates-Studio mit eigenem Shop. Wir verkaufen nur, was wir selbst im Studio benutzen." },
{ slug: "studio", title: "Studio", showInFooter: "company", content: "Hier stellen wir bald unser Studio vor." },
{ slug: "journal", title: "Journal", showInFooter: "company", content: "Hier erscheinen bald Übungen, Tipps und Neuigkeiten aus dem Studio." },
{ slug: "impressum", title: "Impressum", showInFooter: "legal", content: "Bitte im Admin unter Inhalte → Seiten ausfüllen." },
{ slug: "datenschutz", title: "Datenschutz", showInFooter: "legal", content: "Bitte im Admin unter Inhalte → Seiten ausfüllen." },
{ slug: "agb", title: "AGB", showInFooter: "legal", content: "Bitte im Admin unter Inhalte → Seiten ausfüllen." },
{ slug: "widerruf", title: "Widerruf", showInFooter: "legal", content: "Bitte im Admin unter Inhalte → Seiten ausfüllen." },
];
for (const [i, p] of pages.entries()) await db.page.upsert({ where: { slug: p.slug }, create: { ...p, sort: i }, update: {} });
if ((await db.category.count()) === 0) {
const mats = await db.category.create({ data: { name: "Matten", slug: "matten", description: "Rutschfest, langlebig, angenehm unter den Händen.", sort: 0 } });
const gear = await db.category.create({ data: { name: "Kleingeräte", slug: "kleingeraete", description: "Ringe, Bälle und Bänder für dein Training.", sort: 1 } });
const wear = await db.category.create({ data: { name: "Bekleidung", slug: "bekleidung", description: "Bequem in jeder Position.", sort: 2 } });
const products = [
{ name: "Reformer Matte Pro", slug: "reformer-matte-pro", subtitle: "Anthrazit · 8 mm", price: 12900, compareAtPrice: 14900, stock: 24, featured: true, badge: "new", categoryId: mats.id, sku: "SM-2041", description: "Griffige Oberfläche, 8 mm stark, aus recyceltem Naturkautschuk. Rutschfest auf jedem Boden, auch bei langen Flows.", details: "Naturkautschuk, PVC-frei. Mit lauwarmem Wasser und einem weichen Tuch abwischen, liegend trocknen.", variants: [{ name: "173 cm", stock: 8 }, { name: "183 cm", stock: 12 }, { name: "200 cm", stock: 0, price: 13900 }] },
{ name: "Pilates Ring Studio", slug: "pilates-ring-studio", subtitle: "Schwarz / Gold", price: 4900, compareAtPrice: 5900, stock: 40, featured: true, categoryId: gear.id, sku: "SM-1102", description: "Leichter, stabiler Ring mit gepolsterten Griffen für Innen- und Außenseite." },
{ name: "Grip Socks, 2er-Pack", slug: "grip-socks", subtitle: "Sand", price: 2400, stock: 120, featured: true, badge: "best", categoryId: wear.id, sku: "SM-3010", description: "Rutschfeste Socken für Reformer und Matte.", variants: [{ name: "35–37", stock: 30 }, { name: "38–40", stock: 50 }, { name: "41–43", stock: 40 }] },
{ name: "Flow Leggings", slug: "flow-leggings", subtitle: "Nachtblau · hoher Bund", price: 8900, stock: 30, featured: true, categoryId: wear.id, sku: "SM-3201", description: "Blickdicht, weich und mit hohem Bund, der nicht rutscht.", variants: [{ name: "XS", stock: 5 }, { name: "S", stock: 10 }, { name: "M", stock: 10 }, { name: "L", stock: 5 }] },
{ name: "Soft Ball", slug: "soft-ball", subtitle: "Ø 25 cm", price: 1900, stock: 2, categoryId: gear.id, sku: "SM-1120", description: "Weicher Ball für Mobilisation und Stabilisation." },
{ name: "Resistance Band Set", slug: "resistance-band-set", subtitle: "3 Stärken", price: 3400, stock: 60, categoryId: gear.id, sku: "SM-1140", description: "Drei Bänder aus Stoff in leicht, mittel und stark." },
];
for (const [i, p] of products.entries()) {
const { variants, ...data } = p;
await db.product.create({
data: { ...data, images: [], sort: i, variants: variants ? { create: variants.map((v, j) => ({ ...v, sort: j })) } : undefined },
});
}
await db.coupon.create({ data: { code: "WILLKOMMEN10", type: "percent", value: 10 } });
}
}
main()
.then(() => db.$disconnect())
.catch(async (e) => {
console.error(e);
await db.$disconnect();
process.exit(1);
});