Skip to content

Commit beae812

Browse files
authored
feat: add opportunities to user object in cio (#3269)
1 parent 9f1a0c6 commit beae812

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

__tests__/workers/cdc/primary.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ jest.mock('../../../src/temporal/notifications/utils', () => ({
246246
cancelEntityReminderWorkflow: jest.fn(),
247247
}));
248248

249+
jest.mock('../../../src/cio', () => ({
250+
...(jest.requireActual('../../../src/cio') as Record<string, unknown>),
251+
identifyUserOpportunities: jest.fn(),
252+
}));
253+
249254
let con: DataSource;
250255

251256
beforeAll(async () => {

src/cio.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ import type { UserCompany } from './entity/UserCompany';
4646
import type { Company } from './entity/Company';
4747
import { DataSource, In } from 'typeorm';
4848
import { logger } from './logger';
49+
import { OpportunityMatch } from './entity/OpportunityMatch';
50+
import { OpportunityMatchStatus } from './entity/opportunities/types';
4951

5052
export const cio = new TrackClient(
5153
process.env.CIO_SITE_ID,
@@ -149,6 +151,29 @@ export async function identifyUserStreak({
149151
}
150152
}
151153

154+
export const identifyUserOpportunities = async ({
155+
cio,
156+
con,
157+
userId,
158+
}: {
159+
cio: TrackClient;
160+
con: ConnectionManager;
161+
userId: string;
162+
}): Promise<void> => {
163+
const opportunities = await con.getRepository(OpportunityMatch).find({
164+
where: {
165+
userId,
166+
status: OpportunityMatchStatus.Pending,
167+
},
168+
select: ['opportunityId'],
169+
});
170+
await cio.identify(userId, {
171+
opportunities: opportunities.map(
172+
(opportunity) => opportunity.opportunityId,
173+
),
174+
});
175+
};
176+
152177
export const generateIdentifyObject = async (
153178
con: ConnectionManager,
154179
user: ChangeObject<User>,

src/workers/cdc/primary.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ import { PollPost } from '../../entity/posts/PollPost';
162162
import { UserExperienceWork } from '../../entity/user/experiences/UserExperienceWork';
163163
import { UserExperience } from '../../entity/user/experiences/UserExperience';
164164
import { UserExperienceType } from '../../entity/user/experiences/types';
165+
import { cio, identifyUserOpportunities } from '../../cio';
165166

166167
const isFreeformPostLongEnough = (
167168
freeform: ChangeMessage<FreeformPost>,
@@ -1292,6 +1293,11 @@ const onOpportunityMatchChange = async (
12921293
logger: FastifyBaseLogger,
12931294
data: ChangeMessage<OpportunityMatch>,
12941295
) => {
1296+
await identifyUserOpportunities({
1297+
con,
1298+
cio,
1299+
userId: data.payload.after?.userId ?? data.payload.before?.userId ?? '',
1300+
});
12951301
if (data.payload.op === 'u') {
12961302
if (
12971303
data.payload.after?.status === OpportunityMatchStatus.CandidateAccepted &&

0 commit comments

Comments
 (0)