Skip to content

Commit 3f1b052

Browse files
authored
fix: minimal opportunity query (#3451)
1 parent 5f77687 commit 3f1b052

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

__tests__/schema/opportunity.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,63 @@ describe('query opportunityById', () => {
519519
});
520520
});
521521

522+
describe('query opportunityByIdPublic', () => {
523+
const QUERY = /* GraphQL */ `
524+
query OpportunityByIdPublic($id: ID!) {
525+
opportunityByIdPublic(id: $id) {
526+
id
527+
title
528+
organization {
529+
name
530+
}
531+
flags {
532+
plan
533+
}
534+
}
535+
}
536+
`;
537+
538+
it('should return opportunity with organization for anonymous user', async () => {
539+
const res = await client.query<
540+
{
541+
opportunityByIdPublic: {
542+
id: string;
543+
title: string;
544+
organization: { name: string } | null;
545+
flags: { plan: string | null } | null;
546+
} | null;
547+
},
548+
{ id: string }
549+
>(QUERY, {
550+
variables: { id: '550e8400-e29b-41d4-a716-446655440001' },
551+
});
552+
553+
expect(res.errors).toBeFalsy();
554+
expect(res.data.opportunityByIdPublic).toEqual({
555+
id: '550e8400-e29b-41d4-a716-446655440001',
556+
title: 'Senior Full Stack Developer',
557+
organization: { name: 'Daily Dev Inc' },
558+
flags: { plan: null },
559+
});
560+
});
561+
562+
it('should return null for non-existent opportunity', async () => {
563+
const res = await client.query<
564+
{
565+
opportunityByIdPublic: {
566+
id: string;
567+
} | null;
568+
},
569+
{ id: string }
570+
>(QUERY, {
571+
variables: { id: '550e8400-e29b-41d4-a716-000000000000' },
572+
});
573+
574+
expect(res.errors).toBeFalsy();
575+
expect(res.data.opportunityByIdPublic).toBeNull();
576+
});
577+
});
578+
522579
describe('query opportunities', () => {
523580
const GET_OPPORTUNITIES_QUERY = /* GraphQL */ `
524581
query GetOpportunities(

src/schema/opportunity.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,30 @@ export const typeDefs = /* GraphQL */ `
300300
showFeedback: Boolean
301301
}
302302
303+
"""
304+
Minimal organization info for public opportunity
305+
"""
306+
type OpportunityPublicOrganization {
307+
name: String!
308+
}
309+
310+
"""
311+
Minimal flags for public opportunity
312+
"""
313+
type OpportunityPublicFlags {
314+
plan: String
315+
}
316+
317+
"""
318+
Minimal opportunity info for public access
319+
"""
320+
type OpportunityPublic {
321+
id: ID!
322+
title: String!
323+
organization: OpportunityPublicOrganization
324+
flags: OpportunityPublicFlags
325+
}
326+
303327
type Opportunity {
304328
id: ID!
305329
type: ProtoEnumValue!
@@ -606,6 +630,15 @@ export const typeDefs = /* GraphQL */ `
606630
id: ID!
607631
): Opportunity
608632
"""
633+
Get public information about an opportunity (accessible by anonymous users)
634+
"""
635+
opportunityByIdPublic(
636+
"""
637+
Id of Opportunity
638+
"""
639+
id: ID!
640+
): OpportunityPublic
641+
"""
609642
Gets the status and description from the Opportunity match
610643
"""
611644
getOpportunityMatch(
@@ -1311,6 +1344,27 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
13111344

13121345
return opportunity;
13131346
},
1347+
opportunityByIdPublic: async (_, { id }: { id: string }, ctx: Context) =>
1348+
queryReadReplica(ctx.con, async ({ queryRunner }) => {
1349+
const opportunity = await queryRunner.manager
1350+
.getRepository(OpportunityJob)
1351+
.createQueryBuilder('o')
1352+
.leftJoinAndSelect('o.organization', 'org')
1353+
.where('o.id = :id', { id })
1354+
.getOne();
1355+
1356+
if (!opportunity) {
1357+
return null;
1358+
}
1359+
1360+
const organization = await opportunity.organization;
1361+
return {
1362+
id: opportunity.id,
1363+
title: opportunity.title,
1364+
organization: organization ? { name: organization.name } : null,
1365+
flags: { plan: opportunity.flags?.plan ?? null },
1366+
};
1367+
}),
13141368
getOpportunityMatch: async (
13151369
_,
13161370
{ id }: { id: string },

0 commit comments

Comments
 (0)