(params: {
path: string
workflowId: string
tx?: DbOrTx
})
| 23 | * a same-workflow row can never mask a foreign collision. |
| 24 | */ |
| 25 | export async function findConflictingWebhookPathOwner(params: { |
| 26 | path: string |
| 27 | workflowId: string |
| 28 | tx?: DbOrTx |
| 29 | }): Promise<string | null> { |
| 30 | const { path, workflowId, tx } = params |
| 31 | const dbCtx = tx ?? db |
| 32 | |
| 33 | const existing = await dbCtx |
| 34 | .select({ workflowId: webhook.workflowId }) |
| 35 | .from(webhook) |
| 36 | .innerJoin(workflow, eq(webhook.workflowId, workflow.id)) |
| 37 | .where( |
| 38 | and( |
| 39 | eq(webhook.path, path), |
| 40 | eq(webhook.isActive, true), |
| 41 | isNull(webhook.archivedAt), |
| 42 | isNull(workflow.archivedAt) |
| 43 | ) |
| 44 | ) |
| 45 | |
| 46 | const conflict = existing.find((row) => row.workflowId !== workflowId) |
| 47 | return conflict ? conflict.workflowId : null |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Result of syncing webhooks for a credential set |
no test coverage detected