Skip to content
Open
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
5 changes: 5 additions & 0 deletions packages/api/src/__tests__/bounties_recommended.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
9 changes: 6 additions & 3 deletions packages/api/src/routes/bounties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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
Expand Down