Bundles the prior autonomous-session output that was sitting unstaged: - Em-dash sweep across src/ + tests/ (en-dash/em-dash to hyphen, ~2280 instances) - country-flag-icons rollout (CountryFlag component, replaces emoji glyphs that never rendered on Windows; lazy-loads the 3x2 SVG index as a single chunk after the per-subpath dynamic-import approach silently failed in webpack) - Admin IA Phase 1+2: 7-domain regroup, 41 to 38 pages, /admin/berths index, redirects (ocr to ai, reports to dashboard, invitations to users), docs/admin-ia-proposal.md - Per-template email tester (registry + endpoint + UI on Email admin page) - Cancel-document mode picker (delete-from-Documenso vs keep-for-audit) - Dashboard PDF report: 25 widgets, SVG charts, date-range picker, 11 resolvers - Customize-widgets per-region sortables at xl+ (charts/rails/feed); single flat sortable below xl when the layout stacks; per-viewport saved orders - Audit doc updates capturing each shipped item - Lint fixes: react-compiler immutability in DonutChart (reduce instead of let-reassign), set-state-in-effect disables in CountryFlag and UploadForSigning preview-bytes effect, unused 'confirm' destructures in interest contract + reservation tabs, unescaped apostrophe in test-template card copy
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import { and, eq, isNull, type SQL } from 'drizzle-orm';
|
|
|
|
import { interests } from '@/lib/db/schema/interests';
|
|
|
|
/**
|
|
* Canonical "active interest" predicate for SQL WHERE clauses.
|
|
*
|
|
* An interest is **active** when it is:
|
|
* - scoped to the given `portId`,
|
|
* - not soft-archived (`archived_at IS NULL`), and
|
|
* - not yet terminal (`outcome IS NULL` - i.e. not won, lost, or
|
|
* cancelled).
|
|
*
|
|
* "Won" deals are explicitly **not active** under this definition: a won
|
|
* deal is closed business, distinct from in-flight pipeline. The 7-stage
|
|
* pipeline carries deals through `contract` as the final motion stage;
|
|
* setting an `outcome` (won/lost/cancelled) terminates the deal and
|
|
* removes it from the active pool everywhere KPIs, kanban, hot deals,
|
|
* pipeline value, and revenue forecast are computed.
|
|
*
|
|
* Pre-2026-05-14 the dashboard used a broader `outcome IS NULL OR
|
|
* outcome = 'won'` predicate; the new pipeline overhaul collapsed
|
|
* intermediate completion states into explicit stages, making the
|
|
* stricter definition the correct one across every surface.
|
|
*
|
|
* Always combine with the table's own filters; this helper is a leaf
|
|
* predicate, not a complete WHERE.
|
|
*/
|
|
export function activeInterestsWhere(portId: string): SQL {
|
|
return and(
|
|
eq(interests.portId, portId),
|
|
isNull(interests.archivedAt),
|
|
isNull(interests.outcome),
|
|
) as SQL;
|
|
}
|