fix(tenancies): unblock first-tenancy chicken-and-egg in webhook

Webhook auto-create on signed Reservation Agreement was gating itself on
isTenanciesModuleEnabled, but autoCreatePendingTenancies never enabled
the module — so the very first tenancy on a fresh port was unreachable
even though the row-exists fallback in isTenanciesModuleEnabled was
designed exactly for this lazy auto-surface case. Drop the gate; the
inserted row now flips the module on automatically via the fallback.

docs/tenancies-design.md §"When disabled" and the P3 PR-table row
updated to reflect the new contract.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-26 18:48:15 +02:00
parent c8869338e8
commit 353a31323e
3 changed files with 21 additions and 22 deletions

View File

@@ -1683,15 +1683,13 @@ export async function handleDocumentCompleted(eventData: { documentId: string; p
evaluateRule('contract_signed', doc.interestId!, doc.portId, systemMeta),
);
// Tenancies P3 — auto-create pending tenancies (one per in-bundle berth)
// when the module is enabled for this port. Gating is at the call site:
// disabled module = stage + docStatus updates still fire, only the
// tenancy mint is skipped (per docs/tenancies-design.md §"When disabled").
// Tenancies P3 — auto-create pending tenancies (one per in-bundle berth).
// No module gate here: the row-exists fallback in `isTenanciesModuleEnabled`
// lazily surfaces the module after the first signing, which is exactly what
// we want for the first-ever Reservation Agreement on a fresh port. Admins
// can still pre-enable the module to make widgets/sidebar appear earlier.
void (async () => {
try {
const { isTenanciesModuleEnabled } =
await import('@/lib/services/tenancies-module.service');
if (!(await isTenanciesModuleEnabled(doc.portId))) return;
const { autoCreatePendingTenancies } =
await import('@/lib/services/berth-tenancies.service');
// Re-read signedFileId from the post-commit row; the in-tx update