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
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { z } from 'zod';
|
|
|
|
import { baseListQuerySchema } from '@/lib/api/list-query';
|
|
|
|
export const uploadFileSchema = z.object({
|
|
filename: z.string().min(1).max(255),
|
|
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(),
|
|
});
|
|
|
|
export const updateFileSchema = z.object({
|
|
filename: z.string().min(1).max(255).optional(),
|
|
category: z.string().optional(),
|
|
});
|
|
|
|
export const listFilesSchema = baseListQuerySchema
|
|
.extend({
|
|
clientId: z.string().optional(),
|
|
yachtId: z.string().optional(),
|
|
companyId: z.string().optional(),
|
|
interestId: z.string().optional(),
|
|
category: z.string().optional(),
|
|
folderId: z
|
|
.string()
|
|
.uuid()
|
|
.optional()
|
|
.transform((v) => (v === '' ? null : v)),
|
|
/** Entity-aggregated projection params - mutually exclusive with folderId.
|
|
* '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(),
|
|
})
|
|
.refine(
|
|
(q) => !(q.folderId !== undefined && (q.entityType !== undefined || q.entityId !== undefined)),
|
|
{
|
|
message: 'folderId is mutually exclusive with entityType/entityId',
|
|
path: ['folderId'],
|
|
},
|
|
)
|
|
.refine((q) => Boolean(q.entityType) === Boolean(q.entityId), {
|
|
message: 'entityType and entityId must be provided together',
|
|
path: ['entityType'],
|
|
});
|
|
|
|
export type UploadFileInput = z.infer<typeof uploadFileSchema>;
|
|
export type UpdateFileInput = z.infer<typeof updateFileSchema>;
|
|
export type ListFilesInput = z.infer<typeof listFilesSchema>;
|