Skip to content

[Enhancement]: Add GET /api/documents/:id endpoint for single document retrieval #62

Open

Description

@Prathvikmehra

🧭 Project Area

Backend / API

📝 Issue Summary and Problem Description

Issue summary:
The backend document module provides endpoints for listing (GET /api/documents), uploading (POST /api/documents), verifying (PATCH /api/documents/:id/verify), and deleting (DELETE /api/documents/:id). However, there is no endpoint to fetch details of a single document by its ID.

Problem description:
If a client attempts to fetch metadata for a single document via GET /api/documents/:id, the request fails with a generic HTTP 404 ROUTE_NOT_FOUND error instead of a resource lookup response.

Why this is important:
Single resource retrieval is a core RESTful API convention required for document detail pages, auditing, and deep linking within the CertiVault platform.

Who is affected:
Frontend developers building document preview modals or detail views, and API consumers needing single document metadata.

🔍 Current and Expected Behaviour

Current behaviour:
GET /api/documents/demo-credential returns HTTP 404 ROUTE_NOT_FOUND ("Route GET /api/documents/demo-credential was not found").

Current result:
Single document details cannot be queried individually by ID.

Expected behaviour:
GET /api/documents/:id should look up the document in documentStore. If found, return HTTP 200 with { data: document }. If not found, return HTTP 404 with DOCUMENT_NOT_FOUND.

Expected result:
GET /api/documents/demo-credential returns 200 OK with the document payload.

🧩 Reproduction and Evidence

Step 1: Start backend (`npm run dev`)
Step 2: Send GET request to `http://localhost:5000/api/documents/demo-credential`
Step 3: Observe 404 ROUTE_NOT_FOUND error
Step 4: Check document.routes.js — no GET /:id route exists

🎯 Affected Scope

Affected files:

  • backend/src/modules/documents/document.controller.js
  • backend/src/modules/documents/document.routes.js
  • backend/tests/integration/app.test.js

Affected APIs: GET /api/documents/:id
Database changes required? No

🖥 Environment

Operating system: Windows 11
Node.js version: v22.x
Package manager: npm 10.x
Deployment environment: Local development

💡 Solution, Alternatives, and Estimate

Priority: P2 Medium
Proposed solution:

  1. Export getDocument controller function in document.controller.js using documentStore.find(req.params.id).
  2. Register documentRouter.get("/:id", getDocument) in document.routes.js.
  3. Add integration tests verifying HTTP 200 (success path) and HTTP 404 (non-existent ID).

Alternative solutions: Client could filter the full GET /api/documents array, but this is inefficient and bad for bandwidth as document count grows.
Difficulty: Beginner
Estimated time: 30 minutes
Dependencies or blockers: None

✅ Acceptance Criteria and Additional Notes

  • GET /api/documents/:id returns 200 OK with document data when ID exists
  • GET /api/documents/:id returns 404 DOCUMENT_NOT_FOUND when ID does not exist
  • Integration tests added to app.test.js covering both success and 404 cases
  • All existing 18 tests continue to pass

🤝 Contributor Checklist

  • I have searched existing issues and pull requests for duplicates.
  • I can reproduce the issue, or I have clearly explained why reproduction is not applicable.
  • I will follow the contribution guidelines and target ecsoc-2026.
  • I agree to follow the Code of Conduct.
  • I have removed secrets, private documents, and personal data.

Activity

  1. added
    backendBackend API, services, workers, or domain logic
    dependenciesDependency updates and package maintenance
    devopsInfrastructure, deployment, CI/CD, or operations
    frontendReact UI, accessibility, and client experience
    securitySecurity hardening or private security coordination
    testingTest coverage, reliability, or tooling
    on Jul 22, 2026
  2. Prathvikmehra commented on Jul 28, 2026

    @Prathvikmehra
    Author

    /claim

  3. added a commit that references this issue on Aug 10, 2026
    fa20092
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

backendBackend API, services, workers, or domain logicdependenciesDependency updates and package maintenancedevopsInfrastructure, deployment, CI/CD, or operationsenhancementNew or improved functionalityfrontendReact UI, accessibility, and client experiencesecuritySecurity hardening or private security coordinationtestingTest coverage, reliability, or toolingtriageNeeds initial maintainer triage

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions