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:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user