feat: auth, first-run setup, login
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d722c0034c
commit
23f3192cd0
28 files changed
+648
-160
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import { prisma } from "@/server/db";
|
||||
import { seed } from "../../prisma/seed";
|
||||
|
||||
const TABLES = [
|
||||
"OperationSplit", "Operation", "RecurringSplit", "Recurring", "LoanSplit", "Loan",
|
||||
"Settlement", "Budget", "Category", "Setting", "User",
|
||||
];
|
||||
|
||||
/** Vide la base de test et remet les catégories de départ. */
|
||||
export async function resetDb() {
|
||||
if (!process.env.DATABASE_URL?.includes("_test")) throw new Error("resetDb refuse de tourner hors base de test");
|
||||
await prisma.$executeRawUnsafe("SET FOREIGN_KEY_CHECKS = 0");
|
||||
for (const t of TABLES) await prisma.$executeRawUnsafe(`TRUNCATE TABLE \`${t}\``);
|
||||
await prisma.$executeRawUnsafe("SET FOREIGN_KEY_CHECKS = 1");
|
||||
await seed(prisma);
|
||||
}
|
||||
|
||||
export async function makeUsers() {
|
||||
const h = await prisma.user.create({ data: { firstName: "H", login: "h", passwordHash: "x", color: "#4f46e5" } });
|
||||
const c = await prisma.user.create({ data: { firstName: "C", login: "c", passwordHash: "x", color: "#db2777" } });
|
||||
await prisma.setting.update({ where: { id: 1 }, data: { defaultSplit: { [h.id]: 5000, [c.id]: 5000 } } });
|
||||
return { h, c };
|
||||
}
|
||||
|
||||
export async function categoryId(name: string) {
|
||||
return (await prisma.category.findFirstOrThrow({ where: { name } })).id;
|
||||
}
|
||||
Reference in new issue
Block a user