Skip to content

Commit 1fdfae5

Browse files
authored
fix: add update topic (#3364)
1 parent ff326c8 commit 1fdfae5

4 files changed

Lines changed: 25 additions & 12 deletions

File tree

__tests__/workers/cdc/primary.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6917,10 +6917,10 @@ describe('organization', () => {
69176917

69186918
expect(triggerTypedEvent).toHaveBeenCalledTimes(2);
69196919
expect(jest.mocked(triggerTypedEvent).mock.calls[0][1]).toEqual(
6920-
'api.v1.opportunity-added',
6920+
'api.v1.opportunity-updated',
69216921
);
69226922
expect(jest.mocked(triggerTypedEvent).mock.calls[1][1]).toEqual(
6923-
'api.v1.opportunity-added',
6923+
'api.v1.opportunity-updated',
69246924
);
69256925
});
69266926

src/common/opportunity/pubsub.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,12 @@ export const notifyJobOpportunity = async ({
334334
con,
335335
logger,
336336
opportunityId,
337+
isUpdate = false,
337338
}: {
338339
con: DataSource;
339340
logger: FastifyBaseLogger;
340341
opportunityId: string;
342+
isUpdate?: boolean;
341343
}) => {
342344
const [opportunity, organization, keywords, users, locations] =
343345
await queryReadReplica(con, async ({ queryRunner }) => {
@@ -456,8 +458,11 @@ export const notifyJobOpportunity = async ({
456458
excludedUserIds,
457459
});
458460

461+
const topicName = isUpdate
462+
? 'api.v1.opportunity-updated'
463+
: 'api.v1.opportunity-added';
459464
try {
460-
await triggerTypedEvent(logger, 'api.v1.opportunity-added', message);
465+
await triggerTypedEvent(logger, topicName, message);
461466
} catch (_err) {
462467
const err = _err as Error;
463468
logger.error({ err, message }, 'failed to send opportunity event');

src/schema/opportunity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2564,7 +2564,7 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
25642564
.count({
25652565
where: {
25662566
organizationId: organization.id,
2567-
state: OpportunityState.LIVE,
2567+
state: In([OpportunityState.LIVE, OpportunityState.IN_REVIEW]),
25682568
flags: JsonContains({ plan: priceId }),
25692569
},
25702570
});

src/workers/cdc/primary.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,15 +1382,22 @@ const onOpportunityChange = async (
13821382
if (
13831383
data.payload.op === 'u' &&
13841384
data.payload.after?.type === OpportunityType.JOB &&
1385-
data.payload.before?.state === OpportunityState.LIVE &&
1386-
data.payload.after?.state !== OpportunityState.LIVE
1385+
data.payload.before?.state === OpportunityState.LIVE
13871386
) {
1388-
await con
1389-
.getRepository(Alerts)
1390-
.update(
1391-
{ opportunityId: data.payload.after!.id },
1392-
{ opportunityId: null },
1393-
);
1387+
await notifyJobOpportunity({
1388+
con,
1389+
logger,
1390+
opportunityId: data.payload.after!.id,
1391+
isUpdate: true,
1392+
});
1393+
if (data.payload.after?.state !== OpportunityState.LIVE) {
1394+
await con
1395+
.getRepository(Alerts)
1396+
.update(
1397+
{ opportunityId: data.payload.after!.id },
1398+
{ opportunityId: null },
1399+
);
1400+
}
13941401
}
13951402
};
13961403

@@ -1440,6 +1447,7 @@ const onOrganizationChange = async (
14401447
con,
14411448
logger,
14421449
opportunityId: opportunity.id,
1450+
isUpdate: true,
14431451
});
14441452
}),
14451453
);

0 commit comments

Comments
 (0)