101 lines
3.0 KiB
TypeScript
101 lines
3.0 KiB
TypeScript
import { PrismaClient, UserRole, RoomStatus } from '@prisma/client';
|
|
import bcrypt from 'bcryptjs';
|
|
|
|
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:
|
|
* - 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.invitation.deleteMany();
|
|
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: await bcrypt.hash(LANDLORD_DEMO_PASSWORD, 12),
|
|
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: await bcrypt.hash(TENANT_DEMO_PASSWORD, 12),
|
|
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.');
|
|
console.log(`Vermieter-Login (Demo): ${landlord.email} / ${LANDLORD_DEMO_PASSWORD}`);
|
|
console.log(`Mieter-Login (Demo, z.B. mieter1@example.com): ${TENANT_DEMO_PASSWORD}`);
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|