add prisma/seed.ts
This commit is contained in:
parent
efa8e4a8af
commit
55b96aadb2
92
prisma/seed.ts
Normal file
92
prisma/seed.ts
Normal file
@ -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();
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user