Skip to content

Commit 4f8112c

Browse files
authored
fix: add safeguards for opportunity (#3250)
1 parent c2e29f5 commit 4f8112c

4 files changed

Lines changed: 42 additions & 14 deletions

File tree

src/workers/notifications/candidateOpportunityMatchNotification.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { NotificationType } from '../../notifications/common';
22
import { TypedNotificationWorker } from '../worker';
33
import { TypeORMQueryFailedError } from '../../errors';
44
import { MatchedCandidate } from '@dailydotdev/schema';
5+
import { User } from '../../entity';
56

67
const candidateOpportunityMatchNotification: TypedNotificationWorker<'gondul.v1.candidate-opportunity-match'> =
78
{
@@ -17,6 +18,15 @@ const candidateOpportunityMatchNotification: TypedNotificationWorker<'gondul.v1.
1718
return;
1819
}
1920

21+
const user = await con.getRepository(User).findOneBy({ id: userId });
22+
if (!user) {
23+
logger.error(
24+
{ opportunityId, userId },
25+
'candidateOpportunityMatchNotification: User not found',
26+
);
27+
return;
28+
}
29+
2030
return [
2131
{
2232
type: NotificationType.NewOpportunityMatch,

src/workers/notifications/warmIntroNotification.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { logger } from '../../logger';
44
import { OpportunityJob } from '../../entity/opportunities/OpportunityJob';
55
import { OpportunityUserType } from '../../entity/opportunities/types';
66
import { WarmIntro } from '@dailydotdev/schema';
7-
import { Feature, FeatureType } from '../../entity';
7+
import { User } from '../../entity';
88
import { OpportunityMatch } from '../../entity/OpportunityMatch';
99
import { markdown } from '../../common/markdown';
1010

@@ -27,6 +27,15 @@ export const warmIntroNotification: TypedNotificationWorker<'gondul.v1.warm-intr
2727
return;
2828
}
2929

30+
const user = await con.getRepository(User).findOneBy({ id: userId });
31+
if (!user) {
32+
logger.error(
33+
{ opportunityId, userId, opportunity },
34+
'warmIntroNotification: User not found',
35+
);
36+
return;
37+
}
38+
3039
await con
3140
.getRepository(OpportunityMatch)
3241
.createQueryBuilder()
@@ -43,18 +52,6 @@ export const warmIntroNotification: TypedNotificationWorker<'gondul.v1.warm-intr
4352
)
4453
.execute();
4554

46-
// TODO: Temporary until we happy to launch
47-
const isTeamMember = await con.getRepository(Feature).exists({
48-
where: {
49-
userId,
50-
feature: FeatureType.Team,
51-
value: 1,
52-
},
53-
});
54-
if (!isTeamMember) {
55-
return;
56-
}
57-
5855
const organization = await opportunity.organization;
5956
const users = await opportunity.users;
6057

src/workers/opportunity/storeCandidateApplicationScore.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { TypedWorker } from '../worker';
22
import { ApplicationScored } from '@dailydotdev/schema';
33
import { OpportunityMatch } from '../../entity/OpportunityMatch';
44
import { applicationScoreSchema } from '../../common/schema/opportunities';
5+
import { User } from '../../entity';
6+
import { logger } from '../../logger';
57

68
export const storeCandidateApplicationScore: TypedWorker<'gondul.v1.candidate-application-scored'> =
79
{
@@ -14,6 +16,15 @@ export const storeCandidateApplicationScore: TypedWorker<'gondul.v1.candidate-ap
1416
);
1517
}
1618

19+
const user = await con.getRepository(User).findOneBy({ id: userId });
20+
if (!user) {
21+
logger.error(
22+
{ opportunityId, userId },
23+
'storeCandidateApplicationScore: User not found',
24+
);
25+
return;
26+
}
27+
1728
const applicationRank = applicationScoreSchema.parse({
1829
score,
1930
description,

src/workers/opportunity/storeCandidateOpportunityMatch.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { TypedWorker } from '../worker';
22
import { MatchedCandidate } from '@dailydotdev/schema';
33
import { OpportunityMatch } from '../../entity/OpportunityMatch';
44
import { opportunityMatchDescriptionSchema } from '../../common/schema/opportunities';
5-
import { Alerts } from '../../entity';
5+
import { Alerts, User } from '../../entity';
66
import { IsNull } from 'typeorm';
7+
import { logger } from '../../logger';
78

89
export const storeCandidateOpportunityMatch: TypedWorker<'gondul.v1.candidate-opportunity-match'> =
910
{
@@ -17,6 +18,15 @@ export const storeCandidateOpportunityMatch: TypedWorker<'gondul.v1.candidate-op
1718
);
1819
}
1920

21+
const user = await con.getRepository(User).findOneBy({ id: userId });
22+
if (!user) {
23+
logger.error(
24+
{ opportunityId, userId },
25+
'storeCandidateOpportunityMatch: User not found',
26+
);
27+
return;
28+
}
29+
2030
const description = opportunityMatchDescriptionSchema.parse({
2131
reasoning,
2232
reasoningShort,

0 commit comments

Comments
 (0)