Skip to content

Commit 15d75a2

Browse files
fix: anon user (#3438)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Chris Bongers <rebelchris@users.noreply.github.com>
1 parent 2d8823c commit 15d75a2

2 files changed

Lines changed: 67 additions & 3 deletions

File tree

src/common/schema/opportunityMatch.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ export type FeedbackClassification = z.infer<
1818
typeof feedbackClassificationSchema
1919
>;
2020

21+
export const anonymousUserContextSchema = z.object({
22+
seniority: z.string().nullable().optional(),
23+
locationCountry: z.string().nullable().optional(),
24+
});
25+
26+
export type AnonymousUserContext = z.infer<typeof anonymousUserContextSchema>;
27+
2128
export const opportunityScreeningAnswersSchema = z.object({
2229
id: z.uuid(),
2330
answers: z

src/schema/opportunity.ts

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,31 @@ export const typeDefs = /* GraphQL */ `
372372
edges: [OpportunityMatchEdge!]!
373373
}
374374
375+
"""
376+
Anonymous user context data captured at feedback submission time
377+
"""
378+
type AnonymousUserContext {
379+
"""
380+
User's seniority/experience level (e.g., junior, senior, staff)
381+
"""
382+
seniority: String
383+
"""
384+
User's country (general location, not specific city)
385+
"""
386+
locationCountry: String
387+
}
388+
375389
type FeedbackClassification {
376390
platform: Int!
377391
category: Int!
378392
sentiment: Int!
379393
urgency: Int!
380394
screening: String!
381395
answer: String!
396+
"""
397+
Anonymous user context captured at feedback submission
398+
"""
399+
userContext: AnonymousUserContext
382400
}
383401
384402
type FeedbackClassificationEdge {
@@ -1830,23 +1848,62 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
18301848
where: {
18311849
opportunityId,
18321850
},
1833-
select: ['feedback'],
1851+
select: ['feedback', 'userId'],
18341852
}),
18351853
);
18361854

1855+
// Gather unique userIds and fetch their anonymous context with candidate preferences
1856+
const userIds = [...new Set(matches.map((m) => m.userId))];
1857+
1858+
const users = await ctx.con.getRepository(User).find({
1859+
where: { id: In(userIds) },
1860+
select: ['id', 'experienceLevel', 'flags'],
1861+
relations: ['candidatePreference', 'candidatePreference.location'],
1862+
});
1863+
1864+
const userContextMap = new Map(
1865+
await Promise.all(
1866+
users.map(async (user) => {
1867+
const flags = (user.flags ?? {}) as Record<string, unknown>;
1868+
const preference = await user.candidatePreference;
1869+
const preferenceLocation = preference?.location
1870+
? await preference.location
1871+
: null;
1872+
1873+
return [
1874+
user.id,
1875+
{
1876+
seniority: user.experienceLevel ?? null,
1877+
// Prioritize candidatePreference location country over flags.country
1878+
locationCountry:
1879+
preferenceLocation?.country ??
1880+
(flags.country as string) ??
1881+
null,
1882+
},
1883+
] as const;
1884+
}),
1885+
),
1886+
);
1887+
18371888
// Extract feedback items with recruiter platform classification
18381889
const allFeedback = matches
1839-
.flatMap((match) => match.feedback ?? [])
1890+
.flatMap((match) =>
1891+
(match.feedback ?? []).map((f) => ({
1892+
...f,
1893+
userId: match.userId,
1894+
})),
1895+
)
18401896
.filter(
18411897
(f) => f.classification?.platform === FeedbackPlatform.RECRUITER,
18421898
)
1843-
.map(({ screening, answer, classification }) => ({
1899+
.map(({ screening, answer, classification, userId }) => ({
18441900
screening,
18451901
answer,
18461902
platform: classification!.platform,
18471903
category: classification!.category,
18481904
sentiment: classification!.sentiment,
18491905
urgency: classification!.urgency,
1906+
userContext: userContextMap.get(userId) ?? {},
18501907
}));
18511908

18521909
const totalCount = allFeedback.length;

0 commit comments

Comments
 (0)