diff --git a/server.js b/server.js index 17212dd2..c598941c 100644 --- a/server.js +++ b/server.js @@ -634,13 +634,15 @@ app.delete('/claude/api/claude/sessions/:id', requireAuth, (req, res) => { }); // Move session to different project -app.post('/api/sessions/:id/move', requireAuth, (req, res) => { +app.post('/claude/api/claude/sessions/:id/move', requireAuth, (req, res) => { try { const { id } = req.params; const { projectId } = req.body; - // Check if session exists (in-memory or historical) + // Check if session exists (in-memory or historical) - fetch once let session = claudeService.sessions.get(id); + let isActiveSession = !!session; + if (!session) { // Check historical sessions const historicalSessions = claudeService.loadHistoricalSessions(); @@ -668,10 +670,13 @@ app.post('/api/sessions/:id/move', requireAuth, (req, res) => { } // Update session's metadata with projectId - if (claudeService.sessions.get(id)) { - // Active session - update metadata - const activeSession = claudeService.sessions.get(id); - activeSession.metadata.projectId = validatedId; + if (isActiveSession) { + // Active session - update metadata and persist to database + session.metadata.projectId = validatedId; + db.prepare(` + INSERT OR REPLACE INTO sessions (id, projectId, deletedAt) + VALUES (?, ?, NULL) + `).run(id, validatedId); } else { // Historical session - update in database db.prepare(` @@ -681,10 +686,13 @@ app.post('/api/sessions/:id/move', requireAuth, (req, res) => { } } else { // Move to unassigned (projectId = null) - if (claudeService.sessions.get(id)) { - // Active session - remove projectId from metadata - const activeSession = claudeService.sessions.get(id); - delete activeSession.metadata.projectId; + if (isActiveSession) { + // Active session - remove projectId from metadata and persist to database + delete session.metadata.projectId; + db.prepare(` + INSERT OR REPLACE INTO sessions (id, projectId, deletedAt) + VALUES (?, NULL, NULL) + `).run(id); } else { // Historical session - update in database db.prepare(`