update prisma/seed.ts

This commit is contained in:
Giuseppe Lombardo 2026-08-12 17:45:54 +00:00
parent b7df0455a5
commit 0797d85d78

View File

@ -1,7 +1,12 @@
import { PrismaClient, UserRole, RoomStatus } from '@prisma/client'; import { PrismaClient, UserRole, RoomStatus } from '@prisma/client';
import bcrypt from 'bcryptjs';
const prisma = new PrismaClient(); const prisma = new PrismaClient();
// Demo-Passwörter — nur für die Testdaten, sollten in Produktion geändert werden.
const LANDLORD_DEMO_PASSWORD = 'Vermieter2026!';
const TENANT_DEMO_PASSWORD = 'Mieter2026!';
/** /**
* Erzeugt Testdaten für die lokale Entwicklung: * Erzeugt Testdaten für die lokale Entwicklung:
* - 1 Vermieter * - 1 Vermieter
@ -11,6 +16,7 @@ const prisma = new PrismaClient();
*/ */
async function main() { async function main() {
console.log('Seed: lösche vorhandene Testdaten...'); console.log('Seed: lösche vorhandene Testdaten...');
await prisma.invitation.deleteMany();
await prisma.payment.deleteMany(); await prisma.payment.deleteMany();
await prisma.contract.deleteMany(); await prisma.contract.deleteMany();
await prisma.room.deleteMany(); await prisma.room.deleteMany();
@ -19,7 +25,7 @@ async function main() {
const landlord = await prisma.user.create({ const landlord = await prisma.user.create({
data: { data: {
email: 'vermieter@example.com', email: 'vermieter@example.com',
passwordHash: 'not-a-real-hash', passwordHash: await bcrypt.hash(LANDLORD_DEMO_PASSWORD, 12),
fullName: 'Giuseppe Lombardo', fullName: 'Giuseppe Lombardo',
role: UserRole.LANDLORD, role: UserRole.LANDLORD,
}, },
@ -49,7 +55,7 @@ async function main() {
const tenant = await prisma.user.create({ const tenant = await prisma.user.create({
data: { data: {
email: `mieter${i + 1}@example.com`, email: `mieter${i + 1}@example.com`,
passwordHash: 'not-a-real-hash', passwordHash: await bcrypt.hash(TENANT_DEMO_PASSWORD, 12),
fullName: tenantNames[i], fullName: tenantNames[i],
role: UserRole.TENANT, role: UserRole.TENANT,
roomId: room.id, roomId: room.id,
@ -79,7 +85,9 @@ async function main() {
}); });
} }
console.log('Seed abgeschlossen. Vermieter-Login (Demo):', landlord.email); console.log('Seed abgeschlossen.');
console.log(`Vermieter-Login (Demo): ${landlord.email} / ${LANDLORD_DEMO_PASSWORD}`);
console.log(`Mieter-Login (Demo, z.B. mieter1@example.com): ${TENANT_DEMO_PASSWORD}`);
} }
main() main()