From 55b96aadb2a7ed970cdb29bb40212dc41badbf46 Mon Sep 17 00:00:00 2001 From: Giuseppe Lombardo Date: Wed, 12 Aug 2026 16:37:35 +0000 Subject: [PATCH] add prisma/seed.ts --- prisma/seed.ts | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 prisma/seed.ts diff --git a/prisma/seed.ts b/prisma/seed.ts new file mode 100644 index 0000000..d60eca4 --- /dev/null +++ b/prisma/seed.ts @@ -0,0 +1,92 @@ +import { PrismaClient, UserRole, RoomStatus } from '@prisma/client'; + +const prisma = new PrismaClient(); + +/** + * Erzeugt Testdaten für die lokale Entwicklung: + * - 1 Vermieter + * - 4 Zimmer (3x 20qm, 1x 16qm) passend zur Nackenheim-WG + * - 4 Mieter mit aktivem Vertrag je Zimmer + * - je 1 offene Mietzahlung für den aktuellen Monat (für den Banking-Test) + */ +async function main() { + console.log('Seed: lösche vorhandene Testdaten...'); + await prisma.payment.deleteMany(); + await prisma.contract.deleteMany(); + await prisma.room.deleteMany(); + await prisma.user.deleteMany(); + + const landlord = await prisma.user.create({ + data: { + email: 'vermieter@example.com', + passwordHash: 'not-a-real-hash', + fullName: 'Giuseppe Lombardo', + role: UserRole.LANDLORD, + }, + }); + + const roomDefs = [ + { roomNumber: 'Zimmer 1', sizeSqm: 20.0, baseRent: 420, utilityPauschal: 130 }, + { roomNumber: 'Zimmer 2', sizeSqm: 20.0, baseRent: 420, utilityPauschal: 130 }, + { roomNumber: 'Zimmer 3', sizeSqm: 20.0, baseRent: 420, utilityPauschal: 130 }, + { roomNumber: 'Zimmer 4', sizeSqm: 16.0, baseRent: 360, utilityPauschal: 120 }, + ]; + + const tenantNames = ['Anna Schmidt', 'Ben Keller', 'Clara Wagner', 'David Hoffmann']; + + for (let i = 0; i < roomDefs.length; i++) { + const def = roomDefs[i]; + const room = await prisma.room.create({ + data: { + roomNumber: def.roomNumber, + sizeSqm: def.sizeSqm, + baseRent: def.baseRent, + utilityPauschal: def.utilityPauschal, + status: RoomStatus.OCCUPIED, + }, + }); + + const tenant = await prisma.user.create({ + data: { + email: `mieter${i + 1}@example.com`, + passwordHash: 'not-a-real-hash', + fullName: tenantNames[i], + role: UserRole.TENANT, + roomId: room.id, + }, + }); + + const totalWarmRent = def.baseRent + def.utilityPauschal; + + const contract = await prisma.contract.create({ + data: { + userId: tenant.id, + roomId: room.id, + startDate: new Date('2025-10-01'), + totalWarmRent, + depositAmount: totalWarmRent * 3, + isActive: true, + }, + }); + + const now = new Date(); + await prisma.payment.create({ + data: { + contractId: contract.id, + amount: totalWarmRent, + dueDate: new Date(now.getFullYear(), now.getMonth(), 3), + }, + }); + } + + console.log('Seed abgeschlossen. Vermieter-Login (Demo):', landlord.email); +} + +main() + .catch((e) => { + console.error(e); + process.exit(1); + }) + .finally(async () => { + await prisma.$disconnect(); + });