Skip to content

feat(agreement-chat): Add chat system with participant tracking and a…#105

Open
SudiptaPaul-31 wants to merge 2 commits into
Thalos-Infrastructure:mainfrom
SudiptaPaul-31:fix-agreement-chat
Open

feat(agreement-chat): Add chat system with participant tracking and a…#105
SudiptaPaul-31 wants to merge 2 commits into
Thalos-Infrastructure:mainfrom
SudiptaPaul-31:fix-agreement-chat

Conversation

@SudiptaPaul-31

Copy link
Copy Markdown
Contributor

Summary

Implements production-ready agreement chat with sender_id support and enforces proper participant validation. Backend now correctly handles A↔B bidirectional messaging with database persistence and access control.

closes #86

Changes

1. SQL Migration: scripts/003_add_agreement_chat.sql

  • Added agreement_participants table with agreement_id FK, wallet_address, role, and profile_id FK
  • Added agreement_messages table with sender_id (UUID, FK to auth.users), sender_wallet, and message content
  • Added agreement_activity table for audit trail
  • Includes proper indexes on agreement_id, sender_id, created_at for performance
  • All tables have RLS policies enabled for security

2. Updated: src/agreements/agreements.service.ts

Before: If agreement_participants insert failed, we silently logged error and continued, leaving orphaned agreements
After: Now throws BadRequestException if participant creation fails, ensuring atomic agreement + participant creation

if (participantsError) {
  throw new BadRequestException(
    `Failed to create agreement participants: ${participantsError.message}`,
  );
}

3. Updated: src/agreement-chat/agreement-chat.service.ts

Before: Returned { message: null, error: string } tuples (always 200)

After: Throws proper NestJS exceptions:

  • BadRequestException (400) for database errors and validation failures
  • ForbiddenException (403) for unauthorized access (non-participants)
  • NotFoundException (404) for missing agreements

Ensures only JWT users who are creator/participant can access messages.

4. Updated: src/agreement-chat/agreement-chat.controller.ts

Made controller methods async to properly await and propagate exceptions. NestJS automatically converts thrown exceptions to appropriate HTTP status codes.

5. Updated: src/integration/migrated-flows.integration.spec.ts

Added 7 new integration tests verifying the production-ready chat:

  • ✓ Agreement participants always created or entire request fails
  • ✓ Creator can list messages (empty initially)
  • ✓ Non-participants are rejected with 403
  • ✓ Creator sends message → message stored with sender_id → participant receives it
  • ✓ Participant sends message → creator receives it
  • ✓ Empty messages rejected with 400
  • ✓ Wrong sender_wallet rejected with 403

Test Results: All 17 tests passing (10 existing + 7 new)

Acceptance Criteria

  • ✅ Applying migration allows Nest to insert message with sender_id + sender_wallet
  • ✅ Creating agreement always creates participant rows for both parties, or create request fails
  • ✅ Only JWT users who are creator/participant can GET/POST messages
  • ✅ Manual check verified: User A creates agreement with User B → B can list messages (empty) → A sends one → B sees it

Testing

npm run test:integration
# Result: Test Suites: 1 passed, Tests: 17 passed

@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

@SudiptaPaul-31 is attempting to deploy a commit to the ManuelJG's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

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

1 participant