feat(docs): nested-entity 'This deal' / 'From client' split (B4 #8 phase 4)
Finishes B4 #8 by completing the UI half of the per-interest filing model. Backend foundations (files.interest_id column, ensureEntityFolder for 'interest', upload-zone scope radio, outcome rename hook, backfill) shipped earlier in this audit cycle. - listFiles validator + service: optional interestId filter - listFilesAggregatedByEntity: routes entityType='interest' to a new helper that returns "THIS DEAL" + "FROM CLIENT" + symmetric-reach company/yacht groups - InterestDocumentsTab: Attachments section now renders two cohorts via two paginated queries, with client-side de-duplication so files filed under this deal don't double-count under "From client" - FileRow type exposes the optional interestId so the de-dupe filter doesn't need a re-fetch
This commit is contained in:
@@ -814,6 +814,7 @@ _Functional defects. Tag each with `[critical|high|medium|low]` prefix._
|
|||||||
- One-off script `pnpm tsx scripts/backfill-nested-document-folders.ts --apply` — idempotent, per-port advisory-locked.
|
- One-off script `pnpm tsx scripts/backfill-nested-document-folders.ts --apply` — idempotent, per-port advisory-locked.
|
||||||
- **Effort:** ~6-8h end-to-end (migration + service rewrites + folder-name derivation + upload-zone affordance + tree rendering + lifecycle hooks + backfill + tests). Bundles bug #4 — both touch the same code paths. Captured 2026-05-21 from UAT.
|
- **Effort:** ~6-8h end-to-end (migration + service rewrites + folder-name derivation + upload-zone affordance + tree rendering + lifecycle hooks + backfill + tests). Bundles bug #4 — both touch the same code paths. Captured 2026-05-21 from UAT.
|
||||||
- **SHIPPED (foundation only — phase 1/3) in e91055f, phases 2/3 in 0ed03fc:** migration `0078_files_interest_id.sql` adds `files.interest_id` text REFERENCES interests(id) ON DELETE SET NULL + indexes `idx_files_interest` + `idx_files_port_interest`. Drizzle schema picks up the column + `interestId` field. `EntityType` widened to include `'interest'` — `ensureEntityFolder('interest', ...)` recursively ensures the parent client folder first so the tree reads `Clients/<Name>/Deal <mooringNumber>/` nested. `resolveEntityDisplayName` derives the deal label from the primary berth via dynamic-import of `getPrimaryBerth` (circular-dep dodge), falling back to `Deal <YYYY-MM-DD>`. **Phases 2/3 SHIPPED in 0ed03fc:** UploadZone scope radio (`<FileUploadZone>` accepts optional `interestId`; when set, fieldset renders "File at: ⦿ This deal | ◯ Client-level"; default deal-scope so deal-specific docs don't bleed across historical interests of the client; interest FK forwarded only when "This deal" selected). Outcome → folder rename hook: `renameInterestFolderForOutcome(interestId, portId, outcome)` strips prior outcome suffix then appends (Won)/(Lost)/(Cancelled); fired fire-and-forget from `interests.service.setInterestOutcome` via dynamic import (circular-dep dodge); no-op when folder hasn't been created yet. Backfill script: `scripts/backfill-nested-document-folders.ts` iterates every (port_id, interest_id) pair in `files` with non-null interest_id and calls `ensureEntityFolder`; idempotent via per-port advisory lock (FNV-1a of port_id); dry-run by default, `--apply` to commit. **Still deferred:** `listFilesAggregatedByEntity` rewrite for "This deal" vs "From client" subheadings (UI polish; per-row filing already correct); Documents Hub tree rendering for nested interest folders (rows exist with parent_id; tree component picks them up automatically).
|
- **SHIPPED (foundation only — phase 1/3) in e91055f, phases 2/3 in 0ed03fc:** migration `0078_files_interest_id.sql` adds `files.interest_id` text REFERENCES interests(id) ON DELETE SET NULL + indexes `idx_files_interest` + `idx_files_port_interest`. Drizzle schema picks up the column + `interestId` field. `EntityType` widened to include `'interest'` — `ensureEntityFolder('interest', ...)` recursively ensures the parent client folder first so the tree reads `Clients/<Name>/Deal <mooringNumber>/` nested. `resolveEntityDisplayName` derives the deal label from the primary berth via dynamic-import of `getPrimaryBerth` (circular-dep dodge), falling back to `Deal <YYYY-MM-DD>`. **Phases 2/3 SHIPPED in 0ed03fc:** UploadZone scope radio (`<FileUploadZone>` accepts optional `interestId`; when set, fieldset renders "File at: ⦿ This deal | ◯ Client-level"; default deal-scope so deal-specific docs don't bleed across historical interests of the client; interest FK forwarded only when "This deal" selected). Outcome → folder rename hook: `renameInterestFolderForOutcome(interestId, portId, outcome)` strips prior outcome suffix then appends (Won)/(Lost)/(Cancelled); fired fire-and-forget from `interests.service.setInterestOutcome` via dynamic import (circular-dep dodge); no-op when folder hasn't been created yet. Backfill script: `scripts/backfill-nested-document-folders.ts` iterates every (port_id, interest_id) pair in `files` with non-null interest_id and calls `ensureEntityFolder`; idempotent via per-port advisory lock (FNV-1a of port_id); dry-run by default, `--apply` to commit. **Still deferred:** `listFilesAggregatedByEntity` rewrite for "This deal" vs "From client" subheadings (UI polish; per-row filing already correct); Documents Hub tree rendering for nested interest folders (rows exist with parent_id; tree component picks them up automatically).
|
||||||
|
- **Final phase SHIPPED in this session:** `listFiles` now accepts an optional `interestId` filter (validator + service); `listFilesAggregatedByEntity` accepts `entityType='interest'` and routes to a new helper that returns "THIS DEAL" + "FROM CLIENT" + symmetric-reach company/yacht groups. `InterestDocumentsTab` Attachments section now fires two paginated queries (one scoped to `?interestId=<X>`, one scoped to `?clientId=<C>`), filters the client list to drop duplicates, and renders the two cohorts under "This deal" / "From client" subheadings. `FileRow` exposes the optional `interestId` so the de-dupe filter works without a re-fetch. Tree rendering in Documents Hub still relies on the tree component picking up child folders by `parent_id` (which already works); no additional UI surgery needed.
|
||||||
9. **SHIPPED in c14f80a (Q58):** `<SelectTrigger>` now accepts `size?: 'default' | 'sm'`; default = `h-11` so trigger matches Input's h-11 default. Existing compact call sites (FilterBar, dense table headers) opt back in via `size="sm"`. Nothing else breaks. **[medium] SelectTrigger height (`h-9`) doesn't match Input height (`h-11`) — platform-wide visual inconsistency** — _src/components/ui/select.tsx:22_ (SelectTrigger default `h-9` = 36px) + _src/components/ui/input.tsx:18_ (Input default `h-11` = 44px). Every form where an Input sits next to a Select has an 8px height mismatch. Surfaced specifically on _src/components/expenses/expense-form-dialog.tsx:222-247_ (the Amount + Currency two-column row) but affects ALL such combinations across the platform. Fixing locally with `className="h-11"` on each call site is a sweep over dozens of spots and creates drift the next time someone copies the pattern.
|
9. **SHIPPED in c14f80a (Q58):** `<SelectTrigger>` now accepts `size?: 'default' | 'sm'`; default = `h-11` so trigger matches Input's h-11 default. Existing compact call sites (FilterBar, dense table headers) opt back in via `size="sm"`. Nothing else breaks. **[medium] SelectTrigger height (`h-9`) doesn't match Input height (`h-11`) — platform-wide visual inconsistency** — _src/components/ui/select.tsx:22_ (SelectTrigger default `h-9` = 36px) + _src/components/ui/input.tsx:18_ (Input default `h-11` = 44px). Every form where an Input sits next to a Select has an 8px height mismatch. Surfaced specifically on _src/components/expenses/expense-form-dialog.tsx:222-247_ (the Amount + Currency two-column row) but affects ALL such combinations across the platform. Fixing locally with `className="h-11"` on each call site is a sweep over dozens of spots and creates drift the next time someone copies the pattern.
|
||||||
- **Fix (platform-wide):** introduce a `size` variant on SelectTrigger mirroring Button's idiom — `<SelectTrigger size="default" | "sm">`. Default to `"default"` = `h-11` so it pairs with the Input default out of the box. Migrate explicitly-compact uses (filter bars, dense table headers) to pass `size="sm"` = `h-9` to preserve their current density.
|
- **Fix (platform-wide):** introduce a `size` variant on SelectTrigger mirroring Button's idiom — `<SelectTrigger size="default" | "sm">`. Default to `"default"` = `h-11` so it pairs with the Input default out of the box. Migrate explicitly-compact uses (filter bars, dense table headers) to pass `size="sm"` = `h-9` to preserve their current density.
|
||||||
- **Audit step:** grep every `<SelectTrigger>` and `<Select>` call site; flag the ones in compact contexts (FilterBar, DataTable header dropdowns, dense admin lists) for the `size="sm"` override; everything else inherits the new h-11 default.
|
- **Audit step:** grep every `<SelectTrigger>` and `<Select>` call site; flag the ones in compact contexts (FilterBar, DataTable header dropdowns, dense admin lists) for the `size="sm"` override; everything else inherits the new h-11 default.
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ export interface FileRow {
|
|||||||
category: string | null;
|
category: string | null;
|
||||||
createdAt: string | Date;
|
createdAt: string | Date;
|
||||||
uploadedBy: string;
|
uploadedBy: string;
|
||||||
|
/** Optional — present when the file is scoped to a sales deal.
|
||||||
|
* Consumers like InterestDocumentsTab filter on this to split the
|
||||||
|
* "This deal" vs "From client" cohorts. */
|
||||||
|
interestId?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FileGridProps {
|
interface FileGridProps {
|
||||||
|
|||||||
@@ -45,24 +45,34 @@ export function InterestDocumentsTab({ interestId }: InterestDocumentsTabProps)
|
|||||||
apiFetch<{ data: InterestData }>(`/api/v1/interests/${interestId}`).then((r) => r.data),
|
apiFetch<{ data: InterestData }>(`/api/v1/interests/${interestId}`).then((r) => r.data),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Files attach at the client level (the schema has no interest_id
|
// Two cohorts: files tagged with this interestId ("This deal") +
|
||||||
// FK on `files`). For an interest, surface every file that belongs
|
// files belonging to the parent client without an interestId, or
|
||||||
// to its parent client - covers the realistic case where a rep
|
// tagged to another interest of the same client ("From client").
|
||||||
// uploaded a passport / scan / photo while working a deal.
|
// Until the interest record loads we pass a sentinel clientId so
|
||||||
// Until the interest record loads we pass a sentinel clientId so the
|
// the server returns empty rather than the unscoped port-wide list.
|
||||||
// server returns empty rather than the unscoped port-wide file list.
|
|
||||||
const clientId = interest?.clientId ?? '__pending__';
|
const clientId = interest?.clientId ?? '__pending__';
|
||||||
const filesQueryKey = ['files', { clientId }] as const;
|
const thisDealQueryKey = ['files', { interestId }] as const;
|
||||||
const { data: files, isLoading: filesLoading } = usePaginatedQuery<FileRow>({
|
const fromClientQueryKey = ['files', { clientId }] as const;
|
||||||
queryKey: filesQueryKey,
|
|
||||||
|
const { data: thisDealFiles, isLoading: thisDealLoading } = usePaginatedQuery<FileRow>({
|
||||||
|
queryKey: thisDealQueryKey,
|
||||||
|
endpoint: `/api/v1/files?interestId=${encodeURIComponent(interestId)}`,
|
||||||
|
filterDefinitions: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data: clientFiles, isLoading: clientFilesLoading } = usePaginatedQuery<FileRow>({
|
||||||
|
queryKey: fromClientQueryKey,
|
||||||
endpoint: `/api/v1/files?clientId=${encodeURIComponent(clientId)}`,
|
endpoint: `/api/v1/files?clientId=${encodeURIComponent(clientId)}`,
|
||||||
filterDefinitions: [],
|
filterDefinitions: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// "From client" excludes anything we already surface under "This deal".
|
||||||
|
const fromClientFiles = clientFiles.filter((f) => !f.interestId || f.interestId !== interestId);
|
||||||
|
|
||||||
useRealtimeInvalidation({
|
useRealtimeInvalidation({
|
||||||
'file:uploaded': [filesQueryKey],
|
'file:uploaded': [thisDealQueryKey, fromClientQueryKey],
|
||||||
'file:updated': [filesQueryKey],
|
'file:updated': [thisDealQueryKey, fromClientQueryKey],
|
||||||
'file:deleted': [filesQueryKey],
|
'file:deleted': [thisDealQueryKey, fromClientQueryKey],
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleDownload = async (file: FileRow) => {
|
const handleDownload = async (file: FileRow) => {
|
||||||
@@ -85,13 +95,16 @@ export function InterestDocumentsTab({ interestId }: InterestDocumentsTabProps)
|
|||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
try {
|
try {
|
||||||
await apiFetch(`/api/v1/files/${file.id}`, { method: 'DELETE' });
|
await apiFetch(`/api/v1/files/${file.id}`, { method: 'DELETE' });
|
||||||
queryClient.invalidateQueries({ queryKey: filesQueryKey });
|
queryClient.invalidateQueries({ queryKey: thisDealQueryKey });
|
||||||
|
queryClient.invalidateQueries({ queryKey: fromClientQueryKey });
|
||||||
} catch {
|
} catch {
|
||||||
// silent
|
// silent
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasAttachments = files.length > 0;
|
const hasThisDeal = thisDealFiles.length > 0;
|
||||||
|
const hasFromClient = fromClientFiles.length > 0;
|
||||||
|
const hasAttachments = hasThisDeal || hasFromClient;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-8">
|
<div className="space-y-8">
|
||||||
@@ -129,7 +142,8 @@ export function InterestDocumentsTab({ interestId }: InterestDocumentsTabProps)
|
|||||||
<h3 className="text-sm font-medium text-muted-foreground">Attachments</h3>
|
<h3 className="text-sm font-medium text-muted-foreground">Attachments</h3>
|
||||||
{hasAttachments ? (
|
{hasAttachments ? (
|
||||||
<span className="text-xs text-muted-foreground">
|
<span className="text-xs text-muted-foreground">
|
||||||
{files.length} file{files.length === 1 ? '' : 's'}
|
{thisDealFiles.length + fromClientFiles.length} file
|
||||||
|
{thisDealFiles.length + fromClientFiles.length === 1 ? '' : 's'}
|
||||||
</span>
|
</span>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
@@ -148,22 +162,44 @@ export function InterestDocumentsTab({ interestId }: InterestDocumentsTabProps)
|
|||||||
// client-level.
|
// client-level.
|
||||||
interestId={interestId}
|
interestId={interestId}
|
||||||
onUploadComplete={() => {
|
onUploadComplete={() => {
|
||||||
queryClient.invalidateQueries({ queryKey: filesQueryKey });
|
queryClient.invalidateQueries({ queryKey: thisDealQueryKey });
|
||||||
|
queryClient.invalidateQueries({ queryKey: fromClientQueryKey });
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
</PermissionGate>
|
</PermissionGate>
|
||||||
|
|
||||||
{hasAttachments ? (
|
{(hasThisDeal || thisDealLoading) && (
|
||||||
<FileGrid
|
<div className="space-y-2">
|
||||||
files={files}
|
<h4 className="text-xs font-semibold uppercase tracking-wide text-muted-foreground">
|
||||||
onDownload={handleDownload}
|
This deal
|
||||||
onPreview={setPreviewFile}
|
</h4>
|
||||||
onRename={() => {}}
|
<FileGrid
|
||||||
onDelete={handleDelete}
|
files={thisDealFiles}
|
||||||
isLoading={filesLoading}
|
onDownload={handleDownload}
|
||||||
/>
|
onPreview={setPreviewFile}
|
||||||
) : null}
|
onRename={() => {}}
|
||||||
|
onDelete={handleDelete}
|
||||||
|
isLoading={thisDealLoading}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{(hasFromClient || clientFilesLoading) && (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<h4 className="text-xs font-semibold uppercase tracking-wide text-muted-foreground">
|
||||||
|
From client
|
||||||
|
</h4>
|
||||||
|
<FileGrid
|
||||||
|
files={fromClientFiles}
|
||||||
|
onDownload={handleDownload}
|
||||||
|
onPreview={setPreviewFile}
|
||||||
|
onRename={() => {}}
|
||||||
|
onDelete={handleDelete}
|
||||||
|
isLoading={clientFilesLoading}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<EoiGenerateDialog
|
<EoiGenerateDialog
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import { documentFolders } from '@/lib/db/schema/documents';
|
|||||||
import { clients } from '@/lib/db/schema/clients';
|
import { clients } from '@/lib/db/schema/clients';
|
||||||
import { companies, companyMemberships } from '@/lib/db/schema/companies';
|
import { companies, companyMemberships } from '@/lib/db/schema/companies';
|
||||||
import { yachts } from '@/lib/db/schema/yachts';
|
import { yachts } from '@/lib/db/schema/yachts';
|
||||||
|
import { interests } from '@/lib/db/schema/interests';
|
||||||
import type { EntityType } from '@/lib/services/document-folders.service';
|
import type { EntityType } from '@/lib/services/document-folders.service';
|
||||||
|
|
||||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||||
@@ -267,7 +268,8 @@ export async function deleteFile(id: string, portId: string, meta: AuditMeta) {
|
|||||||
// ─── List ─────────────────────────────────────────────────────────────────────
|
// ─── List ─────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export async function listFiles(portId: string, query: ListFilesInput) {
|
export async function listFiles(portId: string, query: ListFilesInput) {
|
||||||
const { page, limit, sort, order, search, clientId, yachtId, companyId, category } = query;
|
const { page, limit, sort, order, search, clientId, yachtId, companyId, interestId, category } =
|
||||||
|
query;
|
||||||
|
|
||||||
const filters = [];
|
const filters = [];
|
||||||
|
|
||||||
@@ -280,6 +282,9 @@ export async function listFiles(portId: string, query: ListFilesInput) {
|
|||||||
if (companyId) {
|
if (companyId) {
|
||||||
filters.push(eq(files.companyId, companyId));
|
filters.push(eq(files.companyId, companyId));
|
||||||
}
|
}
|
||||||
|
if (interestId) {
|
||||||
|
filters.push(eq(files.interestId, interestId));
|
||||||
|
}
|
||||||
if (category) {
|
if (category) {
|
||||||
filters.push(eq(files.category, category));
|
filters.push(eq(files.category, category));
|
||||||
}
|
}
|
||||||
@@ -333,7 +338,7 @@ export type AggregatedFileRow = Omit<typeof files.$inferSelect, 'storagePath' |
|
|||||||
|
|
||||||
export interface AggregatedFileGroup {
|
export interface AggregatedFileGroup {
|
||||||
label: string;
|
label: string;
|
||||||
source: 'direct' | 'client' | 'company' | 'yacht';
|
source: 'direct' | 'client' | 'company' | 'yacht' | 'this_deal' | 'other_deals';
|
||||||
files: AggregatedFileRow[];
|
files: AggregatedFileRow[];
|
||||||
total: number;
|
total: number;
|
||||||
}
|
}
|
||||||
@@ -351,6 +356,74 @@ const GROUP_LIMIT = 20;
|
|||||||
* Source of truth: each file's snapshotted entity FKs.
|
* Source of truth: each file's snapshotted entity FKs.
|
||||||
* Defense-in-depth: port_id at every entity / membership / yacht / file join.
|
* Defense-in-depth: port_id at every entity / membership / yacht / file join.
|
||||||
*/
|
*/
|
||||||
|
async function listFilesAggregatedForInterest(
|
||||||
|
portId: string,
|
||||||
|
interestId: string,
|
||||||
|
clientId: string | null,
|
||||||
|
): Promise<AggregatedFilesResult> {
|
||||||
|
const groups: AggregatedFileGroup[] = [];
|
||||||
|
|
||||||
|
// "THIS DEAL" — files explicitly tagged with this interest_id.
|
||||||
|
const thisDeal = await fetchGroupRows(portId, eq(files.interestId, interestId), GROUP_LIMIT);
|
||||||
|
if (thisDeal.rows.length > 0) {
|
||||||
|
groups.push({
|
||||||
|
label: 'THIS DEAL',
|
||||||
|
source: 'this_deal',
|
||||||
|
files: thisDeal.rows,
|
||||||
|
total: thisDeal.total,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clientId) {
|
||||||
|
// "FROM CLIENT" — files on the same client that aren't tagged to
|
||||||
|
// this interest. NULL interest_id = client-level, non-deal-specific.
|
||||||
|
// A different interest id = another deal's docs, still useful to
|
||||||
|
// surface so the rep can pull from history without leaving the
|
||||||
|
// current detail page.
|
||||||
|
const fromClient = await fetchGroupRows(
|
||||||
|
portId,
|
||||||
|
and(
|
||||||
|
eq(files.clientId, clientId),
|
||||||
|
or(isNull(files.interestId), sql`${files.interestId} <> ${interestId}`),
|
||||||
|
)!,
|
||||||
|
GROUP_LIMIT,
|
||||||
|
);
|
||||||
|
if (fromClient.rows.length > 0) {
|
||||||
|
groups.push({
|
||||||
|
label: 'FROM CLIENT',
|
||||||
|
source: 'other_deals',
|
||||||
|
files: fromClient.rows,
|
||||||
|
total: fromClient.total,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Symmetric reach via the client's related companies + yachts.
|
||||||
|
const related = await collectRelatedEntities(portId, 'client', clientId);
|
||||||
|
for (const { id, name } of related.companies) {
|
||||||
|
const g = await fetchGroupRows(portId, eq(files.companyId, id), GROUP_LIMIT);
|
||||||
|
if (g.rows.length === 0) continue;
|
||||||
|
groups.push({
|
||||||
|
label: `FROM COMPANY: ${name.toUpperCase()}`,
|
||||||
|
source: 'company',
|
||||||
|
files: g.rows,
|
||||||
|
total: g.total,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (const { id, name } of related.yachts) {
|
||||||
|
const g = await fetchGroupRows(portId, eq(files.yachtId, id), GROUP_LIMIT);
|
||||||
|
if (g.rows.length === 0) continue;
|
||||||
|
groups.push({
|
||||||
|
label: `FROM YACHT: ${name.toUpperCase()}`,
|
||||||
|
source: 'yacht',
|
||||||
|
files: g.rows,
|
||||||
|
total: g.total,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { groups };
|
||||||
|
}
|
||||||
|
|
||||||
export async function listFilesAggregatedByEntity(
|
export async function listFilesAggregatedByEntity(
|
||||||
portId: string,
|
portId: string,
|
||||||
entityType: EntityType,
|
entityType: EntityType,
|
||||||
@@ -359,6 +432,20 @@ export async function listFilesAggregatedByEntity(
|
|||||||
const entityExists = await assertEntityInPort(portId, entityType, entityId);
|
const entityExists = await assertEntityInPort(portId, entityType, entityId);
|
||||||
if (!entityExists) return { groups: [] };
|
if (!entityExists) return { groups: [] };
|
||||||
|
|
||||||
|
// Interest view: split direct-attached files into "this deal" (files
|
||||||
|
// explicitly tagged with this interestId) + "from client" (files on
|
||||||
|
// the same client but no interestId OR a different interest). The
|
||||||
|
// client-level companies/yachts walk is reused via the underlying
|
||||||
|
// client.
|
||||||
|
if (entityType === 'interest') {
|
||||||
|
const interest = await db.query.interests.findFirst({
|
||||||
|
where: and(eq(interests.id, entityId), eq(interests.portId, portId)),
|
||||||
|
columns: { id: true, clientId: true },
|
||||||
|
});
|
||||||
|
if (!interest) return { groups: [] };
|
||||||
|
return listFilesAggregatedForInterest(portId, interest.id, interest.clientId ?? null);
|
||||||
|
}
|
||||||
|
|
||||||
const related = await collectRelatedEntities(portId, entityType, entityId);
|
const related = await collectRelatedEntities(portId, entityType, entityId);
|
||||||
const groups: AggregatedFileGroup[] = [];
|
const groups: AggregatedFileGroup[] = [];
|
||||||
|
|
||||||
@@ -434,6 +521,13 @@ export async function assertEntityInPort(
|
|||||||
});
|
});
|
||||||
return Boolean(c);
|
return Boolean(c);
|
||||||
}
|
}
|
||||||
|
if (entityType === 'interest') {
|
||||||
|
const i = await db.query.interests.findFirst({
|
||||||
|
where: and(eq(interests.id, entityId), eq(interests.portId, portId)),
|
||||||
|
columns: { id: true },
|
||||||
|
});
|
||||||
|
return Boolean(i);
|
||||||
|
}
|
||||||
const y = await db.query.yachts.findFirst({
|
const y = await db.query.yachts.findFirst({
|
||||||
where: and(eq(yachts.id, entityId), eq(yachts.portId, portId)),
|
where: and(eq(yachts.id, entityId), eq(yachts.portId, portId)),
|
||||||
columns: { id: true },
|
columns: { id: true },
|
||||||
|
|||||||
@@ -23,14 +23,18 @@ export const listFilesSchema = baseListQuerySchema
|
|||||||
clientId: z.string().optional(),
|
clientId: z.string().optional(),
|
||||||
yachtId: z.string().optional(),
|
yachtId: z.string().optional(),
|
||||||
companyId: z.string().optional(),
|
companyId: z.string().optional(),
|
||||||
|
interestId: z.string().optional(),
|
||||||
category: z.string().optional(),
|
category: z.string().optional(),
|
||||||
folderId: z
|
folderId: z
|
||||||
.string()
|
.string()
|
||||||
.uuid()
|
.uuid()
|
||||||
.optional()
|
.optional()
|
||||||
.transform((v) => (v === '' ? null : v)),
|
.transform((v) => (v === '' ? null : v)),
|
||||||
/** Entity-aggregated projection params - mutually exclusive with folderId. */
|
/** Entity-aggregated projection params - mutually exclusive with folderId.
|
||||||
entityType: z.enum(['client', 'company', 'yacht']).optional(),
|
* 'interest' splits direct-attached into "This deal" (files.interestId
|
||||||
|
* matches) and "From client" (client-level + other deals); the other
|
||||||
|
* values fall through to the legacy symmetric-reach aggregator. */
|
||||||
|
entityType: z.enum(['client', 'company', 'yacht', 'interest']).optional(),
|
||||||
entityId: z.string().uuid().optional(),
|
entityId: z.string().uuid().optional(),
|
||||||
})
|
})
|
||||||
.refine(
|
.refine(
|
||||||
|
|||||||
Reference in New Issue
Block a user