Files

71 lines
2.1 KiB
TypeScript
Raw Permalink 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.
import { PrismaClient } from "@prisma/client";
import bcrypt from "bcryptjs";
const prisma = new PrismaClient();
async function main() {
const adminEmail = process.env.ADMIN_EMAIL || "pierre@secourit.fr";
const adminPassword = process.env.ADMIN_PASSWORD || "JuanitoAdmin2026!";
const existing = await prisma.user.findUnique({
where: { email: adminEmail },
});
if (!existing) {
const hashed = await bcrypt.hash(adminPassword, 10);
await prisma.user.create({
data: {
email: adminEmail,
name: "Juanito",
password: hashed,
role: "ADMIN",
muayThai: { create: {} },
},
});
console.log(`✅ Admin créé: ${adminEmail}`);
} else {
console.log(`Admin existe déjà: ${adminEmail}`);
}
// Créer les tiers Yoga par défaut
const tiers = [
{ name: "Séance unique", numberOfSessions: 1, priceTotal: 9 },
{ name: "Pack 5 séances", numberOfSessions: 5, priceTotal: 40 },
{ name: "Pack 10 séances", numberOfSessions: 10, priceTotal: 70 },
];
for (const t of tiers) {
const exists = await prisma.yogaTier.findFirst({
where: { name: t.name },
});
if (!exists) {
await prisma.yogaTier.create({ data: t });
console.log(`✅ Tier yoga créé: ${t.name}`);
}
}
// Créer les créneaux de cours par défaut
const slots = [
{ slug: "muay-mardi", label: "Mardi", sport: "muay-thai", time: "19h00 – 21h00", capacity: 20, booked: 16 },
{ slug: "muay-vendredi", label: "Vendredi", sport: "muay-thai", time: "20h00 – 22h00", capacity: 20, booked: 6 },
{ slug: "yoga-lundi", label: "Lundi", sport: "yoga", time: "19h30 – 20h30", capacity: 15, booked: 5 },
];
for (const s of slots) {
const exists = await prisma.classSlot.findUnique({ where: { slug: s.slug } });
if (!exists) {
await prisma.classSlot.create({ data: s });
console.log(`✅ Créneau créé: ${s.slug}`);
}
}
console.log("Seed terminé ✅");
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});