feat(documents): Phase A schema + service skeletons
Adds Phase A data model deltas to documents/templates and the new document_watchers table. Introduces createFromWizard/createFromUpload stubs, getDocumentDetail aggregator, cancelDocument flow, signed-doc email composer, reservation agreement context, and notifyDocumentEvent fan-out. Validator update accepts new template formats with html-only bodyHtml requirement. EOI cadence backfilled to 1 day to preserve current effective behaviour. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
pgTable,
|
||||
primaryKey,
|
||||
text,
|
||||
boolean,
|
||||
integer,
|
||||
@@ -55,6 +56,7 @@ export const documents = pgTable(
|
||||
clientId: text('client_id').references(() => clients.id),
|
||||
yachtId: text('yacht_id'), // FK wired in relations.ts
|
||||
companyId: text('company_id'), // FK wired in relations.ts
|
||||
reservationId: text('reservation_id'), // FK wired in relations.ts
|
||||
documentType: text('document_type').notNull(), // eoi, contract, nda, reservation_agreement, other
|
||||
title: text('title').notNull(),
|
||||
status: text('status').notNull().default('draft'), // draft, sent, partially_signed, completed, expired, cancelled
|
||||
@@ -63,6 +65,8 @@ export const documents = pgTable(
|
||||
signedFileId: text('signed_file_id').references(() => files.id),
|
||||
isManualUpload: boolean('is_manual_upload').notNull().default(false),
|
||||
notes: text('notes'),
|
||||
remindersDisabled: boolean('reminders_disabled').notNull().default(false),
|
||||
reminderCadenceOverride: integer('reminder_cadence_override'),
|
||||
createdBy: text('created_by').notNull(),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
@@ -73,7 +77,9 @@ export const documents = pgTable(
|
||||
index('idx_docs_client').on(table.clientId),
|
||||
index('idx_documents_yacht').on(table.yachtId),
|
||||
index('idx_documents_company').on(table.companyId),
|
||||
index('idx_docs_reservation').on(table.reservationId),
|
||||
index('idx_docs_type').on(table.portId, table.documentType),
|
||||
index('idx_docs_status_port').on(table.portId, table.status),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -134,8 +140,19 @@ export const documentTemplates = pgTable(
|
||||
name: text('name').notNull(),
|
||||
description: text('description'),
|
||||
templateType: text('template_type').notNull(), // welcome_letter, handover_checklist, acknowledgment, correspondence, custom
|
||||
bodyHtml: text('body_html').notNull(),
|
||||
// Nullable: only required when template_format='html'.
|
||||
bodyHtml: text('body_html'),
|
||||
mergeFields: jsonb('merge_fields').notNull().default([]),
|
||||
// 'html' | 'pdf_form' | 'pdf_overlay' | 'documenso_render'
|
||||
templateFormat: text('template_format').notNull().default('html'),
|
||||
sourceFileId: text('source_file_id').references(() => files.id),
|
||||
documensoTemplateId: text('documenso_template_id'),
|
||||
// pdf_form: { acroFieldName: mergeToken }
|
||||
fieldMapping: jsonb('field_mapping').notNull().default({}),
|
||||
// pdf_overlay: [{ token, page, x, y, fontSize }]
|
||||
overlayPositions: jsonb('overlay_positions').notNull().default([]),
|
||||
// null = no auto-reminders
|
||||
reminderCadenceDays: integer('reminder_cadence_days'),
|
||||
isActive: boolean('is_active').notNull().default(true),
|
||||
createdBy: text('created_by').notNull(),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
@@ -147,6 +164,23 @@ export const documentTemplates = pgTable(
|
||||
],
|
||||
);
|
||||
|
||||
export const documentWatchers = pgTable(
|
||||
'document_watchers',
|
||||
{
|
||||
documentId: text('document_id')
|
||||
.notNull()
|
||||
.references(() => documents.id, { onDelete: 'cascade' }),
|
||||
userId: text('user_id').notNull(),
|
||||
addedBy: text('added_by').notNull(),
|
||||
addedAt: timestamp('added_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(table) => [
|
||||
primaryKey({ columns: [table.documentId, table.userId] }),
|
||||
index('idx_doc_watchers_doc').on(table.documentId),
|
||||
index('idx_doc_watchers_user').on(table.userId),
|
||||
],
|
||||
);
|
||||
|
||||
export const formTemplates = pgTable(
|
||||
'form_templates',
|
||||
{
|
||||
@@ -200,6 +234,8 @@ export type DocumentEvent = typeof documentEvents.$inferSelect;
|
||||
export type NewDocumentEvent = typeof documentEvents.$inferInsert;
|
||||
export type DocumentTemplate = typeof documentTemplates.$inferSelect;
|
||||
export type NewDocumentTemplate = typeof documentTemplates.$inferInsert;
|
||||
export type DocumentWatcher = typeof documentWatchers.$inferSelect;
|
||||
export type NewDocumentWatcher = typeof documentWatchers.$inferInsert;
|
||||
export type FormTemplate = typeof formTemplates.$inferSelect;
|
||||
export type NewFormTemplate = typeof formTemplates.$inferInsert;
|
||||
export type FormSubmission = typeof formSubmissions.$inferSelect;
|
||||
|
||||
Reference in New Issue
Block a user