Skip to content

Conversation

@aabrius
Copy link
Contributor

@aabrius aabrius commented Dec 7, 2025

Summary

  • Implements domain events (EntityCreated, EntityUpdated, EntityDeleted, UserLogin, UserLogout)
  • Adds AuditListener for handling events and creating audit logs
  • Implements AuditSubscriber for automatic TypeORM entity auditing
  • Captures actor info, IP, user agent, and request context
  • Adds 44 unit tests for events, listener, and subscriber

Test plan

  • Run npm test -- --testPathPattern="domain-events|audit.listener|audit.subscriber" to verify all tests pass
  • Verify audit logs are created on entity changes

🤖 Generated with Claude Code

aabrius and others added 2 commits December 6, 2025 22:16
- Add @nestjs/event-emitter for domain events
- Create domain events (EntityCreated, EntityUpdated, EntityDeleted, UserLogin, UserLogout)
- Add AuditListener to handle events and create audit logs
- Keep TypeORM subscriber for backwards compatibility
- Event-driven approach provides explicit dependencies and richer context

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add domain-events.spec.ts with 22 tests covering:
  - EntityCreatedEvent, EntityUpdatedEvent, EntityDeletedEvent
  - UserLoginEvent, UserLogoutEvent
  - RequestContext and ActorContext interfaces
- Add audit.listener.spec.ts with 13 tests covering:
  - Event handlers for all domain events
  - Audit log creation with proper transaction types
  - Error handling (non-throwing on failures)
- Add audit.subscriber.spec.ts with 9 tests covering:
  - TypeORM subscriber hooks (afterInsert, afterUpdate, afterRemove)
  - AuditLog entity skipping (prevents recursive auditing)
  - CLS context integration
- Add Jest moduleNameMapper for src/* path resolution

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Dec 7, 2025

Warning

Rate limit exceeded

@aabrius has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 28 minutes and 2 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 793cb77 and 4ab4ef1.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (10)
  • apps/backend/package.json (2 hunks)
  • apps/backend/src/app.module.ts (2 hunks)
  • apps/backend/src/events/domain-events.spec.ts (1 hunks)
  • apps/backend/src/events/domain-events.ts (1 hunks)
  • apps/backend/src/events/events.module.ts (1 hunks)
  • apps/backend/src/events/index.ts (1 hunks)
  • apps/backend/src/modules/audit/audit.listener.spec.ts (1 hunks)
  • apps/backend/src/modules/audit/audit.listener.ts (1 hunks)
  • apps/backend/src/modules/audit/audit.module.ts (1 hunks)
  • apps/backend/src/modules/audit/subscribers/audit.subscriber.spec.ts (1 hunks)
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/event-driven-audit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants