Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions __tests__/workers/cdc/primary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6917,10 +6917,10 @@ describe('organization', () => {

expect(triggerTypedEvent).toHaveBeenCalledTimes(2);
expect(jest.mocked(triggerTypedEvent).mock.calls[0][1]).toEqual(
'api.v1.opportunity-added',
'api.v1.opportunity-updated',
);
expect(jest.mocked(triggerTypedEvent).mock.calls[1][1]).toEqual(
'api.v1.opportunity-added',
'api.v1.opportunity-updated',
);
});

Expand Down
7 changes: 6 additions & 1 deletion src/common/opportunity/pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,12 @@ export const notifyJobOpportunity = async ({
con,
logger,
opportunityId,
isUpdate = false,
}: {
con: DataSource;
logger: FastifyBaseLogger;
opportunityId: string;
isUpdate?: boolean;
}) => {
const [opportunity, organization, keywords, users, locations] =
await queryReadReplica(con, async ({ queryRunner }) => {
Expand Down Expand Up @@ -456,8 +458,11 @@ export const notifyJobOpportunity = async ({
excludedUserIds,
});

const topicName = isUpdate
? 'api.v1.opportunity-updated'
: 'api.v1.opportunity-added';
try {
await triggerTypedEvent(logger, 'api.v1.opportunity-added', message);
await triggerTypedEvent(logger, topicName, message);
} catch (_err) {
const err = _err as Error;
logger.error({ err, message }, 'failed to send opportunity event');
Expand Down
2 changes: 1 addition & 1 deletion src/schema/opportunity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2564,7 +2564,7 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
.count({
where: {
organizationId: organization.id,
state: OpportunityState.LIVE,
state: In([OpportunityState.LIVE, OpportunityState.IN_REVIEW]),
flags: JsonContains({ plan: priceId }),
},
});
Expand Down
24 changes: 16 additions & 8 deletions src/workers/cdc/primary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1382,15 +1382,22 @@ const onOpportunityChange = async (
if (
data.payload.op === 'u' &&
data.payload.after?.type === OpportunityType.JOB &&
data.payload.before?.state === OpportunityState.LIVE &&
data.payload.after?.state !== OpportunityState.LIVE
data.payload.before?.state === OpportunityState.LIVE
) {
await con
.getRepository(Alerts)
.update(
{ opportunityId: data.payload.after!.id },
{ opportunityId: null },
);
await notifyJobOpportunity({
con,
logger,
opportunityId: data.payload.after!.id,
isUpdate: true,
});
if (data.payload.after?.state !== OpportunityState.LIVE) {
await con
.getRepository(Alerts)
.update(
{ opportunityId: data.payload.after!.id },
{ opportunityId: null },
);
}
}
};

Expand Down Expand Up @@ -1440,6 +1447,7 @@ const onOrganizationChange = async (
con,
logger,
opportunityId: opportunity.id,
isUpdate: true,
});
}),
);
Expand Down
Loading