Skip to content

Commit ff5a738

Browse files
authored
fix: send recruiter to match accepted (#3187)
1 parent bd639bb commit ff5a738

File tree

4 files changed

+60
-14
lines changed

4 files changed

+60
-14
lines changed

__tests__/workers/cdc/primary.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ import {
172172
} from '../../../src/entity/contentPreference/types';
173173
import { OpportunityMatch } from '../../../src/entity/OpportunityMatch';
174174
import { UserCandidatePreference } from '../../../src/entity/user/UserCandidatePreference';
175-
import { OpportunityMatchStatus } from '../../../src/entity/opportunities/types';
175+
import {
176+
OpportunityMatchStatus,
177+
OpportunityUserType,
178+
} from '../../../src/entity/opportunities/types';
176179
import { OpportunityJob } from '../../../src/entity/opportunities/OpportunityJob';
177180
import {
178181
opportunitiesFixture,
@@ -185,6 +188,7 @@ import {
185188
ContentPreferenceOrganization,
186189
ContentPreferenceOrganizationStatus,
187190
} from '../../../src/entity/contentPreference/ContentPreferenceOrganization';
191+
import { OpportunityUser } from '../../../src/entity/opportunities/user';
188192

189193
jest.mock('../../../src/common', () => ({
190194
...(jest.requireActual('../../../src/common') as Record<string, unknown>),
@@ -5643,6 +5647,13 @@ describe('opportunity match', () => {
56435647

56445648
beforeEach(async () => {
56455649
await saveFixtures(con, User, usersFixture);
5650+
await con.getRepository(User).update(
5651+
{ id: usersFixture[0].id },
5652+
{
5653+
title: 'CTO',
5654+
bio: 'Here to break things',
5655+
},
5656+
);
56465657
await saveFixtures(con, Organization, organizationsFixture);
56475658
await saveFixtures(con, Opportunity, opportunitiesFixture);
56485659
await con.getRepository(UserCandidatePreference).save({
@@ -5659,6 +5670,11 @@ describe('opportunity match', () => {
56595670
screening: [],
56605671
applicationRank: {},
56615672
});
5673+
await con.getRepository(OpportunityUser).save({
5674+
userId: usersFixture[0].id,
5675+
opportunityId: opportunitiesFixture[0].id,
5676+
type: OpportunityUserType.Recruiter,
5677+
});
56625678
});
56635679

56645680
describe('candidate accepted', () => {
@@ -5800,6 +5816,11 @@ describe('opportunity match', () => {
58005816
expect.objectContaining({
58015817
opportunityId: opportunitiesFixture[0].id,
58025818
userId: '1',
5819+
recruiter: {
5820+
name: 'Ido',
5821+
role: 'CTO',
5822+
bio: 'Here to break things',
5823+
},
58035824
}),
58045825
);
58055826
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"@connectrpc/connect-fastify": "^1.6.1",
3737
"@connectrpc/connect-node": "^1.6.1",
3838
"@dailydotdev/graphql-redis-subscriptions": "^2.4.3",
39-
"@dailydotdev/schema": "0.2.40",
39+
"@dailydotdev/schema": "0.2.47",
4040
"@dailydotdev/ts-ioredis-pool": "^1.0.2",
4141
"@fastify/cookie": "^11.0.2",
4242
"@fastify/cors": "^11.1.0",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common/opportunity/pubsub.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import {
2424
ContentPreferenceType,
2525
} from '../../entity/contentPreference/types';
2626
import { ContentPreferenceOrganization } from '../../entity/contentPreference/ContentPreferenceOrganization';
27+
import { OpportunityUser } from '../../entity/opportunities/user';
28+
import { OpportunityUserType } from '../../entity/opportunities/types';
2729

2830
const fetchCandidateKeywords = async (
2931
manager: EntityManager,
@@ -171,14 +173,32 @@ export const notifyRecruiterCandidateMatchAccepted = async ({
171173
return;
172174
}
173175

174-
const match = await queryReadReplica(con, async ({ queryRunner }) => {
175-
return queryRunner.manager.getRepository(OpportunityMatch).findOne({
176-
select: ['opportunityId', 'userId'],
177-
where: { opportunityId: data.opportunityId, userId: data.userId },
178-
});
179-
});
176+
/**
177+
* TODO: For now this will simply fetch the first recruiter.
178+
* Ideally this should maintain which recruiter accepted the match
179+
*/
180+
const [match, opportunityUser] = await queryReadReplica(
181+
con,
182+
({ queryRunner }) =>
183+
Promise.all([
184+
queryRunner.manager.getRepository(OpportunityMatch).findOne({
185+
select: ['opportunityId', 'userId'],
186+
where: { opportunityId: data.opportunityId, userId: data.userId },
187+
}),
188+
queryRunner.manager.getRepository(OpportunityUser).findOne({
189+
select: ['userId', 'opportunityId', 'type'],
190+
relations: ['user'],
191+
where: {
192+
opportunityId: data.opportunityId,
193+
type: OpportunityUserType.Recruiter,
194+
},
195+
}),
196+
]),
197+
);
180198

181-
if (!match) {
199+
const recruiter = await opportunityUser?.user;
200+
201+
if (!match || !recruiter) {
182202
logger.warn(
183203
{ opportunityId: data.opportunityId, userId: data.userId },
184204
'Opportunity match not found for recruiter accepted candidate notification',
@@ -191,6 +211,11 @@ export const notifyRecruiterCandidateMatchAccepted = async ({
191211
userId: match.userId,
192212
createdAt: getSecondsTimestamp(match.createdAt),
193213
updatedAt: getSecondsTimestamp(match.updatedAt),
214+
recruiter: {
215+
name: recruiter.name,
216+
role: recruiter?.title,
217+
bio: recruiter?.bio,
218+
},
194219
});
195220

196221
try {

0 commit comments

Comments
 (0)