Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions src/workers/opportunity/storeCandidateOpportunityMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<Alerts>({ 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<Alerts>({
hasSeenOpportunity: false,
}),
},
);
}
});
},
parseMessage: (message) => {
Expand Down
Loading