Repository navigation
feat: atomic proposal acceptance → contract creation flow - #256
Open
CodeNinjaStephen wants to merge 2 commits into
Open
CodeNinjaStephen wants to merge 2 commits into
CodeNinjaStephen wants to merge 2 commits into
Conversation
- Add scripts/012-proposals.sql: proposals table with UUID PKs, proposal_status enum, JSONB milestone_breakdown, and a partial unique index (WHERE status='accepted') enforcing one accepted proposal per project at the DB level - Add lib/proposals.ts: service layer with acceptProposal() running a 10-step atomic BEGIN/COMMIT/ROLLBACK transaction: validate proposal, verify client ownership, check project state, mark accepted, reject other proposals, create contract (status=pending, escrow_status=unfunded), back-reference proposal.contract_id, create milestone rows, advance project to in_progress, insert audit log - Add app/api/proposals/[id]/accept/route.ts: POST handler with withAuthCtx, UUID path validation, client/admin-only role guard, wallet→userId resolution, deterministic HTTP codes for all domain errors (400/401/403/404/409/422/500) - Add lib/validations/index.ts: AcceptProposalSchema, CreateProposalSchema, ProposalMilestoneSchema - Add __tests__/api/proposals.test.ts: 29 tests covering atomicity rollback, duplicate prevention, unauthorized access, project state validation, milestone creation, escrow init, concurrent race (unique constraint), and full success shape
|
@CodeNinjaStephen 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! 🚀 |
Collaborator
|
@CodeNinjaStephen build fails |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the full proposal acceptance → contract creation flow as an atomic database
transaction, ensuring no partial state is ever persisted if any step fails.
When a client accepts a freelancer's proposal, the system now:
All 8 steps run inside a single BEGIN/COMMIT/ROLLBACK — if anything fails, the entire
transaction rolls back.
───────────────────────────────────────────────────────────────────────────────────────────────
Changes
milestone_breakdown, and a partial unique index (WHERE status = 'accepted') enforcing one
accepted proposal per project at the DB level
errors (ProposalNotFoundError, ProposalAlreadyAcceptedError, ProjectNotActiveError,
UnauthorizedAcceptanceError, etc.)
client/admin-only role guard, and deterministic HTTP error codes
ProposalMilestoneSchema
───────────────────────────────────────────────────────────────────────────────────────────────
Testing
pnpm test tests/api/proposals.test.ts
29/29 passed
pnpm build
exit 0 — route compiled as ƒ /api/proposals/[id]/accept
Test coverage includes: happy path, milestone creation, duplicate acceptance prevention,
unauthorized freelancer access, non-active project rejection, transaction rollback on DB error,
concurrent race condition (unique constraint violation), and all HTTP error codes.
───────────────────────────────────────────────────────────────────────────────────────────────
Acceptance Criteria
closes #217