Organizes contact fact objects into applied and proposed maps keyed by field for quick lookup.
// Source: https://github.com/mperkins0155/crm | License: MIT | Copyright 2026 Comp AI
// Provided via justclaw.it.com; keep this notice with the code.
import type { RouterOutputs } from "@/lib/trpc/types";
type Contact = RouterOutputs["contacts"]["byId"];
export type ContactFact = Contact["facts"][number];
export function factsByField(facts: ContactFact[]) {
const applied = new Map<string, ContactFact>();
const proposed = new Map<string, ContactFact>();
for (const fact of facts) {
const bucket = fact.status === "APPLIED" ? applied : proposed;
if (!bucket.has(fact.field)) bucket.set(fact.field, fact);
}
return { applied, proposed };
}
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key