feat(documents): owner-aggregated projection (files + workflows)

listFilesAggregatedByEntity walks the relationship graph (symmetric
reach: clients <-> companies via memberships, <-> yachts via current
ownership) and groups results by source: DIRECTLY ATTACHED + FROM
COMPANY/YACHT/CLIENT. File-FK snapshot is the source of truth so
historical files survive yacht-ownership transfer. Each group caps at
20 rows + a total for "Show all (N)" drill-through. Defense-in-depth
port_id filter at every join.

listInflightWorkflowsAggregatedByEntity reuses the same graph walk
for in-flight signing workflows (draft/sent/partially_signed only).
Completed workflows are hidden — they surface via their signed-PDF
file row instead.

applyEntityFkFromFolder auto-sets the matching entity FK on the file
row when the upload target is a system-managed entity subfolder (E8).
Wired into uploadFile; validator extended with folderId field.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-11 11:54:23 +02:00
parent 8e2e2ea113
commit 3037d832c6
4 changed files with 767 additions and 19 deletions

View File

@@ -7,6 +7,7 @@ export const uploadFileSchema = z.object({
clientId: z.string().optional(),
yachtId: z.string().optional(),
companyId: z.string().optional(),
folderId: z.string().uuid().optional(),
category: z.string().optional(),
entityType: z.string().optional(),
entityId: z.string().optional(),