Skip to main content

Function: markLeadWon()

markLeadWon(_prev, formData): Promise<LeadWonState>

Defined in: src/server/actions/crm.ts:257

Mark a lead won and convert it into an active client facility (copying the primary contact).

Claim-first: we atomically flip the lead open → won with a guarded UPDATE … RETURNING, so only one caller can win a given lead. A concurrent or double-submit loses the claim (0 rows) and bails before creating any facility — so no orphan can be created. If the facility insert then fails we revert the claim back to open. The facilities FK has no cascade, but the contact row is removed by facility_contacts' ON DELETE CASCADE if we ever need to delete the facility.

Parameters

_prev

LeadWonState

formData

FormData

Returns

Promise<LeadWonState>