Files
Void-Homelab/lib/db/repos/projects.js
root 80363d3e68 feat(ui): Settings view + per-space project cards (status/research/edit/delete) + theming pass
- Settings (#/settings): API tokens (mint/list/revoke), Agents list, Orthos Mode placeholder
- Per-space Projects: Void-1-style expandable cards — inline status, ↻ Research (Eithan stub),
  Edit/New modal, Delete-with-confirm; migration 019 adds research_status/notes/timestamps;
  POST /api/projects/:id/research stub; GET /api/agent-tokens list
- Global +1 font bump; themed scrollbars; larger/bolder themed topbar

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 00:06:08 +10:00

63 lines
2.3 KiB
JavaScript

import { pool } from '../pool.js';
import { recordAudit } from './audit_stub.js';
export async function create({ space_id, slug, name, description, status = 'active', started_at }, actor) {
const { rows: [r] } = await pool.query(
`INSERT INTO projects(space_id, slug, name, description, status, started_at)
VALUES($1,$2,$3,$4,$5,$6) RETURNING *`,
[space_id, slug, name, description || null, status, started_at || null]
);
await recordAudit(actor, 'create', 'project', r.id, null, r);
return r;
}
export async function getById(id) {
const { rows: [r] } = await pool.query(`SELECT * FROM projects WHERE id=$1`, [id]);
return r;
}
export async function listBySpace(space_id, { status } = {}) {
const sql = status
? `SELECT * FROM projects WHERE space_id=$1 AND status=$2 ORDER BY name`
: `SELECT * FROM projects WHERE space_id=$1 ORDER BY name`;
const args = status ? [space_id, status] : [space_id];
const { rows } = await pool.query(sql, args);
return rows;
}
export async function update(id, patch, actor) {
const before = await getById(id);
const fields = ['slug','name','description','status','started_at','completed_at'];
const sets = [], vals = [];
let i = 1;
for (const f of fields) {
if (patch[f] !== undefined) { sets.push(`${f}=$${i++}`); vals.push(patch[f]); }
}
sets.push(`updated_at=now()`);
vals.push(id);
const { rows: [r] } = await pool.query(
`UPDATE projects SET ${sets.join(', ')} WHERE id=$${i} RETURNING *`,
vals
);
await recordAudit(actor, 'update', 'project', id, before, r);
return r;
}
// Stub for the future Eithan research agent: flag the project as research-requested.
// Eithan will later transition requested → researching → done and fill research_notes.
export async function requestResearch(id, actor) {
const before = await getById(id);
if (!before) return null;
const { rows: [r] } = await pool.query(
`UPDATE projects SET research_status='requested', research_requested_at=now(), updated_at=now()
WHERE id=$1 RETURNING *`, [id]);
await recordAudit(actor, 'update', 'project', id, before, r);
return r;
}
export async function del(id, actor) {
const before = await getById(id);
await pool.query(`DELETE FROM projects WHERE id=$1`, [id]);
await recordAudit(actor, 'delete', 'project', id, before, null);
}