From 4cb5d3e627da6b792c754d28320bfc3d23768cff Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Mon, 2 Mar 2026 01:49:18 -0800 Subject: [PATCH] fix(backend): replace $contains with post-filter for webhook events array query $contains generates CONTAINS() SQL in Cosmos (string match), not ARRAY_CONTAINS() needed for string[] fields. Use findMany + in-memory post-filter for correct behavior across both providers. --- backend/src/modules/webhooks/repository.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/backend/src/modules/webhooks/repository.ts b/backend/src/modules/webhooks/repository.ts index fc56cc6..fab0bc3 100644 --- a/backend/src/modules/webhooks/repository.ts +++ b/backend/src/modules/webhooks/repository.ts @@ -96,10 +96,12 @@ export async function findSubscriptionsForEvent( productId: string, eventType: WebhookEventType ): Promise { - // events is a string[] — $contains works for primitive arrays in memory provider - return subsCollection().findMany({ - filter: { userId, productId, active: true, events: { $contains: eventType } }, + // $contains generates CONTAINS() SQL (string match) in Cosmos, not ARRAY_CONTAINS(). + // Use findMany + post-filter for correct behavior across both providers. + const subs = await subsCollection().findMany({ + filter: { userId, productId, active: true }, }); + return subs.filter(s => s.events.includes(eventType)); } // ── Increment Failure Count ───────────────────────────────────