fix: activation via connexion WS principale, cascade delete student→nodes, lien fiche étudiant

- agent/websocket.go: expose sendMessage() + notifyUI() pour broadcaster
  les résultats d'activation à tous les clients UI connectés
- agent/ui.go: supprime forwardActivation(), utilise sendMessage() sur
  la connexion WS principale au lieu d'une connexion temporaire
- agent/activation.go: ajoute os.MkdirAll avant l'écriture d'activation.json
- server/prisma/schema.prisma: onDelete Cascade sur Node→Student
- server/app/dashboard/students/page.tsx: nom cliquable vers fiche détail
- server/app/dashboard/students/[id]/actions.ts: deleteMany → delete
This commit is contained in:
root
2026-06-06 22:41:15 +00:00
parent 349c8d0e2a
commit 479a8de858
10 changed files with 130 additions and 41 deletions
@@ -23,12 +23,15 @@ export async function deleteStudent(formData: FormData) {
if (!id) return;
const establishmentId = session.user.establishmentId;
await prisma.student.deleteMany({
const student = await prisma.student.findFirst({
where: {
id,
class: establishmentId ? { establishmentId } : undefined,
},
});
if (!student) return;
await prisma.student.delete({ where: { id } });
redirect("/dashboard/students");
}
+5 -1
View File
@@ -47,7 +47,11 @@ export default async function StudentsPage() {
const node = s.nodes[0];
return (
<TableRow key={s.id}>
<TableCell className="font-medium">{s.firstName} {s.lastName}</TableCell>
<TableCell className="font-medium">
<Link href={`/dashboard/students/${s.id}`} className="hover:underline">
{s.firstName} {s.lastName}
</Link>
</TableCell>
<TableCell>{s.class.name}</TableCell>
<TableCell>{s.email}</TableCell>
<TableCell>{s.activationCode || "-"}</TableCell>
+5
View File
@@ -18,10 +18,12 @@ const nodes = new Map<string, WebSocket>();
export function initWebSocketServer(wss: WebSocketServer) {
wss.on("connection", (ws: WebSocket) => {
let nodeId: string | null = null;
console.log("[WS] New connection");
ws.on("message", async (raw) => {
try {
const msg: NodeMessage = JSON.parse(raw.toString());
console.log("[WS] Received:", msg.action, "from", msg.nodeId || nodeId);
if (msg.action === "register" && msg.nodeId) {
nodeId = msg.nodeId;
@@ -41,6 +43,7 @@ export function initWebSocketServer(wss: WebSocketServer) {
where: { activationCode: msg.code },
});
if (!student) {
console.log("[WS] Invalid code:", msg.code);
ws.send(JSON.stringify({ action: "activation_failed", error: "Invalid code" }));
return;
}
@@ -49,6 +52,7 @@ export function initWebSocketServer(wss: WebSocketServer) {
update: { studentId: student.id, status: "online", lastSeen: new Date() },
create: { id: nodeId, studentId: student.id, status: "online", lastSeen: new Date() },
});
console.log("[WS] Activated:", student.firstName, student.lastName, "on", nodeId);
ws.send(JSON.stringify({ action: "activated", studentId: student.id, studentName: `${student.firstName} ${student.lastName}` }));
return;
}
@@ -83,6 +87,7 @@ export function initWebSocketServer(wss: WebSocketServer) {
});
ws.on("close", async () => {
console.log("[WS] Connection closed for", nodeId);
if (nodeId) {
nodes.delete(nodeId);
await prisma.node.upsert({
+1 -1
View File
@@ -63,7 +63,7 @@ model Student {
model Node {
id String @id
studentId String?
student Student? @relation(fields: [studentId], references: [id], onDelete: SetNull)
student Student? @relation(fields: [studentId], references: [id], onDelete: Cascade)
tailscaleIp String?
status String @default("offline")
lastSeen DateTime?
Binary file not shown.
Binary file not shown.
Binary file not shown.