Skip to content

Commit a870ac9

Browse files
authored
chore: reset only new matches (#3337)
1 parent 772da34 commit a870ac9

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

src/workers/opportunity/storeCandidateOpportunityMatch.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)