Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Rename "Subscription" to "EntitySubscription" #8809

Merged
merged 6 commits into from
Feb 28, 2025

Conversation

rahul-rocket
Copy link
Collaborator

@rahul-rocket rahul-rocket commented Feb 28, 2025

PR

Please note: we will close your PR without comment if you do not check the boxes above and provide ALL requested information.


Summary by CodeRabbit

  • New Features

    • Introduced enhanced entity subscription management, now clearly aligned with employee and organizational data.
    • Added new endpoints and data validation to improve subscription-related interactions.
  • Refactor

    • Renamed and restructured the subscription system to “entity subscription” for improved clarity and consistency.
    • Consolidated event handling and command processing to streamline subscription operations.
    • Updated imports and service dependencies to reflect the new entity subscription model.
  • Bug Fixes

    • Addressed issues related to subscription event handling and data integrity.
  • Chores

    • Removed deprecated subscription-related files and classes to clean up the codebase.

Copy link
Contributor

coderabbitai bot commented Feb 28, 2025

Warning

Rate limit exceeded

@rahul-rocket has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 24 minutes and 32 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 6620447 and cbd1a57.

📒 Files selected for processing (1)
  • packages/core/src/lib/entity-subscription/entity-subscription.controller.ts (1 hunks)

Walkthrough

This pull request refactors the subscription-related functionality by replacing the legacy "Subscription" model with the new "EntitySubscription" model. The changes include renaming exports, modules, controllers, services, commands, events, handlers, DTOs, and repositories. Legacy subscription files have been removed and replaced with new implementations that adopt updated naming conventions and adjusted parameters (e.g., replacing userId with employeeId), ensuring a more specific and consistent approach to handling entity subscriptions across the codebase.

Changes

