Skip to content

Commit 107fb3f

Browse files
authored
fix: gondul result parsing (#3343)
1 parent 3cb490a commit 107fb3f

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/common/schema/opportunities.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,8 @@ export const opportunitySubscriptionFlagsSchema = z
295295
}),
296296
})
297297
.partial();
298+
299+
export const gondulOpportunityPreviewResultSchema = z.object({
300+
user_ids: z.array(z.string()),
301+
total_count: z.number().int().nonnegative(),
302+
});

src/schema/opportunity.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import {
6767
createSharedSlackChannelSchema,
6868
parseOpportunitySchema,
6969
opportunityMatchesQuerySchema,
70+
gondulOpportunityPreviewResultSchema,
7071
} from '../common/schema/opportunities';
7172
import { OpportunityKeyword } from '../entity/OpportunityKeyword';
7273
import {
@@ -1284,11 +1285,22 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
12841285
userIds = opportunity.flags.preview.userIds;
12851286
totalCount = opportunity.flags.preview.totalCount;
12861287
} else {
1288+
const opportunityContent: Record<string, unknown> = {};
1289+
1290+
// since this is json endpoint we need to make sure all keys are present
1291+
// even if empty, remove this when we move to protobuf service call
1292+
Object.keys(new OpportunityContent()).forEach((key) => {
1293+
const opportunityKey = key as keyof OpportunityContent;
1294+
1295+
opportunityContent[opportunityKey] =
1296+
opportunity.content[opportunityKey] || {};
1297+
});
1298+
12871299
const validatedPayload = {
12881300
opportunity: {
12891301
title: opportunity.title,
12901302
tldr: opportunity.tldr,
1291-
content: opportunity.content,
1303+
content: opportunityContent,
12921304
meta: opportunity.meta,
12931305
location: opportunity.location,
12941306
state: opportunity.state,
@@ -1314,7 +1326,13 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
13141326
if (!response.ok) {
13151327
throw new Error('Failed to fetch opportunity preview');
13161328
}
1317-
return await response.json();
1329+
const { user_ids, total_count } =
1330+
gondulOpportunityPreviewResultSchema.parse(await response.json());
1331+
1332+
return {
1333+
userIds: user_ids,
1334+
totalCount: total_count,
1335+
};
13181336
});
13191337

13201338
await ctx.con.getRepository(OpportunityJob).update(

0 commit comments

Comments
 (0)