Skip to content

feat: implement credential controller and routes#47

Merged
3m1n3nc3 merged 2 commits into
learnault:mainfrom
tech-adrian:feature/credential-controller-routes
Mar 9, 2026
Merged

feat: implement credential controller and routes#47
3m1n3nc3 merged 2 commits into
learnault:mainfrom
tech-adrian:feature/credential-controller-routes

Conversation

@tech-adrian
Copy link
Copy Markdown
Contributor

Credential Controller & Routes Implementation

Closes #8

Overview

Implements credential management endpoints for certificates and achievements as specified in issue #8.

Changes Made

New Files

  • src/controllers/credential.controller.ts - Controller with three main endpoints
  • src/routes/v1/credentials.routes.ts - Route definitions with validation
  • tests/unit/credential.controller.test.ts - Comprehensive unit tests (14 tests, all passing)

Modified Files

  • src/routes/index.ts - Added credentials routes to API

Implemented Endpoints

1. GET /api/v1/credentials

  • Auth: Required
  • Purpose: Retrieve all credentials for authenticated user
  • Query Params: moduleId, fromDate, toDate, page, limit
  • Features:
    • Pagination support (default: page=1, limit=10, max=100)
    • Filter by module
    • Filter by date range
    • Returns credential details with module information
    • Includes shareable verification links

2. GET /api/v1/credentials/:id

  • Auth: Required (user must own credential)
  • Purpose: Retrieve single credential details
  • Features:
    • Full credential information
    • Module details (title, description, category, difficulty, reward)
    • Holder information
    • Verification metadata
    • Shareable link

3. GET /api/v1/credentials/verify/:onChainId

  • Auth: Not required (public endpoint)
  • Purpose: Public verification of credentials
  • Features:
    • Verifies by onChainId or regular credential ID
    • Returns validation status
    • Shows credential holder and module information
    • Timestamp of verification

Technical Details

Validation

  • Uses Zod schemas for input validation
  • UUID validation for IDs
  • ISO 8601 datetime validation for date filters
  • Numeric validation for pagination parameters

Error Handling

  • Proper HTTP status codes (400, 401, 404)
  • Descriptive error messages
  • Uses custom error classes (BadRequestError, NotFoundError, UnauthorizedError)
  • Wrapped with asyncHandler for promise rejection handling

Database

  • Uses Prisma ORM
  • Efficient queries with proper includes
  • Pagination with count queries
  • Indexed lookups by ID and onChainId

Testing

  • 14 unit tests covering all endpoints
  • Tests for success cases
  • Tests for error cases (invalid input, unauthorized access, not found)
  • Tests for filtering and pagination
  • All tests passing ✅

Acceptance Criteria Met

  • ✅ Users can view all their earned credentials
  • ✅ Public verification endpoint returns credential validity
  • ✅ Verification works without authentication
  • ✅ Credential details include on-chain reference
  • ✅ Filtering and pagination work correctly
  • ✅ Unit tests written and passing

Code Quality

  • ✅ Linting passed
  • ✅ All existing tests still passing (225 tests total)
  • ✅ Follows existing codebase patterns
  • ✅ Proper TypeScript types
  • ✅ Comprehensive error handling
  • ✅ Clean, readable code with comments

- Add GET /credentials endpoint for user credentials with filtering and pagination
- Add GET /credentials/:id endpoint for single credential details
- Add GET /credentials/verify/:onChainId for public verification
- Implement comprehensive validation using Zod schemas
- Add 14 unit tests with full coverage
- Update routes index to include credentials endpoints

Closes learnault#8
@tech-adrian
Copy link
Copy Markdown
Contributor Author

@3m1n3nc3 please review and merge

@3m1n3nc3 3m1n3nc3 merged commit 4b282bc into learnault:main Mar 9, 2026
1 check passed
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