Skip to content

Enhance GET /bounties/:id with full details#74

Open
buttonwild wants to merge 1 commit intodevasignhq:mainfrom
buttonwild:feature/bounty-detail
Open

Enhance GET /bounties/:id with full details#74
buttonwild wants to merge 1 commit intodevasignhq:mainfrom
buttonwild:feature/bounty-detail

Conversation

@buttonwild
Copy link

Description

Implement GET /bounties/:id — bounty detail endpoint as per bounty requirements.

Changes

  • Add creator info (username, avatar)
  • Add assignee info (if assigned)
  • Add application count
  • Add current status field
  • Use Drizzle ORM's with clause for eager loading

Issue

Fixes #21

- Add creator info (username, avatar)
- Add assignee info (if assigned)
- Add application count
- Add current status field
- Use Drizzle ORM's with clause for eager loading
@devasign-app
Copy link

devasign-app bot commented Mar 1, 2026

🟠 AI Code Review Results

Status: Changes Needed
Confidence: 100%


🟠 Merge Score: 65/100

🔴 █████████████░░░░░░░ 65%

Recommendation: ❌ This PR needs significant improvements before it should be merged.

The PR correctly adds the required data to the bounty details endpoint but introduces a performance bottleneck by using two separate database queries. The response construction is also verbose and includes a redundant field. A refactor is suggested to use a single, more efficient query and simplify the code.

💡 Code Suggestions (1)

🔴 High Priority (1)

  1. packages/api/src/routes/bounties.ts (Line 129)
    ⚡ The current implementation uses two separate database queries to fetch the bounty details and the application count, which is inefficient. Additionally, the response object is constructed manually, leading to verbose code and a redundant currentStatus field that duplicates the existing status field.

💭 Reasoning: Refactoring to a single database query using Drizzle's extras for the count and aliasing columns in the with clause will significantly improve performance by reducing database round-trips. This change also simplifies the code, makes it more maintainable, and cleans up the API response by removing duplicate fields and renaming status to currentStatus cleanly.

Suggested Code:

bountiesRouter.get('/:id', async (c) => {
    const id = c.req.param('id');

    const bountyResult = await db.query.bounties.findFirst({
        where: eq(bounties.id, id),
        with: {
            creator: {
                columns: {
                    id: true,
                    username: true,
                    avatar: users.avatarUrl, // Alias avatarUrl to avatar
                },
            },
            assignee: {
                columns: {
                    id: true,
                    username: true,
                    avatar: users.avatarUrl, // Alias avatarUrl to avatar
                },
            },
        },
        extras: {
            applicationCount: sql<number>`(select count(*) from ${applications} where ${applications.bountyId} = ${bounties.id})`.as('application_count'),
        }
    });

    if (!bountyResult) {
        return c.json({ error: 'Bounty not found' }, 404);
    }

    // Destructure to rename 'status' to 'currentStatus' and remove the original 'status' field
    const { status, ...bountyData } = bountyResult;
    const response = {
        ...bountyData,
        currentStatus: status,
    };

    return c.json(response);
});
📊 Review Metadata
  • Processing Time: 73s
  • Analysis Date: 3/1/2026, 12:29:36 AM

🤖 This review was generated by AI. While we strive for accuracy, please use your judgment when applying suggestions.

💬 Questions about this review? Open an issue or contact support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement GET /bounties/:id — bounty detail

1 participant