project summaries addition

This commit is contained in:
Storme-bit
2026-04-26 18:57:25 -07:00
parent 2429fedb2c
commit 4c6bd1df2d
5 changed files with 178 additions and 7 deletions
+24 -1
View File
@@ -50,4 +50,27 @@ function deleteSummary(id) {
getDB().prepare(`DELETE FROM summaries WHERE id = ?`).run(id);
}
module.exports = { createSummary, getSummary, getSummariesBySession, getSummariesByProject, updateSummary, deleteSummary };
// Fetches session summaries that belong to sessions in a given project
// Joins through sessions table since session summaries don't store project_id directly
function getSessionSummariesForProject(projectId) {
const db = getDB();
return db.prepare(`
SELECT s.* FROM summaries s
JOIN sessions sess ON sess.id = s.session_id
WHERE sess.project_id = ? AND s.session_id IS NOT NULL
ORDER BY s.created_at ASC
`).all(projectId).map(parseRow);
}
// Fetches the most recent project-level overview summary (session_id IS NULL distinguishes it)
function getProjectOverviewSummary(projectId) {
const db = getDB();
const row = db.prepare(`
SELECT * FROM summaries
WHERE project_id = ? AND session_id IS NULL
ORDER BY created_at DESC LIMIT 1
`).get(projectId);
return row ? parseRow(row) : null;
}
module.exports = { createSummary, getSummary, getSummariesBySession, getSummariesByProject, updateSummary, deleteSummary, getSessionSummariesForProject, getProjectOverviewSummary };