Skip to content

Implement POST /api/v1/streams with Zod validation and fix unimported references in streams router #185

Description

@greatest0fallt1me

Description

src/api/v1/streams.ts exposes GET /, GET /:id, GET /:id/accrual-preview, and PATCH /:id, but there is no POST / to create a stream — even though docs/ARCHITECTURE.md and the OpenAPI description advertise stream creation. The router also references AuditService (line 11), accrualService (line 47), and UpdateStreamParams (line 86) without importing them, so the file does not compile. This issue adds a validated creation endpoint and fixes the missing imports.

Requirements and context

  • Import AuditService from ../../services/auditService, accrualService from ../../services/accrualService, and UpdateStreamParams from ../../repositories/streamRepository.
  • Add a createStreamSchema to src/validation/schemas.ts (Zod) covering payer, recipient, ratePerSecond (positive decimal string), startTime, optional endTime, totalAmount, optional labels/offChainMemo.
  • Add POST / to streams.ts guarded by the existing validate(...) middleware, persisting via a new StreamRepository.create(...) (or db.insert) and returning 201 with the created stream including accruedEstimate.
  • Record an audit entry via AuditService on creation, consistent with auditActionEnum (stream_create).
  • Non-functional: reject invalid/extra fields with 400; do not trust client-supplied id, status, or timestamps for invariants.

Acceptance criteria

  • streams.ts imports resolve and the file compiles.
  • POST /api/v1/streams with a valid body returns 201 and the persisted stream.
  • Invalid bodies (missing/negative ratePerSecond, bad addresses) return 400 with Zod issues.
  • A stream_create audit log entry is written on success.
  • npm run build and npm test pass.
  • OpenAPI (src/api/v1/openapi.ts) documents the new endpoint.

Suggested execution

1. Fork the repo and create a branchgit checkout -b feature/create-stream-endpoint.
2. Implement changes — add the schema in src/validation/schemas.ts, the POST / handler in src/api/v1/streams.ts, and a repository create method.
3. Write/extend tests — this repo uses Jest + Supertest. Add cases to src/api/v1/streams.test.ts covering success (201), validation failure (400), and audit-log invocation using a mocked repository/service.
4. Test and commit

npm run lint -- --max-warnings 0
npm run build
npm test

Example commit message

feat(api): add validated POST /api/v1/streams and fix router imports

Guidelines

Target >=90% coverage on new handler/validation code (repo standard 95% per jest.config.js). Update README.md and the OpenAPI spec. Timeframe: 96 hours.

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions