Add document storage (local filesystem) + fix dashboard outstanding KPI

- Local file storage via STORAGE_PATH env var (replaces DO Spaces)
- POST/GET/DELETE /api/cases/:caseId/documents + GET /api/documents/:docId/download
- useDocuments hook + upload/list/download/delete UI in CaseDetailPage
- GET /api/invoices/summary — live SUM of sent+overdue invoices
- Dashboard outstanding KPI wired to real DB value
- api.upload() for FormData, formatBytes() utility

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Leon Serfaty
2026-04-26 03:07:37 -04:00
co-authored by Claude Sonnet 4.6
parent 0700d54225
commit ce2278f4be
13 changed files with 334 additions and 14 deletions
+10
View File
@@ -115,6 +115,16 @@ export async function invoicesRoutes(app: FastifyInstance) {
return { items: rows, total: count?.total ?? 0 };
});
// Summary — outstanding total across sent + overdue invoices
app.get('/api/invoices/summary', async (req) => {
const firmId = req.user!.firmId!;
const [row] = await getDb()
.select({ outstanding: sql<string>`COALESCE(SUM(${invoices.total}), 0)` })
.from(invoices)
.where(and(eq(invoices.firmId, firmId), inArray(invoices.status, ['sent', 'overdue'])));
return { outstanding: row?.outstanding ?? '0' };
});
// Get with items
app.get('/api/invoices/:id', async (req, reply) => {
const firmId = req.user!.firmId!;