Skip to content

feat: make agreement chat production-ready (schema + participants) #86

Description

@Kalchaqui

Context

Nest already exposes JWT-protected chat endpoints:

  • GET /v1/agreements/:agreementId/messages
  • POST /v1/agreements/:agreementId/messages

Frontend will be wired to these in a companion FE issue. Before that can work in production, the backend schema and create-agreement path must support real A↔B chat.

Problem

  1. AgreementChatService inserts sender_id, but the FE SQL schema for agreement_messages (004-contacts-and-chat.sql) has no sender_id column → Nest insert will fail against current DB.
  2. On agreement create, if agreement_participants insert fails, we only console.error and continue → counterparty cannot access the agreement or chat (Not a participant).

Scope (keep tight)

  • Add SQL migration: agreement_messages.sender_id (UUID, preferably FK/auth_users.id; backfill nullable OK for old rows).
  • Document / add the migration under BE scripts/ (schema should live with the API that writes it).
  • Fail agreement create if participant insert fails (do not leave orphan agreements without participants).
  • Prefer mapping chat DB/validation errors to proper HTTP 4xx (not always 200 + { error }).

Out of scope

  • Frontend wiring (separate FE issue)
  • Realtime / WebSockets
  • Rate limiting / MaxLength (nice-to-have later)
  • Multi-wallet identity alignment (user_wallets vs auth_users.wallet_public_key)

Acceptance criteria

  1. Applying the migration allows Nest to insert a message with sender_id + sender_wallet.
  2. Creating an agreement always creates participant rows for both parties, or the create request fails.
  3. Only JWT users who are creator/participant can GET/POST messages.
  4. Manual check: User A creates agreement with User B’s wallet → B can list messages (empty) and A can send one → B sees it.

Related

  • Companion FE issue: wire AgreementChat to Nest + persist UUID (link after creation)
  • Existing Nest module: src/agreement-chat/

DoD

  • PR on main with migration + create harden
  • Short proof in PR (SQL applied + curl/Postman or integration test for messages)
  • Closes #NN

Metadata

Metadata

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions