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) => {