From a0d4026d997a3dfb082902fdb00d1536c6d57897 Mon Sep 17 00:00:00 2001 From: Chris Bongers Date: Wed, 10 Dec 2025 10:50:26 +0200 Subject: [PATCH] chore: reset only new matches --- .../storeCandidateOpportunityMatch.ts | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/workers/opportunity/storeCandidateOpportunityMatch.ts b/src/workers/opportunity/storeCandidateOpportunityMatch.ts index 46a06bb88c..27beec4ac7 100644 --- a/src/workers/opportunity/storeCandidateOpportunityMatch.ts +++ b/src/workers/opportunity/storeCandidateOpportunityMatch.ts @@ -35,6 +35,14 @@ export const storeCandidateOpportunityMatch: TypedWorker<'gondul.v1.candidate-op }); await con.transaction(async (manager) => { + // Check if match already exists to determine if this is a new insert + const existingMatch = await manager + .getRepository(OpportunityMatch) + .findOne({ + where: { userId, opportunityId }, + select: ['userId', 'opportunityId'], + }); + await manager.getRepository(OpportunityMatch).upsert( { userId, @@ -46,13 +54,19 @@ export const storeCandidateOpportunityMatch: TypedWorker<'gondul.v1.candidate-op skipUpdateIfNoValuesChanged: true, }, ); - await manager.getRepository(Alerts).update( - { userId, opportunityId: IsNull() }, - { - opportunityId, - flags: updateFlagsStatement({ hasSeenOpportunity: false }), - }, - ); + + // Only update alert if this is a new match (insert) + if (!existingMatch) { + await manager.getRepository(Alerts).update( + { userId, opportunityId: IsNull() }, + { + opportunityId, + flags: updateFlagsStatement({ + hasSeenOpportunity: false, + }), + }, + ); + } }); }, parseMessage: (message) => {