Skip to content

feat: add GET /api/v1/check/{checkId} endpoint#245

Merged
UlisesGascon merged 2 commits intomainfrom
ulises/v1-check-details
Jun 16, 2025
Merged

feat: add GET /api/v1/check/{checkId} endpoint#245
UlisesGascon merged 2 commits intomainfrom
ulises/v1-check-details

Conversation

@UlisesGascon
Copy link
Member

@UlisesGascon UlisesGascon commented Jun 16, 2025

Related #216

image

Summary by CodeRabbit

  • New Features

    • Added a new API endpoint to retrieve a specific compliance check by its ID.
    • Updated API documentation to include the new endpoint for fetching individual compliance checks.
  • Tests

    • Introduced tests covering successful retrieval, invalid ID handling, not found, and server error scenarios for the new endpoint.

@UlisesGascon UlisesGascon self-assigned this Jun 16, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jun 16, 2025

Walkthrough

A new API endpoint, GET /api/v1/check/:checkId, was introduced to retrieve a single compliance check by its ID. Supporting changes include the addition of a getCheckById method in the data store, route handler implementation, OpenAPI documentation updates, and corresponding tests for various success and error scenarios.

Changes

File(s) Change Summary
src/store/index.js Added getCheckById method for fetching a compliance check by ID.
src/httpServer/routers/apiV1.js Added new route handler for GET /check/:checkId using getCheckById; updated error message in /check.
src/httpServer/swagger/api-v1.yml Documented new endpoint /api/v1/check/{checkId} with responses and parameter details.
tests/httpServer/apiV1.test.js Added tests for the new endpoint, covering success, validation, not found, and server error cases.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API_Router
    participant Store

    Client->>API_Router: GET /api/v1/check/:checkId
    API_Router->>API_Router: Validate checkId
    alt checkId invalid
        API_Router-->>Client: 400 Bad Request
    else checkId valid
        API_Router->>Store: getCheckById(checkId)
        alt Check found
            API_Router-->>Client: 200 OK (Check data)
        else Check not found
            API_Router-->>Client: 404 Not Found
        end
    end
    alt Internal error
        API_Router-->>Client: 500 Internal Server Error
    end
Loading

Poem

In the warren of code, a new path appears,
Fetching checks by ID—let’s give three cheers!
With tests that ensure each branch is explored,
And docs that keep all the details stored.
Now, one little hop brings the answer you seek,
For compliance is found—no need to peek!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9178c61 and fb479bd.

📒 Files selected for processing (4)
  • __tests__/httpServer/apiV1.test.js (3 hunks)
  • src/httpServer/routers/apiV1.js (2 hunks)
  • src/httpServer/swagger/api-v1.yml (1 hunks)
  • src/store/index.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/store/index.js
  • tests/httpServer/apiV1.test.js
  • src/httpServer/swagger/api-v1.yml
  • src/httpServer/routers/apiV1.js
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@UlisesGascon UlisesGascon added this to the v1.0.0 milestone Jun 16, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
src/httpServer/routers/apiV1.js (1)

148-149: Typo in log message

'Failed to retrieve Compliance Checks' was updated, but “Checks” is now plural whereas the corresponding singular route above still says “Check”. Align wording or factor a helper to avoid drift.

__tests__/httpServer/apiV1.test.js (1)

418-424: Expectation couples test to middleware wording

The test asserts the exact string must be integer. If we ever tweak the OpenAPI-validator version (or remove redundant manual validation per previous comment) this will become brittle.

Recommend asserting on status + presence of an error field, not the specific phrasing:

-      expect(response.body.errors[0]).toHaveProperty('message', 'must be integer')
+      expect(response.body.errors[0].message).toMatch(/integer/i)

Keeps the intent while decoupling from library internals.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 981ce19 and 9178c61.