File(s) Change Summary
packages/contracts/src/index.ts, .../lib/entity-subscription.model.ts, .../lib/subscription.model.ts Contracts & Models: Removed export of subscription.model and added entity-subscription.model; introduced new interfaces and enums while deleting legacy subscriptions.
packages/core/src/lib/app/app.module.ts, .../seeder.module.ts, .../mention/mention.module.ts Module Import Updates: Replaced SubscriptionModule with EntitySubscriptionModule in module imports and dependency arrays.
packages/core/src/lib/core/entities/index.ts, .../core/entities/internal.ts, .../entity-subscription/entity-subscription.controller.ts, .../entity-subscription/entity-subscription.entity.ts, .../entity-subscription/entity-subscription.service.ts Controller, Service & Entity Updates: Renamed entities from Subscription to EntitySubscription, updated core exports, and refactored controller routes and service dependencies accordingly.
packages/core/src/lib/entity-subscription/commands/*, .../entity-subscription/events/*, .../entity-subscription/commands/handlers/*, .../entity-subscription/events/handlers/* Command, Event & Handler Updates: Renamed commands, events, and handlers from Subscription* to EntitySubscription*; added new command handler and updated event payloads (e.g., using employeeId instead of userId).
packages/core/src/lib/entity-subscription/dto/*, .../entity-subscription/repository/mikro-orm-entity-subscription.repository.ts, .../entity-subscription/repository/type-orm-entity-subscription.repository.ts DTO & Repository Additions: Introduced new DTOs for creating and querying entity subscriptions along with new repository implementations for MikroORM and TypeORM.
packages/core/src/lib/comment/comment.service.ts, .../organization-project/organization-project.service.ts, .../organization-sprint/organization-sprint.service.ts, .../organization-team-employee/organization-team-employee.service.ts, .../organization-team/organization-team.service.ts, .../mention/mention.service.ts, packages/core/src/lib/tasks/* Service Logic Updates: Updated multiple domain services to incorporate the new EntitySubscriptionService and adjust event publishing (renaming events and replacing userId with employeeId).
packages/core/src/lib/subscription/* Legacy File Deletions: Removed all legacy Subscription files including models, DTOs, commands, events, repositories, and modules.
packages/core/src/lib/tasks/commands/handlers/*, .../screening-tasks/screening-tasks.service.ts, .../task.service.ts Task Handlers & Events Updates: Revised task-related subscription logic to use updated event names and parameters for entity subscriptions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller as EntitySubscriptionController
    participant Service as EntitySubscriptionService
    participant CommandHandler as EntitySubscriptionCreateHandler
    participant Repository as EntitySubscriptionRepository

    Client->>Controller: POST /entity-subscription (Create DTO)
    Controller->>Service: createEntitySubscription(dto)
    Service->>CommandHandler: execute(EntitySubscriptionCreateCommand)
    CommandHandler->>Service: invoke create() with employeeId, organizationId
    Service->>Repository: Save new EntitySubscription
    Repository-->>Service: Return saved entity
    Service-->>Controller: Return success response
    Controller-->>Client: 201 Created (EntitySubscription details)
Loading

Possibly related PRs

  • [Fix] Comment entity employee based #8769: The changes in the main PR, which involve the transition from subscription.model to entity-subscription.model, are related to the modifications in the retrieved PR that also focus on transitioning from user-based identifiers to employee-based identifiers in various models, indicating a broader shift in how entities are managed across the codebase.
  • [Feat] Subscribe user on assignment / Un-assignment #8574: The changes in the main PR, which involve the reorganization of subscription-related exports and the introduction of a new entity subscription model, are related to the retrieved PR that enhances subscription management in the OrganizationProjectService and other services by integrating event-driven capabilities and updating subscription handling logic. Both PRs focus on transitioning from a general subscription model to a more specific entity-based subscription approach.

Poem

I hopped through lines of refactored code,
Changing names on every road.
Subscriptions old took their final bow,
Entity Subscriptions now lead the show.
With carrots and clean code, I cheer aloud! 🥕


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (8)
packages/core/src/lib/entity-subscription/commands/handlers/entity-subscription.create.handler.ts (1)

1-15: Consider renaming variable to match entity name.

The handler implementation is correct, but for consistency with the refactoring effort, consider renaming the injected service variable from subscriptionService to entitySubscriptionService to fully reflect the new naming convention.

-	constructor(private readonly subscriptionService: EntitySubscriptionService) {}
+	constructor(private readonly entitySubscriptionService: EntitySubscriptionService) {}

-		return await this.subscriptionService.create(input);
+		return await this.entitySubscriptionService.create(input);
packages/core/src/lib/organization-team/organization-team.service.ts (1)

287-287: Update error message to reflect new entity name

The error message still references the old "CreateSubscriptionEvent" name which should be updated for consistency.

-console.error('Error publishing CreateSubscriptionEvent:', error);
+console.error('Error publishing CreateEntitySubscriptionEvent:', error);
packages/core/src/lib/tasks/task.service.ts (1)

210-210: Update error message to reflect new entity name

The error message still references the old "CreateSubscriptionEvent" name which should be updated for consistency.

-console.error('Error publishing CreateSubscriptionEvent:', error);
+console.error('Error publishing CreateEntitySubscriptionEvent:', error);
packages/core/src/lib/organization-project/organization-project.service.ts (1)

131-140: Consider more robust error handling for subscription creation.
This logic correctly differentiates between CREATED_ENTITY and ASSIGNMENT, but the try/catch block only logs errors without rethrowing or handling them gracefully.

packages/core/src/lib/organization-team-employee/organization-team-employee.service.ts (2)

309-309: Wrap task unassignment in a try/catch for reliability.
If _taskService.unassignEmployeeFromTeamTasks fails, it may leave inconsistent data.


339-339: Same suggestion for unassigning tasks here.
Consider adding a try/catch or logging block to ensure errors are surfaced properly.

packages/core/src/lib/organization-sprint/organization-sprint.service.ts (1)

125-132: Subscription event dispatch logic is sound but consider more explicit error handling.
The code checks manager vs. member subscriptions, but the catch block is empty. You might wish to log or rethrow.

packages/core/src/lib/entity-subscription/entity-subscription.controller.ts (1)

18-23: Constructor injection of EntitySubscriptionService and CommandBus is coherent.
Maintains consistent CQRS approach for creating subscriptions via commands.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 590cf1c and 34cd9f4.

📒 Files selected for processing (47)
  • packages/contracts/src/index.ts (1 hunks)
  • packages/contracts/src/lib/entity-subscription.model.ts (1 hunks)
  • packages/contracts/src/lib/subscription.model.ts (0 hunks)
  • packages/core/src/lib/app/app.module.ts (2 hunks)
  • packages/core/src/lib/comment/comment.service.ts (2 hunks)
  • packages/core/src/lib/core/entities/index.ts (2 hunks)
  • packages/core/src/lib/core/entities/internal.ts (1 hunks)
  • packages/core/src/lib/core/seeds/seeder.module.ts (2 hunks)
  • packages/core/src/lib/entity-subscription/commands/entity-subscription.create.command.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/commands/handlers/entity-subscription.create.handler.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/commands/handlers/index.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/commands/index.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/dto/create-entity-subscription.dto.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/dto/entity-subscription-find-input.dto.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/dto/index.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/entity-subscription.controller.ts (5 hunks)
  • packages/core/src/lib/entity-subscription/entity-subscription.entity.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/entity-subscription.module.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/entity-subscription.service.ts (5 hunks)
  • packages/core/src/lib/entity-subscription/events/entity-subscription.create.event.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/events/handlers/entity-subscription.create.handler.ts (2 hunks)
  • packages/core/src/lib/entity-subscription/events/handlers/index.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/events/index.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/repository/mikro-orm-entity-subscription.repository.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/repository/type-orm-entity-subscription.repository.ts (1 hunks)
  • packages/core/src/lib/mention/mention.module.ts (2 hunks)
  • packages/core/src/lib/mention/mention.service.ts (2 hunks)
  • packages/core/src/lib/organization-project/organization-project.service.ts (6 hunks)
  • packages/core/src/lib/organization-sprint/organization-sprint.service.ts (7 hunks)
  • packages/core/src/lib/organization-team-employee/organization-team-employee.service.ts (6 hunks)
  • packages/core/src/lib/organization-team/organization-team.service.ts (3 hunks)
  • packages/core/src/lib/subscription/commands/handlers/index.ts (0 hunks)
  • packages/core/src/lib/subscription/commands/handlers/subscription.create.handler.ts (0 hunks)
  • packages/core/src/lib/subscription/commands/index.ts (0 hunks)
  • packages/core/src/lib/subscription/dto/create-subscription.dto.ts (0 hunks)
  • packages/core/src/lib/subscription/dto/index.ts (0 hunks)
  • packages/core/src/lib/subscription/dto/subscription-find-input.dto.ts (0 hunks)
  • packages/core/src/lib/subscription/events/handlers/index.ts (0 hunks)
  • packages/core/src/lib/subscription/events/index.ts (0 hunks)
  • packages/core/src/lib/subscription/repository/mikro-orm-subscription.repository.ts (0 hunks)
  • packages/core/src/lib/subscription/repository/type-orm-subscription.repository.ts (0 hunks)
  • packages/core/src/lib/subscription/subscription.entity.ts (0 hunks)
  • packages/core/src/lib/subscription/subscription.module.ts (0 hunks)
  • packages/core/src/lib/tasks/commands/handlers/automation-task.sync.handler.ts (7 hunks)
  • packages/core/src/lib/tasks/commands/handlers/task-create.handler.ts (3 hunks)
  • packages/core/src/lib/tasks/screening-tasks/screening-tasks.service.ts (3 hunks)
  • packages/core/src/lib/tasks/task.service.ts (5 hunks)
💤 Files with no reviewable changes (13)
  • packages/core/src/lib/subscription/events/index.ts
  • packages/core/src/lib/subscription/commands/handlers/index.ts
  • packages/core/src/lib/subscription/events/handlers/index.ts
  • packages/core/src/lib/subscription/repository/mikro-orm-subscription.repository.ts
  • packages/core/src/lib/subscription/dto/subscription-find-input.dto.ts
  • packages/core/src/lib/subscription/subscription.entity.ts
  • packages/core/src/lib/subscription/dto/create-subscription.dto.ts
  • packages/core/src/lib/subscription/dto/index.ts
  • packages/contracts/src/lib/subscription.model.ts
  • packages/core/src/lib/subscription/subscription.module.ts
  • packages/core/src/lib/subscription/commands/index.ts
  • packages/core/src/lib/subscription/commands/handlers/subscription.create.handler.ts
  • packages/core/src/lib/subscription/repository/type-orm-subscription.repository.ts
✅ Files skipped from review due to trivial changes (8)
  • packages/core/src/lib/entity-subscription/events/index.ts
  • packages/core/src/lib/entity-subscription/commands/handlers/index.ts
  • packages/core/src/lib/entity-subscription/events/entity-subscription.create.event.ts
  • packages/core/src/lib/entity-subscription/commands/entity-subscription.create.command.ts
  • packages/core/src/lib/entity-subscription/dto/index.ts
  • packages/core/src/lib/core/entities/index.ts
  • packages/core/src/lib/entity-subscription/commands/index.ts
  • packages/core/src/lib/entity-subscription/events/handlers/index.ts
🧰 Additional context used
🧠 Learnings (1)
packages/core/src/lib/tasks/screening-tasks/screening-tasks.service.ts (1)
Learnt from: rahul-rocket
PR: ever-co/ever-gauzy#8800
File: packages/core/src/lib/tasks/screening-tasks/screening-tasks.service.ts:81-81
Timestamp: 2025-02-24T05:25:58.665Z
Learning: The `creatorId` column in the `screening-task` entity will be renamed to `createdByUserId` in a future PR to maintain consistency with the task entity.
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: build
  • GitHub Check: test
🔇 Additional comments (72)
packages/core/src/lib/entity-subscription/repository/mikro-orm-entity-subscription.repository.ts (1)

1-4: Repository implementation looks good!

The MikroOrmEntitySubscriptionRepository class correctly extends the base repository with the EntitySubscription type. This follows the repository pattern used elsewhere in the codebase.

packages/core/src/lib/mention/mention.module.ts (1)

7-7: Dependency updated properly

The module dependency has been correctly updated from SubscriptionModule to EntitySubscriptionModule as part of the renaming refactor.

Also applies to: 21-21

packages/core/src/lib/core/entities/internal.ts (1)

134-134: Export correctly updated

The export for the entity subscription has been properly updated to use the new path and entity name.

packages/core/src/lib/entity-subscription/dto/entity-subscription-find-input.dto.ts (1)

1-7: DTO implementation follows best practices

The DTO correctly:

  1. Extends PartialType(EntitySubscription) to make all entity properties optional
  2. Implements the contract interface IEntitySubscriptionFindInput
  3. Follows NestJS conventions for DTOs

This approach ensures type safety while maintaining compatibility with the entity structure.

packages/core/src/lib/entity-subscription/dto/create-entity-subscription.dto.ts (1)

1-22: Class structure looks good with proper implementation of the interface.

The DTO extends TenantOrganizationBaseDTO and implements IEntitySubscriptionCreateInput correctly. All required properties are defined with appropriate types, and optional properties are properly marked with ?.

packages/core/src/lib/entity-subscription/repository/type-orm-entity-subscription.repository.ts (1)

1-11: Repository implementation follows TypeORM best practices.

The class correctly extends the TypeORM Repository and uses proper dependency injection. The constructor appropriately initializes the parent class with the repository target, manager, and queryRunner.

packages/core/src/lib/entity-subscription/entity-subscription.module.ts (1)

1-25: Module configuration is correct and follows NestJS best practices.

The module is properly marked as @global() and includes all necessary imports and providers. The module exports the service and repository for use in other modules, which maintains compatibility with the previous subscription module structure.

packages/core/src/lib/app/app.module.ts (2)

160-160: Import statement correctly references the new EntitySubscriptionModule.

The import has been updated from SubscriptionModule to EntitySubscriptionModule, which aligns with the refactoring efforts.


472-472: Module registration correctly uses EntitySubscriptionModule.

The module reference has been properly updated in the imports array from SubscriptionModule to EntitySubscriptionModule.

packages/core/src/lib/tasks/screening-tasks/screening-tasks.service.ts (3)

6-7: All imports updated correctly for the refactoring

The import of EntitySubscriptionTypeEnum replaces the former SubscriptionTypeEnum as part of the subscription model refactoring.


21-21: Import path updated properly

Import statement updated from CreateSubscriptionEvent to CreateEntitySubscriptionEvent, correctly reflecting the renamed entity.


110-114: Subscription event creation updated with improved semantics

The event creation has been updated to use:

  1. CreateEntitySubscriptionEvent instead of CreateSubscriptionEvent
  2. employeeId: user?.employeeId instead of userId: user?.id
  3. EntitySubscriptionTypeEnum.CREATED_ENTITY instead of SubscriptionTypeEnum.CREATED_ENTITY

These changes are consistent with the refactoring and provide better semantic clarity by using employee-specific identifiers.

packages/contracts/src/lib/entity-subscription.model.ts (1)

1-19: Well-structured new EntitySubscription model

The newly introduced model properly replaces the old Subscription model with:

  • Clear interface definitions that extend appropriate base interfaces
  • A well-defined enum with all the required subscription types
  • Consistent naming conventions that match the refactoring goals

The model maintains the same functionality while providing more specific and contextual naming.

packages/core/src/lib/core/seeds/seeder.module.ts (2)

10-10: Module import updated correctly

The import statement has been updated from SubscriptionModule to EntitySubscriptionModule, correctly reflecting the renamed module.


45-45: Module usage updated in imports array

The module reference in the imports array has been updated from SubscriptionModule to EntitySubscriptionModule, ensuring the seeder uses the renamed module.

packages/core/src/lib/comment/comment.service.ts (3)

5-7: Import updated correctly for the refactoring

The import of EntitySubscriptionTypeEnum replaces the former SubscriptionTypeEnum as part of the subscription model refactoring.


14-14: Import path updated properly

Import statement updated from CreateSubscriptionEvent to CreateEntitySubscriptionEvent, correctly reflecting the renamed entity.


86-93: Subscription event creation updated with improved semantics

The event creation has been updated to use:

  1. CreateEntitySubscriptionEvent instead of CreateSubscriptionEvent
  2. Explicit employeeId parameter (which was likely userId before)
  3. EntitySubscriptionTypeEnum.COMMENT instead of SubscriptionTypeEnum.COMMENT

These changes provide better semantic clarity by using employee-specific identifiers and follow the refactoring pattern consistently.

packages/contracts/src/index.ts (1)

128-128: Correctly added export for the new entity-subscription model.

The addition of the entity-subscription model export aligns with the renaming refactor from "Subscription" to "EntitySubscription" while maintaining the alphabetical ordering of exports.

packages/core/src/lib/entity-subscription/entity-subscription.entity.ts (1)

1-58: Well-structured entity implementation.

This entity implementation is thorough with proper:

  • ORM decorations for both TypeORM and MikroORM
  • Validation using class-validator
  • Clear comments explaining each property
  • Correct relationship mapping with the Employee entity
  • Appropriate indexing for performance optimization

The refactoring from Subscription to EntitySubscription is well-executed in this file.

packages/core/src/lib/mention/mention.service.ts (1)

10-10: Correctly updated imports and event references.

All Subscription references have been properly updated to EntitySubscription in both imports and usage. The event publishing code now correctly uses the new EntitySubscriptionTypeEnum and CreateEntitySubscriptionEvent.

Also applies to: 16-16, 71-77

packages/core/src/lib/tasks/commands/handlers/task-create.handler.ts (4)

11-12: Properly updated import for EntitySubscriptionTypeEnum

The imports have been correctly updated to use the new EntitySubscriptionTypeEnum which replaces the previous SubscriptionTypeEnum.


20-20: Correctly updated import path for CreateEntitySubscriptionEvent

The import path has been properly changed from the old subscription module to the new entity-subscription module.


138-145: Successfully migrated from CreateSubscriptionEvent to CreateEntitySubscriptionEvent

The event creation has been correctly updated to use the new EntitySubscriptionTypeEnum.CREATED_ENTITY for the subscription type.


164-171: Properly refactored subscription event for assignees

The code now correctly uses:

  • CreateEntitySubscriptionEvent instead of CreateSubscriptionEvent
  • employeeId parameter (which was already in use)
  • EntitySubscriptionTypeEnum.ASSIGNMENT enum value

This maintains the same functionality while using the new entity-subscription pattern.

packages/core/src/lib/organization-team/organization-team.service.ts (3)

24-25: Correctly added IEmployee and EntitySubscriptionTypeEnum imports

The imports have been properly added for the interfaces and enums needed in the refactored code.


42-42: Updated import path for CreateEntitySubscriptionEvent

The import has been correctly changed from the subscription module to the entity-subscription module.


270-284: Properly refactored subscription event creation for team members

The changes correctly:

  • Use IEmployee interface instead of destructuring
  • Use employee.id for assigning the employeeId parameter
  • Use appropriate EntitySubscriptionTypeEnum values based on whether the employee is the creator
packages/core/src/lib/entity-subscription/events/handlers/entity-subscription.create.handler.ts (4)

4-5: Updated import paths for entity subscription events and commands

The imports have been correctly updated to reflect the new module structure and naming convention.


7-8: Properly updated EventsHandler decorator and class implementation

The class definition has been correctly updated to handle CreateEntitySubscriptionEvent.


17-21: Updated method signature and documentation

The method signature and JSDoc comments have been properly updated to reflect the new event type.


24-36: Successfully migrated from userId to employeeId

The code now correctly:

  • Extracts employeeId instead of userId from the event input
  • Uses EntitySubscriptionCreateCommand instead of SubscriptionCreateCommand
  • Passes employeeId instead of userId to the command

This change properly aligns with the entity-specific subscription model.

packages/core/src/lib/tasks/task.service.ts (6)

29-29: Successfully imported EntitySubscriptionTypeEnum

The import has been correctly updated to use the new EntitySubscriptionTypeEnum.


41-41: Updated import for EntitySubscriptionService

The import has been properly changed to use the new EntitySubscriptionService.


45-45: Updated import path for CreateEntitySubscriptionEvent

The import path has been correctly changed to the new entity-subscription module.


61-61: Renamed service property to _entitySubscriptionService

The dependency injection property has been correctly renamed from _subscriptionService to _entitySubscriptionService.


164-169: Updated unsubscribe logic to use EntitySubscriptionService

The code now correctly:

  • Uses _entitySubscriptionService.delete method
  • Uses employeeId parameter instead of userId
  • Uses EntitySubscriptionTypeEnum.ASSIGNMENT

183-191: Updated subscription event creation

The code now correctly uses CreateEntitySubscriptionEvent with the appropriate parameters and EntitySubscriptionTypeEnum.

packages/core/src/lib/organization-project/organization-project.service.ts (3)

18-18: No issues with introducing EntitySubscriptionTypeEnum.
This enum replacement is consistent with the broader subscription refactor.


29-30: New imports for entity subscription event handling look good.
The references to CreateEntitySubscriptionEvent and EntitySubscriptionService are correctly aligned with the new subscription design.


50-50: Service injection update is consistent with the refactor.
Replacing _subscriptionService with _entitySubscriptionService maintains clarity for entity-based subscriptions. No concerns here.

packages/core/src/lib/organization-team-employee/organization-team-employee.service.ts (4)

6-6: EntitySubscriptionTypeEnum import is aligned with the subscription refactor.
No issues spotted.


13-13: No concerns regarding RolesEnum usage.
This enum usage is consistent with the rest of the codebase.


20-21: New event and service imports properly replace the old subscription references.
This ensures consistency with the renamed subscription logic.


31-32: Injected _taskService and _entitySubscriptionService are valid additions.
They unify task unassignment logic and manage entity subscriptions, respectively.

packages/core/src/lib/organization-sprint/organization-sprint.service.ts (4)

13-13: EntitySubscriptionTypeEnum is properly introduced.
This aligns well with the new subscription model.


21-22: Replacing the old subscription imports with CreateEntitySubscriptionEvent and EntitySubscriptionService is correct.
The new approach matches your entity-based subscription refactor.


142-142: Internal activity log injection _activityLogService looks fine.
No issues identified.


207-207: Another activity log usage consistent with your approach.
No further concerns here.

packages/core/src/lib/entity-subscription/entity-subscription.service.ts (6)

2-2: Importing DeleteResult is a beneficial step for typed delete operations.
This enhances clarity when performing subscription deletions.


12-13: Repositories and entity imports align with the transition to EntitySubscription.
The new repos are logically consistent with your new naming and structure.

Also applies to: 14-14


16-16: Refactor to EntitySubscriptionService highlights the new domain-driven approach.
Clear naming better reflects the service’s purpose.


18-20: Constructor injection of repositories and call to super is correct.
This ensures the base TenantAwareCrudService functionalities remain intact.

Also applies to: 21-21


31-64: Creating subscriptions with employeeId and organizationId is a solid approach.
The fallback to context-based tenant and employee data looks consistent, but watch out for calls that omit organizationId.


81-105: unsubscribe method logic is cleanly adapted to the new approach.
Again, be mindful that upstream calls should pass organizationId to match the filter if the subscription was created that way.

packages/core/src/lib/tasks/commands/handlers/automation-task.sync.handler.ts (10)

14-15: Renaming to EntitySubscriptionTypeEnum & IEmployee import looks appropriate.
No functional issues spotted here; aligns with the broader rename to entity-based subscriptions.


19-20: Imports from entity-subscription events and service are consistent.
Please verify that any references to the old subscription event/service are fully replaced throughout the codebase.


24-24: TaskService import is valid.
No concerns here; usage seems standard.


33-35: Dependency injection for repositories appears correct.
Matches the custom repositories' declarations and usage.


40-40: Updated subscription service reference is clear.
Dependency name reflects the new entity-based subscription management.


54-54: Nullish coalescing operator is a good choice.
This simplifies the tenant ID fallback logic nicely.


153-157: Publishing the CreateEntitySubscriptionEvent for CREATED_ENTITY is effective.
This aligns with the updated subscription pattern. Double-check if multiple creation events are not triggered unintentionally in edge cases.


173-179: Assigning tasks to employees via subscription events is consistent.
Ensures proper subscription type (ASSIGNMENT) is set. Great approach to keep each member in sync.


264-269: Deleting entity subscriptions for removed task members is well-structured.
Implementation correctly unsubscribes those who are no longer assigned.


281-287: New subscriptions for newly assigned team members look correct.
Consider verifying in tests that duplicates aren’t created for employees who were already on the task.

packages/core/src/lib/entity-subscription/entity-subscription.controller.ts (7)

9-12: New imports for EntitySubscription and related DTOs are aligned with rename.
No issues observed with the updated references.


14-17: API tags and controller path renamed to 'EntitySubscriptions' and '/entity-subscription'.
Ensure that any client-side references to the old route or tags are updated.


31-31: Response type updated to EntitySubscription in metadata.
Properly reflects the new entity type.


39-41: findAll with entitySubscriptionService is correct.
The usage of pagination params is aligned with the Crud approach.


56-58: findById references the new method signature.
No obvious issues; ensures typed validations remain in place.


73-75: create method uses EntitySubscriptionCreateCommand.
Promotes consistent usage of the new entity-based model.


91-93: delete method now unsubscribes from entity subscriptions.
Functional flow is straightforward; removing subscription data is logically handled by the service.

Copy link

nx-cloud bot commented Feb 28, 2025

View your CI Pipeline Execution ↗ for commit cbd1a57.

Command Status Duration Result
nx build desktop --base-href ./ ✅ Succeeded 1m 46s View ↗
nx build desktop-api --output-path=dist/apps/de... ✅ Succeeded 27s View ↗
nx run api:desktop-api ✅ Succeeded 1m 15s View ↗
nx build gauzy -c=production --prod --verbose ✅ Succeeded 3m 53s View ↗
nx run gauzy:desktop-ui --base-href ./ ✅ Succeeded 3m 26s View ↗
nx build api -c=production --prod ✅ Succeeded 1m 8s View ↗
nx build desktop-ui-lib --configuration=develop... ✅ Succeeded 29s View ↗
nx build desktop-ui-lib --configuration=production ✅ Succeeded 28s View ↗
Additional runs (56) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-02-28 08:41:14 UTC

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (6)
packages/core/src/lib/entity-subscription/dto/create-entity-subscription.dto.ts (1)

1-14: Looks great – consider adding validation decorators.

Everything looks correct, and the usage of IntersectionType with PickType is a succinct approach to constructing your DTO. If any fields (e.g., entityId) require strict formats such as UUID, consider applying class-validator decorators (like IsUUID(), IsString(), etc.) to ensure robust input validation.

packages/core/src/lib/entity-subscription/dto/entity-subscription-find-input.dto.ts (1)

1-11: All set – consider stricter validations if needed.

The usage of IntersectionType and PartialType is correct for building flexible query criteria. If you anticipate needing more robust input validation (e.g., verifying UUID formats in partial fields), consider adding class-validator decorators for the optional properties.

packages/core/src/lib/entity-subscription/entity-subscription.service.ts (2)

60-61: Use a logging system instead of console.log for error tracking.

Relying on console.log makes it harder to centralize or filter logs. Consider using NestJS's built-in logger or a dedicated logging library for better traceability and log management.


96-98: Fix minor grammatical error in throw message.

Use “Failed to unsubscribe employee from entity” or similar.

Apply this diff to correct the grammar:

- throw new BadRequestException('Failed to unsubscribing employee from entity', error);
+ throw new BadRequestException('Failed to unsubscribe employee from entity', error);
packages/core/src/lib/entity-subscription/entity-subscription.controller.ts (1)

151-159: Address the spelling to satisfy cspell checks.

The pipeline is flagging “unsubscription” as an unknown word. You can either add it to your project's cspell dictionary or replace it with an alternative (e.g., “subscription cancellation” or “unsubscribe operation”) to pass the spelling checks.

Consider the following diff to rewrite relevant descriptions:

- description: 'Optional filters to locate the subscription for unsubscription.'
+ description: 'Optional filters to locate the subscription for cancellation.'
- description: 'Unsubscription request accepted.'
+ description: 'Unsubscribe request accepted.'
🧰 Tools
🪛 GitHub Check: Cspell

[warning] 152-152:
Unknown word (unsubscription)


[warning] 157-157:
Unknown word (Unsubscription)

🪛 GitHub Actions: Check Spelling and Typos with cspell

[warning] 152-152: Unknown word (unsubscription)


[warning] 157-157: Unknown word (Unsubscription)

packages/core/src/lib/database/migrations/1740723269734-AlterSubscriptionEntityTable.ts (1)

28-28: Use the standard “new Error” constructor.

Throwing errors without the new keyword can be confusing and inconsistent with typical JS best practices.

- throw Error(`Unsupported database: ${queryRunner.connection.options.type}`);
+ throw new Error(`Unsupported database: ${queryRunner.connection.options.type}`);

Also applies to: 50-50

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 34cd9f4 and afd76c2.

📒 Files selected for processing (7)
  • packages/core/src/lib/database/migrations/1740723269734-AlterSubscriptionEntityTable.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/dto/create-entity-subscription.dto.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/dto/entity-subscription-find-input.dto.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/entity-subscription.controller.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/entity-subscription.entity.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/entity-subscription.service.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/events/handlers/entity-subscription.create.handler.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/core/src/lib/entity-subscription/events/handlers/entity-subscription.create.handler.ts
  • packages/core/src/lib/entity-subscription/entity-subscription.entity.ts
🧰 Additional context used
🪛 GitHub Check: Cspell
packages/core/src/lib/entity-subscription/entity-subscription.controller.ts

[warning] 152-152:
Unknown word (unsubscription)


[warning] 157-157:
Unknown word (Unsubscription)

🪛 GitHub Actions: Check Spelling and Typos with cspell
packages/core/src/lib/entity-subscription/entity-subscription.controller.ts

[warning] 152-152: Unknown word (unsubscription)


[warning] 157-157: Unknown word (Unsubscription)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: build
🔇 Additional comments (2)
packages/core/src/lib/entity-subscription/entity-subscription.controller.ts (1)

1-150: Code looks solid overall.

Your controller methods align well with standard NestJS CRUD patterns, with appropriate guards, input validation, and Swagger annotations. Great job on the thorough inline documentation and typed query/DTO usages.

Also applies to: 160-172

packages/core/src/lib/database/migrations/1740723269734-AlterSubscriptionEntityTable.ts (1)

1-27: No major issues identified.

Your migration properly handles PostgreSQL, MySQL, and SQLite paths. The usage of raw queries, index drops, constraint modifications, and table renaming appears consistent with TypeORM migrations. The console log provides helpful status feedback.

Also applies to: 29-49, 51-336

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/core/src/lib/organization-team-employee/organization-team-employee.service.ts (1)

92-93: Fix inaccurate error log message.

The error message mentions "subscribing" but this code block is handling unsubscription operations.

-				console.error('Error subscribing new team members:', error);
+				console.error('Error unsubscribing team members:', error);
packages/core/src/lib/tasks/commands/handlers/automation-task.sync.handler.ts (1)

275-276: Fix inaccurate error log message.

The error message mentions "subscribing" but this code block is handling unsubscription operations.

-				console.error('Error subscribing new members to the task:', error);
+				console.error('Error unsubscribing members from the task:', error);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between afd76c2 and e858af4.

📒 Files selected for processing (5)
  • packages/core/src/lib/organization-project/organization-project.service.ts (6 hunks)
  • packages/core/src/lib/organization-sprint/organization-sprint.service.ts (7 hunks)
  • packages/core/src/lib/organization-team-employee/organization-team-employee.service.ts (6 hunks)
  • packages/core/src/lib/tasks/commands/handlers/automation-task.sync.handler.ts (7 hunks)
  • packages/core/src/lib/tasks/task.service.ts (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/core/src/lib/organization-sprint/organization-sprint.service.ts
  • packages/core/src/lib/organization-project/organization-project.service.ts
  • packages/core/src/lib/tasks/task.service.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: build
🔇 Additional comments (2)
packages/core/src/lib/organization-team-employee/organization-team-employee.service.ts (1)

81-88: Changes successfully address previous review concern.

The code now correctly passes both organizationId and tenantId parameters when deleting entity subscriptions, which addresses the previous review comment about ensuring organizationId is provided.

packages/core/src/lib/tasks/commands/handlers/automation-task.sync.handler.ts (1)

54-54: Verify nullish coalescing operator behavior change.

The change from || to ?? operator alters how falsy values are handled. The ?? operator will only use input.tenantId when RequestContext.currentTenantId() is null or undefined, not for other falsy values like 0 or empty string.

Make sure this behavior change is intentional and doesn't break existing functionality where falsy (but not null/undefined) tenant IDs might be valid.

- Added migrations to rename the "subscription" table to "entity_subscription" across Postgres, SQLite, and MySQL.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/core/src/lib/database/migrations/1740727466186-RenameOldSubscriptionToEntitySubscriptionEntityTable.ts (1)

1-26: Migration looks good, with minor suggestions for improvement.

The migration correctly implements the renaming of 'subscription' table to 'entity_subscription' with appropriate up and down methods. This aligns well with the overall PR objective of refactoring Subscription to EntitySubscription across the codebase.

A couple of suggestions:

  • Consider adding a completion log message after the rename operation completes
  • You might want to add more detailed documentation about what this migration is doing and why
 public async up(queryRunner: QueryRunner): Promise<void> {
   console.log(chalk.yellow(this.name + ' start running!'));

   await queryRunner.renameTable('subscription', 'entity_subscription');
+  console.log(chalk.green(this.name + ' completed successfully!'));
 }

 /**
  * Down Migration
  *
  * @param queryRunner
  */
 public async down(queryRunner: QueryRunner): Promise<void> {
   await queryRunner.renameTable('entity_subscription', 'subscription');
+  console.log(chalk.green('Reverted ' + this.name + ' successfully!'));
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e858af4 and 6620447.

📒 Files selected for processing (2)
  • packages/core/src/lib/database/migrations/1740727466186-RenameOldSubscriptionToEntitySubscriptionEntityTable.ts (1 hunks)
  • packages/core/src/lib/entity-subscription/entity-subscription.entity.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/lib/entity-subscription/entity-subscription.entity.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: test
  • GitHub Check: build

@rahul-rocket rahul-rocket merged commit 26f568c into develop Feb 28, 2025
14 of 15 checks passed
@rahul-rocket rahul-rocket deleted the fix/alter-entity-subscription-entity branch February 28, 2025 07:56
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