Skip to content

refactor: extract publish helper and deduplicate RequestLike type#697

Open
kamilwronka wants to merge 1 commit intodevelopfrom
claude/trusting-wilson
Open

refactor: extract publish helper and deduplicate RequestLike type#697
kamilwronka wants to merge 1 commit intodevelopfrom
claude/trusting-wilson

Conversation

@kamilwronka
Copy link
Copy Markdown
Contributor

@kamilwronka kamilwronka commented Apr 7, 2026

Summary

  • EventEmitterService: Extracted a private publish() method to eliminate 6 identical try-catch blocks. Each public method now delegates to the shared helper, reducing boilerplate by ~30 lines while preserving identical behavior (same exchange, routing keys, and error logging).
  • nest-shared decorators: Exported RequestLike type from create-required-request-value.decorator.ts and imported it in create-required-unauthorized-request-value.decorator.ts instead of redefining the same type.

Safety

  • EventEmitterService: All 14 existing tests pass unchanged — the refactor only moves the try-catch into a private method with the same semantics. Error log messages now include the routing key name for better debugging.
  • RequestLike: Pure type-level change — no runtime behavior change. The type definition is identical in both files.

Touched files

  • apps/api/src/events/services/event-emitter.service.ts
  • packages/nest-shared/src/decorators/create-required-request-value.decorator.ts
  • packages/nest-shared/src/decorators/create-required-unauthorized-request-value.decorator.ts

Test plan

  • EventEmitterService unit tests pass (14/14)
  • Format check passes on changed files
  • Lint passes on changed files (only pre-existing warnings)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Improved internal code organization and error handling for better maintainability.

…te RequestLike type

- EventEmitterService: Extract private `publish()` method to eliminate 6 identical try-catch blocks
- nest-shared decorators: Export `RequestLike` type from source and import it instead of redefining

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fe34eaad-03a1-4e41-a49f-a9966bd9ee42

📥 Commits

Reviewing files that changed from the base of the PR and between f99033e and 50af7a3.

📒 Files selected for processing (3)
  • apps/api/src/events/services/event-emitter.service.ts
  • packages/nest-shared/src/decorators/create-required-request-value.decorator.ts
  • packages/nest-shared/src/decorators/create-required-unauthorized-request-value.decorator.ts

📝 Walkthrough

Walkthrough

Refactored EventEmitterService to centralize AMQP publishing logic into a single private publish() helper method, consolidating error handling across six public emitter methods. Separately, the RequestLike type is exported from one decorator and imported into another to eliminate duplication.

Changes

Cohort / File(s) Summary
EventEmitterService Refactoring
apps/api/src/events/services/event-emitter.service.ts
Introduced private publish(routingKey, payload) helper method. Refactored emitMapStatusUpdate, emitHeroKilled, emitRankingUpdate, emitRespawnWindowOpened, emitRespawnWindowClosed, and emitTimerUpdate to delegate to this helper. Consolidated error handling with generic error message pattern.
RequestLike Type Sharing
packages/nest-shared/src/decorators/create-required-request-value.decorator.ts, packages/nest-shared/src/decorators/create-required-unauthorized-request-value.decorator.ts
Exported RequestLike type from create-required-request-value.decorator.ts; removed local definition from create-required-unauthorized-request-value.decorator.ts and imported from the source file instead.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

A rabbit hops through logic clean, 🐰
Where duplication once had been.
Now helpers share the common way,
Less code to reason through each day! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the two main refactoring objectives: extracting a publish helper in EventEmitterService and deduplicating the RequestLike type across decorator files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/trusting-wilson

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant