server: fix project_shares audit logging and add share transfer

- Fix PATCH /api/projects/:id/shares/:userId: query SELECT 1 instead of
  SELECT id (project_shares has a composite PK, no id column)
- Add audit logging to existing share grant/revoke routes
- Add POST /api/projects/:id/transfer for ownership handoff
- Remove inline admin user/audit routes from routes.ts (now in admin.ts)
- Remove unused requireAdmin import and userPatch schema from routes.ts
This commit is contained in:
Schwitzz
2026-10-29 10:44:58 -05:00
parent 1e16b0d5d2
commit fc8eaa86c3
7 changed files with 327 additions and 36 deletions
+27
View File
@@ -1,6 +1,7 @@
import type {
AISession,
AISessionRole,
AuditLogEntry,
Board,
Book,
Chapter,
@@ -29,6 +30,15 @@ export interface ShareRow {
user_id: string;
perm: "read" | "edit";
}
/** Raw `audit` table row (CHUNK #10). */
export interface AuditRow {
id: string;
at: string;
user_id: string | null;
action: string;
detail: string;
}
export interface ProjectRow {
id: string;
owner_id: string;
@@ -107,6 +117,23 @@ export function toUser(r: UserRow): User {
};
}
/** Map a raw `audit` row to the shared `AuditLogEntry` (CHUNK #10). */
export function toAudit(r: AuditRow): AuditLogEntry {
let detail: Record<string, unknown> = {};
try {
detail = JSON.parse(r.detail ?? "{}") as Record<string, unknown>;
} catch {
detail = {};
}
return {
id: r.id,
at: r.at,
userId: r.user_id,
action: r.action,
detail,
};
}
export function toProject(r: ProjectRow, shares: ShareRow[]): Project {
return {
id: r.id,