From 285ca2060ca9673a6d53f475d933bcd79d06ba74 Mon Sep 17 00:00:00 2001 From: "Galio (Demaciains)" Date: Sun, 22 Mar 2026 15:51:04 +0000 Subject: [PATCH] feat: include relevanceScore in GET /bounties/recommended response The issue (#22) asks to 'Return top matches with relevance scores' but the endpoint was stripping relevanceScore from the response. Changes: - Keep relevanceScore in scored bounties response (remove destructuring that strips it) - Add relevanceScore: 0 for no-tech-stack fallback path - Add relevanceScore assertions to existing tests Fixes #22 --- packages/api/src/__tests__/bounties_recommended.test.ts | 5 +++++ packages/api/src/routes/bounties.ts | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/api/src/__tests__/bounties_recommended.test.ts b/packages/api/src/__tests__/bounties_recommended.test.ts index 0a7e52d..8794014 100644 --- a/packages/api/src/__tests__/bounties_recommended.test.ts +++ b/packages/api/src/__tests__/bounties_recommended.test.ts @@ -80,8 +80,11 @@ describe('GET /api/bounties/recommended', () => { // Check sorting: Bounty 2 (2 score), Bounty 3 (1 score), Bounty 1 (0 score) expect(body.data).toHaveLength(3); expect(body.data[0].id).toBe('2'); + expect(body.data[0].relevanceScore).toBe(2); expect(body.data[1].id).toBe('3'); + expect(body.data[1].relevanceScore).toBe(1); expect(body.data[2].id).toBe('1'); + expect(body.data[2].relevanceScore).toBe(0); }); it('should fall back to sorting by createdAt for identical relevance scores', async () => { @@ -117,7 +120,9 @@ describe('GET /api/bounties/recommended', () => { // Check sorting: Both have 1 score, so the newer one comes first expect(body.data).toHaveLength(2); expect(body.data[0].id).toBe('new'); + expect(body.data[0].relevanceScore).toBe(1); expect(body.data[1].id).toBe('old'); + expect(body.data[1].relevanceScore).toBe(1); }); it('should use cache on subsequent requests within TTL', async () => { diff --git a/packages/api/src/routes/bounties.ts b/packages/api/src/routes/bounties.ts index 316bda0..ae30616 100644 --- a/packages/api/src/routes/bounties.ts +++ b/packages/api/src/routes/bounties.ts @@ -168,9 +168,12 @@ bountiesRouter.get('/recommended', async (c) => { let results = []; - // If no tech stack, just return latest open bounties + // If no tech stack, just return latest open bounties with relevanceScore: 0 if (techStack.length === 0) { - results = openBounties.slice(0, 10); + results = openBounties.slice(0, 10).map(bounty => ({ + ...bounty, + relevanceScore: 0, + })); } else { // Calculate relevance score const scoredBounties = openBounties.map(bounty => { @@ -195,7 +198,7 @@ bountiesRouter.get('/recommended', async (c) => { return b.createdAt.getTime() - a.createdAt.getTime(); }); - results = scoredBounties.slice(0, 10).map(({ relevanceScore, ...rest }) => rest); + results = scoredBounties.slice(0, 10); } // Save to cache