Files
RFP_Finanzen/prisma/seed.ts
Jan 6acc2852d8
All checks were successful
CI / Build (push) Successful in 1m21s
CI / Deploy (push) Successful in 53s
In dashboard-shell.tsx ist der Rest-Hinweis unter Neue Ausgabe komplett raus. In budget-column.tsx habe ich den inneren Budget-Streifen auf Desktop technisch umgestellt: kein Stack mehr als Desktop-Scrollcontainer, sondern ein fester Flex-Track mit berechneter Breite plus etwas Reserve. Damit soll innerhalb einer AG nur mobil noch intern gescrollt werden, auf Desktop aber nicht mehr. Der äußere horizontale Scroll der Gesamtübersicht bleibt erhalten.
Das Demo-Zeug ist ebenfalls deutlich zurückgebaut: login-form.tsx hat keine Demo-Chips, keine vorbefüllten Zugangsdaten und keinen Demo-Hinweis mehr. In prisma/seed.ts sind die beiden Muster-Ausgaben raus, und das Seed-Passwort ist jetzt über SEED_INITIAL_PASSWORD steuerbar statt fest auf demo123!. Die sichtbare Doku in README.md ist entsprechend bereinigt.
2026-04-13 22:25:50 +02:00

187 lines
4.2 KiB
TypeScript

import { ApprovalStatus, ApprovalType, ExpenseRecurrence, PrismaClient, Role } from "@prisma/client";
import bcrypt from "bcryptjs";
const prisma = new PrismaClient();
const APPROVAL_THRESHOLD = 50;
async function upsertAppSettings() {
await prisma.appSettings.upsert({
where: { id: "global" },
update: {
approvalThreshold: APPROVAL_THRESHOLD
},
create: {
id: "global",
approvalThreshold: APPROVAL_THRESHOLD
}
});
}
async function upsertCurrentPeriod() {
const year = new Date().getFullYear();
const startsAt = new Date(Date.UTC(year, 0, 1));
const endsAt = new Date(Date.UTC(year, 11, 31, 23, 59, 59));
await prisma.accountingPeriod.updateMany({
data: {
isCurrent: false
}
});
return prisma.accountingPeriod.upsert({
where: {
name: `Haushalt ${year}`
},
update: {
startsAt,
endsAt,
isCurrent: true
},
create: {
name: `Haushalt ${year}`,
startsAt,
endsAt,
isCurrent: true
}
});
}
async function upsertWorkingGroup(name: string) {
return prisma.workingGroup.upsert({
where: { name },
update: {},
create: { name }
});
}
async function upsertBudget(
workingGroupId: string,
periodId: string,
name: string,
totalBudget: number,
colorCode: string,
releasedAmount = 0
) {
return prisma.budget.upsert({
where: {
workingGroupId_periodId_name: {
workingGroupId,
periodId,
name
}
},
update: {
totalBudget,
releasedAmount,
colorCode
},
create: {
name,
totalBudget,
releasedAmount,
colorCode,
workingGroupId,
periodId
}
});
}
async function upsertUser(input: {
username: string;
role: Role;
passwordHash: string;
workingGroupId?: string | null;
approvalPermissions: ApprovalType[];
}) {
const approvalPreference = input.approvalPermissions[0] ?? null;
await prisma.user.upsert({
where: { username: input.username },
update: {
name: input.username,
username: input.username,
email: null,
passwordHash: input.passwordHash,
role: input.role,
approvalPreference,
approvalPermissions: input.approvalPermissions,
workingGroupId: input.workingGroupId ?? null
},
create: {
name: input.username,
username: input.username,
email: null,
passwordHash: input.passwordHash,
role: input.role,
approvalPreference,
approvalPermissions: input.approvalPermissions,
workingGroupId: input.workingGroupId ?? null
}
});
}
async function main() {
const initialPassword = process.env.SEED_INITIAL_PASSWORD?.trim() || "Bitte-sofort-aendern-2026!";
const passwordHash = await bcrypt.hash(initialPassword, 12);
await upsertAppSettings();
const currentPeriod = await upsertCurrentPeriod();
const deko = await upsertWorkingGroup("AG Deko");
const awareness = await upsertWorkingGroup("AG Awareness");
const technik = await upsertWorkingGroup("AG Technik");
await upsertBudget(deko.id, currentPeriod.id, "Deko Hauptbudget", 0, "#FFB94A", 0);
await upsertBudget(awareness.id, currentPeriod.id, "Awareness Hauptbudget", 800, "#68A35D", 250);
await upsertBudget(technik.id, currentPeriod.id, "Technik Infrastruktur", 1500, "#5677F6", 500);
await upsertUser({
username: "vorstand-a",
role: Role.ADMIN,
passwordHash,
approvalPermissions: [ApprovalType.CHAIR_A]
});
await upsertUser({
username: "vorstand-b",
role: Role.ADMIN,
passwordHash,
approvalPermissions: [ApprovalType.CHAIR_B]
});
await upsertUser({
username: "finanzen",
role: Role.FINANCE,
passwordHash,
approvalPermissions: [ApprovalType.FINANCE]
});
await upsertUser({
username: "deko",
role: Role.MEMBER,
passwordHash,
workingGroupId: deko.id,
approvalPermissions: []
});
await upsertUser({
username: "technik",
role: Role.MEMBER,
passwordHash,
workingGroupId: technik.id,
approvalPermissions: []
});
}
main()
.then(async () => {
await prisma.$disconnect();
})
.catch(async (error) => {
console.error(error);
await prisma.$disconnect();
process.exit(1);
});