Function: findOpenLeadIdForFacility()
findOpenLeadIdForFacility(
svc,companyId,facilityId):Promise<string|null>
Defined in: src/db/queries/pipeline.ts:304
An existing OPEN lead already raised for this facility, found via the signal bridge
(job_signals.crm_lead_id). The existing CRM reserves crm_leads.converted_facility_id for the
win-conversion (a won lead → a new active facility), so a prospect lead is linked to its facility
through the signal, not that column. Returns the lead id so a new signal refreshes it, not dupes.
Parameters
svc
SupabaseClient
companyId
string
facilityId
string
Returns
Promise<string | null>