fix: address code review feedback - add error handling and fix import style

Co-authored-by: ZimengXiong <83783148+ZimengXiong@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-06 22:42:50 +00:00
parent 2e40deb82c
commit e97fbbdf27
2 changed files with 27 additions and 22 deletions
@@ -8,6 +8,7 @@
*/ */
import { describe, it, expect, beforeAll, afterAll, beforeEach } from "vitest"; import { describe, it, expect, beforeAll, afterAll, beforeEach } from "vitest";
import bcrypt from "bcrypt";
import { import {
getTestPrisma, getTestPrisma,
cleanupTestDb, cleanupTestDb,
@@ -28,7 +29,6 @@ describe("User Data Sandboxing", () => {
prisma = getTestPrisma(); prisma = getTestPrisma();
// Create two test users // Create two test users
const bcrypt = require("bcrypt");
const hashA = await bcrypt.hash("passwordA", 10); const hashA = await bcrypt.hash("passwordA", 10);
const hashB = await bcrypt.hash("passwordB", 10); const hashB = await bcrypt.hash("passwordB", 10);
+26 -21
View File
@@ -797,30 +797,35 @@ io.on("connection", (socket) => {
drawingId: string; drawingId: string;
user: Omit<User, "socketId" | "isActive">; user: Omit<User, "socketId" | "isActive">;
}) => { }) => {
// Verify the authenticated user owns this drawing try {
if (authenticatedUserId) { // Verify the authenticated user owns this drawing
const drawing = await prisma.drawing.findFirst({ if (authenticatedUserId) {
where: { id: drawingId, userId: authenticatedUserId }, const drawing = await prisma.drawing.findFirst({
select: { id: true }, where: { id: drawingId, userId: authenticatedUserId },
}); select: { id: true },
});
if (!drawing) { if (!drawing) {
socket.emit("error", { message: "Drawing not found or access denied" }); socket.emit("error", { message: "Drawing not found or access denied" });
return; return;
}
} }
const roomId = `drawing_${drawingId}`;
socket.join(roomId);
const newUser: User = { ...user, socketId: socket.id, isActive: true };
const currentUsers = roomUsers.get(roomId) || [];
const filteredUsers = currentUsers.filter((u) => u.id !== user.id);
filteredUsers.push(newUser);
roomUsers.set(roomId, filteredUsers);
io.to(roomId).emit("presence-update", filteredUsers);
} catch (err) {
console.error("Error in join-room handler:", err);
socket.emit("error", { message: "Failed to join room" });
} }
const roomId = `drawing_${drawingId}`;
socket.join(roomId);
const newUser: User = { ...user, socketId: socket.id, isActive: true };
const currentUsers = roomUsers.get(roomId) || [];
const filteredUsers = currentUsers.filter((u) => u.id !== user.id);
filteredUsers.push(newUser);
roomUsers.set(roomId, filteredUsers);
io.to(roomId).emit("presence-update", filteredUsers);
} }
); );