📒 Files selected for processing (4)
  • __tests__/httpServer/apiV1.test.js (3 hunks)
  • src/httpServer/routers/apiV1.js (2 hunks)
  • src/httpServer/swagger/api-v1.yml (1 hunks)
  • src/store/index.js (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Playwright Tests
🔇 Additional comments (1)
src/store/index.js (1)

252-254: ```shell
#!/bin/bash
echo "Checking definitions in src/store/index.js:"
rg "getAllComplianceChecks" -n src/store/index.js
rg "getAllChecks" -n src/store/index.js

echo
echo "Checking usages across repository:"
rg "getAllComplianceChecks(" -n .
rg "getAllChecks(" -n .


</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Comment on lines 124 to 137
router.get('/check/:checkId', async (req, res) => {
try {
const checkId = parseInt(req.params.checkId, 10)
if (isNaN(checkId) || !Number.isInteger(checkId) || checkId <= 0) {
return res.status(400).json({ errors: [{ message: 'Invalid Compliance Check ID. Must be a positive integer.' }] })
}

const check = await getCheckById(checkId)
if (!check) {
return res.status(404).json({ errors: [{ message: 'Compliance Check not found' }] })
}
res.json(check)
} catch (error) {
logger.error(error)
res.status(500).json({ errors: [{ message: 'Failed to retrieve Compliance Check' }] })
}
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Redundant validation & message drift

The OpenAPI-validator middleware already guarantees checkId is an integer ≥ 0, so the manual parseInt block is never reached for invalid IDs.
Consequences:

  1. Dead code path → harder to test.
  2. Error message returned by middleware (“must be integer”) differs from the hard-coded one (“Invalid Compliance Check ID …”), creating confusion for API users and for the test suite.

Either:

A) Delete the manual check and rely on spec validation, or
B) Disable param validation for this route and keep the manual logic, but then adjust the spec & tests.

Option A is simpler:

-      const checkId = parseInt(req.params.checkId, 10)
-      if (isNaN(checkId) || !Number.isInteger(checkId) || checkId <= 0) {
-        return res.status(400).json({ errors: [{ message: 'Invalid Compliance Check ID. Must be a positive integer.' }] })
-      }
-
-      const check = await getCheckById(checkId)
+      const checkId = req.params.checkId              // already integer by validator
+      const check = await getCheckById(checkId)

This also removes one source of truth for the error message.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
router.get('/check/:checkId', async (req, res) => {
try {
const checkId = parseInt(req.params.checkId, 10)
if (isNaN(checkId) || !Number.isInteger(checkId) || checkId <= 0) {
return res.status(400).json({ errors: [{ message: 'Invalid Compliance Check ID. Must be a positive integer.' }] })
}
const check = await getCheckById(checkId)
if (!check) {
return res.status(404).json({ errors: [{ message: 'Compliance Check not found' }] })
}
res.json(check)
} catch (error) {
logger.error(error)
res.status(500).json({ errors: [{ message: 'Failed to retrieve Compliance Check' }] })
}
})
router.get('/check/:checkId', async (req, res) => {
try {
const checkId = req.params.checkId // already integer by validator
const check = await getCheckById(checkId)
if (!check) {
return res.status(404).json({ errors: [{ message: 'Compliance Check not found' }] })
}
res.json(check)
} catch (error) {
logger.error(error)
res.status(500).json({ errors: [{ message: 'Failed to retrieve Compliance Check' }] })
}
})
🤖 Prompt for AI Agents
In src/httpServer/routers/apiV1.js around lines 124 to 140, remove the manual
parseInt and validation logic for checkId since the OpenAPI-validator middleware
already ensures checkId is a positive integer. This eliminates redundant code
and inconsistent error messages. Rely solely on the middleware validation and
keep the rest of the route handler unchanged.

@UlisesGascon UlisesGascon force-pushed the ulises/v1-check-details branch from 9178c61 to fb479bd Compare June 16, 2025 14:07
@UlisesGascon UlisesGascon merged commit 9c7cd61 into main Jun 16, 2025
7 checks passed
@UlisesGascon UlisesGascon deleted the ulises/v1-check-details branch June 16, 2025 14:11
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.

1 participant