@@ -35,6 +35,14 @@ export const storeCandidateOpportunityMatch: TypedWorker<'gondul.v1.candidate-op
3535 } ) ;
3636
3737 await con . transaction ( async ( manager ) => {
38+ // Check if match already exists to determine if this is a new insert
39+ const existingMatch = await manager
40+ . getRepository ( OpportunityMatch )
41+ . findOne ( {
42+ where : { userId, opportunityId } ,
43+ select : [ 'userId' , 'opportunityId' ] ,
44+ } ) ;
45+
3846 await manager . getRepository ( OpportunityMatch ) . upsert (
3947 {
4048 userId,
@@ -46,13 +54,19 @@ export const storeCandidateOpportunityMatch: TypedWorker<'gondul.v1.candidate-op
4654 skipUpdateIfNoValuesChanged : true ,
4755 } ,
4856 ) ;
49- await manager . getRepository ( Alerts ) . update (
50- { userId, opportunityId : IsNull ( ) } ,
51- {
52- opportunityId,
53- flags : updateFlagsStatement < Alerts > ( { hasSeenOpportunity : false } ) ,
54- } ,
55- ) ;
57+
58+ // Only update alert if this is a new match (insert)
59+ if ( ! existingMatch ) {
60+ await manager . getRepository ( Alerts ) . update (
61+ { userId, opportunityId : IsNull ( ) } ,
62+ {
63+ opportunityId,
64+ flags : updateFlagsStatement < Alerts > ( {
65+ hasSeenOpportunity : false ,
66+ } ) ,
67+ } ,
68+ ) ;
69+ }
5670 } ) ;
5771 } ,
5872 parseMessage : ( message ) => {
0 commit comments