Skip to content

feat: Implement GET /api/credit/lines/:id With Repository + Standardized 404 Handling (#6)#68

Open
Bug-Hunter-X wants to merge 4 commits intoCreditra:mainfrom
Bug-Hunter-X:feature/get-credit-line-by-id
Open

feat: Implement GET /api/credit/lines/:id With Repository + Standardized 404 Handling (#6)#68
Bug-Hunter-X wants to merge 4 commits intoCreditra:mainfrom
Bug-Hunter-X:feature/get-credit-line-by-id

Conversation

@Bug-Hunter-X
Copy link
Contributor

Overview

Implements GET /api/credit/lines/:id using a shared credit line repository and standardized error handling middleware.
The route now returns full credit line details on success (200) and a consistent not-found error body on missing IDs (404).

Closes #6

Changes

Core API

  • [ADD] src/repositories/creditLineRepository.ts

    • Added creditLineRepository with:
    • getById(id: string): CreditLine | undefined
    • getAll(): CreditLine[]
    • Reuses shared CreditLine model/store from the credit service.
  • [MODIFY] src/routes/credit.ts

    • GET /lines/:id now uses creditLineRepository.getById.
    • Throws CreditLineNotFoundError when missing and delegates to route error middleware.
    • Returns full payload as { data: <creditLine> } with status 200.
    • Standardized not-found response via shared error handling: { error: 'Credit line "<id>" not found.' } with status 404.
    • Route-level error handler middleware now handles service/repository errors consistently.

Tests

  • [ADD] src/test/creditLineRepository.test.ts

    • Verifies getById returns full object for known ID.
    • Verifies getById returns undefined for unknown ID.
  • [MODIFY] src/test/creditRoute.test.ts

    • Updated GET-by-id tests to assert full payload and exact standardized 404 body.
    • Added 500-path tests for repository-thrown Error and non-Error throw to fully cover route error branches.
    • Converted this test file to Vitest-native mocking (vi) to run in current test runner.

Documentation

  • [MODIFY] README.md
    • Updated API section to document concrete behavior for GET /api/credit/lines/:id, including standardized 404 response shape.

Dependencies

  • [MODIFY] package.json
  • [MODIFY] package-lock.json
    • Added missing test deps used by existing route tests: supertest, @types/supertest.

How to Run Tests

npm test -- src/__test__/creditRoute.test.ts src/__test__/creditLineRepository.test.ts

# Coverage for this route handler:
npx vitest run src/__test__/creditRoute.test.ts --coverage --coverage.include=src/routes/credit.ts --coverage.reporter=text

Verification Results

Requirement Status
getById added in repository Done
GET route uses repository Done
200 with full payload on found Done
404 standardized error on not found Done
Tests for found/not-found Done
Route handler coverage >=95% Done (100% lines/branches/functions for src/routes/credit.ts)
Documentation updated Done

Verification Evidence

  • npm test -- src/__test__/creditRoute.test.ts src/__test__/creditLineRepository.test.ts
    • 2 test files passed, 25 tests passed.
image
  • npx vitest run src/__test__/creditRoute.test.ts --coverage --coverage.include=src/routes/credit.ts --coverage.reporter=text
    • credit.ts: 100% statements, 100% branches, 100% functions, 100% lines.
image

@Bug-Hunter-X
Copy link
Contributor Author

@greatest0fallt1me please review and merge

… into feature/get-credit-line-by-id

# Conflicts:
#	package-lock.json
#	package.json
#	src/routes/credit.ts
@greatest0fallt1me
Copy link
Contributor

@Bug-Hunter-X Can you resolve the conflicts?

@Bug-Hunter-X
Copy link
Contributor Author

@Bug-Hunter-X Can you resolve the conflicts?

@greatest0fallt1me DOne boss

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 /api/credit/lines/:id with proper 404 handling

2 participants