Skip to content

feat(backend): POST /api/v1/streams — create stream endpoint with Zod validation#79

Merged
greatest0fallt1me merged 2 commits intoStreampay-Org:mainfrom
Oluwaseyi89:feature/create-stream-persist-optional-chain-invoke
Apr 1, 2026
Merged

feat(backend): POST /api/v1/streams — create stream endpoint with Zod validation#79
greatest0fallt1me merged 2 commits intoStreampay-Org:mainfrom
Oluwaseyi89:feature/create-stream-persist-optional-chain-invoke

Conversation

@Oluwaseyi89
Copy link
Copy Markdown
Contributor

Pull Request: POST /api/v1/streams — Create Stream Endpoint

Implements create stream API as specified in #3.

Changes

  • Validation: Zod schema for payload validation (payer, recipient, ratePerSecond, totalAmount, startTime, endTime)
  • Persistence: StreamRepository.create() with Drizzle returning inserted record
  • Endpoint: POST /api/v1/streams returns 201 with stream_id and status

Files

modified: src/api/v1/streams.ts
modified: src/api/v1/streams.test.ts
modified: src/repositories/streamRepository.ts

Validation Rules

Field Rule
payer/recipient Non-empty strings
ratePerSecond/totalAmount Positive decimal strings
startTime ISO-8601 datetime
endTime Optional ISO-8601 (must be after startTime)

Test Coverage

  • 201 success with mocked repository
  • 400 validation errors with field details
  • 500 error handling

Security

  • All input sanitized via Zod before DB insertion
  • No raw user input in queries
  • Decimal fields as strings (no float precision issues)

Closes #3

… validation

Implements the create stream API for issue Streampay-Org#3.

Changes:
- Add  to StreamRepository using
  Drizzle insert().values().returning() consistent with existing query patterns
- Add Zod schema  validating:
    - payer / recipient (non-empty strings)
    - ratePerSecond / totalAmount (positive decimal strings)
    - startTime / endTime (ISO-8601 datetime; endTime optional)
- Add POST /api/v1/streams handler: validate body → persist → return 201 + stream
- Stream status defaults to active; lastSettledAt seeded from startTime
- Return structured 400 validation errors with per-field details via
  zod.flatten().fieldErrors

Tests (supertest):
- 201 success path with mocked repository
- 400 missing required fields
- 400 invalid ratePerSecond (non-decimal string)
- 400 invalid startTime (non-ISO-8601)
- 500 when repository throws unexpectedly

Security notes:
- All input sanitised through Zod before reaching the repository
- No raw user input passed to DB queries
- Decimal fields accepted as strings to avoid float precision issues

Draft — optional chain invoke not yet wired (follow-up issue)
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 30, 2026

@Oluwaseyi89 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Oluwaseyi89 Oluwaseyi89 marked this pull request as draft March 30, 2026 12:50
@Oluwaseyi89 Oluwaseyi89 marked this pull request as ready for review March 31, 2026 06:54
@greatest0fallt1me greatest0fallt1me merged commit 7b28638 into Streampay-Org:main Apr 1, 2026
1 check failed
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.

POST /api/v1/streams — create stream (persist + optional chain invoke)

2 participants