feat: auto-detect podman/docker in agent, add studentId to activation response, fix download URLs

This commit is contained in:
root
2026-06-06 21:14:24 +00:00
parent a1883080d3
commit 349c8d0e2a
11 changed files with 132 additions and 20 deletions
@@ -4,6 +4,7 @@ import { prisma } from "@/lib/prisma";
import { redirect } from "next/navigation";
import { revalidatePath } from "next/cache";
import { z } from "zod";
import { hashPassword } from "@/lib/auth";
const updateSchema = z.object({
plan: z.enum(["trial", "starter", "standard", "premium"]),
@@ -36,3 +37,42 @@ export async function deleteEstablishment(establishmentId: string) {
});
redirect("/superadmin/establishments");
}
const createAdminSchema = z.object({
email: z.string().email("Email invalide"),
password: z.string().min(8, "Le mot de passe doit contenir au moins 8 caractères"),
});
export async function createAdmin(establishmentId: string, formData: FormData) {
const email = formData.get("email") as string;
const password = formData.get("password") as string;
const parsed = createAdminSchema.safeParse({ email, password });
if (!parsed.success) {
throw new Error(parsed.error.issues.map((e) => e.message).join(", "));
}
const existing = await prisma.user.findUnique({ where: { email: parsed.data.email } });
if (existing) throw new Error("Cet email est déjà utilisé");
const hashed = await hashPassword(parsed.data.password);
await prisma.user.create({
data: {
email: parsed.data.email,
password: hashed,
role: "admin",
establishmentId,
},
});
revalidatePath(`/superadmin/establishments/${establishmentId}`);
}
export async function deleteAdmin(establishmentId: string, userId: string) {
await prisma.user.deleteMany({
where: { id: userId, establishmentId, role: "admin" },
});
revalidatePath(`/superadmin/establishments/${establishmentId}`);
}