Skip to content

refactor(api): centrelize lifecycle-hook-manager types #1108

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yassinedorbozgithub
Copy link
Collaborator

@yassinedorbozgithub yassinedorbozgithub commented Jun 8, 2025

Motivation

The main motivation of this PR is to centralize lifecycle-hook-manager types.

Fixes #1107

Checklist:

  • I have performed a self-review of my own code
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • Refactor
    • Unified and streamlined method signatures for various lifecycle hooks across multiple repositories, improving consistency and maintainability.
    • Simplified internal parameter handling for create, update, and delete operations.
    • Introduced new type definitions for lifecycle hook arguments and returns to standardize repository method patterns.
  • Chores
    • Cleaned up unused imports and improved type usage for better code clarity.

@yassinedorbozgithub yassinedorbozgithub self-assigned this Jun 8, 2025
@yassinedorbozgithub yassinedorbozgithub added the 🪄 Investigate Investigate old code to find any missing logic label Jun 8, 2025
Copy link
Contributor

coderabbitai bot commented Jun 8, 2025

Walkthrough

The codebase refactors all lifecycle hook method signatures in repository classes to use unified argument and return types imported from a new lifecycle-hook-manager.types.ts file. Explicit Mongoose types are removed from method parameters, replaced with generic tuple destructuring (Args<...>) for consistency and maintainability. No business logic is changed.

Changes

File(s) Change Summary
api/src/chat/repositories/block.repository.ts
api/src/chat/repositories/category.repository.ts
api/src/chat/repositories/context-var.repository.ts
api/src/chat/repositories/label.repository.ts
api/src/chat/repositories/subscriber.repository.ts
Refactored lifecycle hook method signatures to use Args<...> types; removed explicit Mongoose types.
api/src/cms/repositories/content-type.repository.ts
api/src/cms/repositories/content.repository.ts
Refactored lifecycle hook method signatures to use generic argument tuples from new lifecycle types file.
api/src/nlp/repositories/nlp-entity.repository.ts
api/src/nlp/repositories/nlp-sample.repository.ts
api/src/nlp/repositories/nlp-value.repository.ts
Updated lifecycle hook signatures to use variadic tuple arguments and removed explicit Mongoose types.
api/src/setting/repositories/setting.repository.ts Changed lifecycle hook method signatures to use tuple arguments and unified return types.
api/src/user/repositories/user.repository.ts Refactored lifecycle hook signatures to use Args<...> and removed explicit Mongoose types.
api/src/utils/generics/base-repository.ts Refactored all base lifecycle hook signatures to use generic tuple arguments and return types.
api/src/utils/types/lifecycle-hook-manager.types.ts New file: Defines all generic lifecycle hook argument and return types for repository hooks.

Sequence Diagram(s)

Loading
sequenceDiagram
    participant Repository
    participant LifecycleTypes

    Repository->>LifecycleTypes: Import Args, preCreate, preUpdate, etc.
    Repository->>Repository: Define hook (e.g., preCreate(...[doc]: Args<preCreate<T>>))
    Note right of Repository: Use tuple destructuring for arguments
    Repository->>Repository: Execute hook logic as before

Assessment against linked issues

Objective Addressed Explanation
Centralize lifecycle-hook-manager types and update all usages to import from one location (#1107)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Suggested labels

enhancement

Suggested reviewers

  • yassinedorbozgithub
  • medchedli

Poem

A hop, a skip, a type refactor,
Now hooks are neat—no need to barter!
Args and R, the types align,
Across the code, the signatures shine.
With tuples tidy, the code’s a treat,
This rabbit’s paws applaud your feat! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@yassinedorbozgithub yassinedorbozgithub linked an issue Jun 8, 2025 that may be closed by this pull request
@yassinedorbozgithub yassinedorbozgithub force-pushed the 1107-issue---refactor-lifecycle-hook-manager-types branch from d8200ff to 3e22921 Compare June 8, 2025 08:46
@marrouchi marrouchi changed the base branch from 1105-issue---botstats-is-missed-echo-type to main June 9, 2025 08:30
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: 2

🧹 Nitpick comments (1)
api/src/utils/types/lifecycle-hook-manager.types.ts (1)

61-64: Consider stronger typing for the updated parameter.

The _updated: any parameter in postUpdateMany could benefit from more specific typing for better type safety.

export type postUpdateMany<T> = (
  _query: Query<Document<T>, Document<T>, unknown, T, 'updateMany'>,
-  _updated: any,
+  _updated: { acknowledged: boolean; modifiedCount: number; upsertedId?: any; upsertedCount: number; matchedCount: number },
) => Promise<void>;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9bfa76a and 3e22921.

📒 Files selected for processing (14)
  • api/src/chat/repositories/block.repository.ts (7 hunks)
  • api/src/chat/repositories/category.repository.ts (2 hunks)
  • api/src/chat/repositories/context-var.repository.ts (2 hunks)
  • api/src/chat/repositories/label.repository.ts (3 hunks)
  • api/src/chat/repositories/subscriber.repository.ts (3 hunks)
  • api/src/cms/repositories/content-type.repository.ts (2 hunks)
  • api/src/cms/repositories/content.repository.ts (3 hunks)
  • api/src/nlp/repositories/nlp-entity.repository.ts (4 hunks)
  • api/src/nlp/repositories/nlp-sample.repository.ts (2 hunks)
  • api/src/nlp/repositories/nlp-value.repository.ts (4 hunks)
  • api/src/setting/repositories/setting.repository.ts (3 hunks)
  • api/src/user/repositories/user.repository.ts (3 hunks)
  • api/src/utils/generics/base-repository.ts (3 hunks)
  • api/src/utils/types/lifecycle-hook-manager.types.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (9)
api/src/nlp/repositories/nlp-sample.repository.ts (5)
api/src/utils/types/lifecycle-hook-manager.types.ts (2)
  • Args (21-21)
  • preDelete (71-80)
api/src/chat/repositories/label.repository.ts (1)
  • preDelete (74-83)
api/src/nlp/repositories/nlp-entity.repository.ts (1)
  • preDelete (85-101)
api/src/nlp/repositories/nlp-value.repository.ts (1)
  • preDelete (84-101)
api/src/utils/generics/base-repository.ts (1)
  • preDelete (631-633)
api/src/chat/repositories/category.repository.ts (9)
api/src/utils/types/lifecycle-hook-manager.types.ts (2)
  • Args (21-21)
  • preDelete (71-80)
api/src/chat/repositories/label.repository.ts (1)
  • preDelete (74-83)
api/src/chat/repositories/context-var.repository.ts (1)
  • preDelete (50-72)
api/src/chat/repositories/block.repository.ts (1)
  • preDelete (224-247)
api/src/cms/repositories/content-type.repository.ts (1)
  • preDelete (45-60)
api/src/nlp/repositories/nlp-sample.repository.ts (1)
  • preDelete (46-56)
api/src/nlp/repositories/nlp-entity.repository.ts (1)
  • preDelete (85-101)
api/src/nlp/repositories/nlp-value.repository.ts (1)
  • preDelete (84-101)
api/src/utils/generics/base-repository.ts (1)
  • preDelete (631-633)
api/src/cms/repositories/content-type.repository.ts (5)
api/src/utils/types/lifecycle-hook-manager.types.ts (2)
  • Args (21-21)
  • preDelete (71-80)
api/src/chat/repositories/category.repository.ts (1)
  • preDelete (44-63)
api/src/chat/repositories/context-var.repository.ts (1)
  • preDelete (50-72)
api/src/nlp/repositories/nlp-sample.repository.ts (1)
  • preDelete (46-56)
api/src/utils/generics/base-repository.ts (1)
  • preDelete (631-633)
api/src/chat/repositories/label.repository.ts (10)
api/src/utils/types/lifecycle-hook-manager.types.ts (3)
  • Args (21-21)
  • postCreate (47-47)
  • preDelete (71-80)
api/src/chat/repositories/subscriber.repository.ts (1)
  • postCreate (45-52)
api/src/nlp/repositories/nlp-entity.repository.ts (2)
  • postCreate (54-59)
  • preDelete (85-101)
api/src/nlp/repositories/nlp-value.repository.ts (2)
  • postCreate (57-62)
  • preDelete (84-101)
api/src/utils/generics/base-repository.ts (2)
  • postCreate (611-613)
  • preDelete (631-633)
api/src/chat/repositories/category.repository.ts (1)
  • preDelete (44-63)
api/src/chat/repositories/context-var.repository.ts (1)
  • preDelete (50-72)
api/src/chat/repositories/block.repository.ts (1)
  • preDelete (224-247)
api/src/cms/repositories/content-type.repository.ts (1)
  • preDelete (45-60)
api/src/nlp/repositories/nlp-sample.repository.ts (1)
  • preDelete (46-56)
api/src/setting/repositories/setting.repository.ts (4)
api/src/utils/types/lifecycle-hook-manager.types.ts (4)
  • Args (21-21)
  • preCreateValidate (25-29)
  • preUpdateValidate (35-38)
  • postUpdate (66-69)
api/src/utils/generics/base-repository.ts (3)
  • preCreateValidate (583-587)
  • preUpdateValidate (595-599)
  • postUpdate (627-629)
api/src/nlp/repositories/nlp-entity.repository.ts (1)
  • postUpdate (69-74)
api/src/nlp/repositories/nlp-value.repository.ts (1)
  • postUpdate (70-75)
api/src/utils/types/lifecycle-hook-manager.types.ts (2)
api/src/utils/generics/base-repository.ts (13)
  • preCreateValidate (583-587)
  • postCreateValidate (589-593)
  • preUpdateValidate (595-599)
  • postUpdateValidate (601-605)
  • preCreate (607-609)
  • postCreate (611-613)
  • preUpdate (615-617)
  • preUpdateMany (619-621)
  • postUpdateMany (623-625)
  • postUpdate (627-629)
  • preDelete (631-633)
  • DeleteResult (58-61)
  • postDelete (635-637)
api/src/utils/types/filter.types.ts (1)
  • TFilterQuery (134-142)
api/src/cms/repositories/content.repository.ts (5)
api/src/utils/types/lifecycle-hook-manager.types.ts (3)
  • Args (21-21)
  • preCreate (45-45)
  • preUpdate (49-53)
api/src/user/repositories/user.repository.ts (2)
  • preCreate (46-53)
  • preUpdate (62-83)
api/src/utils/generics/base-repository.ts (2)
  • preCreate (607-609)
  • preUpdate (615-617)
api/src/chat/repositories/message.repository.ts (1)
  • preCreate (47-53)
api/src/user/repositories/invitation.repository.ts (1)
  • preCreate (38-44)
api/src/user/repositories/user.repository.ts (4)
api/src/utils/types/lifecycle-hook-manager.types.ts (3)
  • Args (21-21)
  • preCreate (45-45)
  • preUpdate (49-53)
api/src/cms/repositories/content.repository.ts (2)
  • preCreate (45-47)
  • preUpdate (57-63)
api/src/utils/generics/base-repository.ts (2)
  • preCreate (607-609)
  • preUpdate (615-617)
api/src/user/repositories/invitation.repository.ts (1)
  • preCreate (38-44)
api/src/nlp/repositories/nlp-value.repository.ts (4)
api/src/utils/types/lifecycle-hook-manager.types.ts (4)
  • Args (21-21)
  • postCreate (47-47)
  • postUpdate (66-69)
  • preDelete (71-80)
api/src/nlp/repositories/nlp-entity.repository.ts (3)
  • postCreate (54-59)
  • postUpdate (69-74)
  • preDelete (85-101)
api/src/utils/generics/base-repository.ts (3)
  • postCreate (611-613)
  • postUpdate (627-629)
  • preDelete (631-633)
api/src/nlp/repositories/nlp-sample.repository.ts (1)
  • preDelete (46-56)
🔇 Additional comments (30)
api/src/chat/repositories/context-var.repository.ts (2)

16-19: Import refactoring looks good.

The import changes correctly remove unused Mongoose types and add the centralized lifecycle hook types, improving consistency across the codebase.


50-50: Method signature refactoring is consistent.

The preDelete method signature correctly adopts the new Args<preDelete<ContextVar>> pattern with rest parameter destructuring, maintaining type safety while following the centralized approach.

api/src/nlp/repositories/nlp-sample.repository.ts (2)

11-14: Import statements properly updated.

The imports are correctly simplified and the centralized lifecycle hook types are properly imported, maintaining consistency with the refactoring pattern.


46-46: Lifecycle hook signature correctly updated.

The method signature follows the established pattern using Args<preDelete<NlpSample>> with proper parameter destructuring.

api/src/chat/repositories/category.repository.ts (2)

11-14: Import refactoring implemented correctly.

The import changes align with the centralization effort, removing unused Mongoose types and adding the required lifecycle hook types.


44-45: Method signature follows the new pattern.

The preDelete method correctly uses the Args<preDelete<Category>> pattern. Note that the criteria parameter is immediately reassigned from query.getQuery(), which suggests the original implementation pattern is preserved where the query object's criteria takes precedence over the passed criteria parameter.

api/src/cms/repositories/content-type.repository.ts (3)

11-15: Clean import refactoring.

The imports are properly updated to use the centralized lifecycle hook types, removing dependency on explicit Mongoose types in the method signatures.


45-46: Method signature and parameter handling improved.

The new signature using Args<preDelete<ContentType>> with destructuring is consistent with the pattern, and the direct assignment of criteria._id to entityId is cleaner than the previous approach.


53-54: Logic preservation with cleaner structure.

The entity ID validation and deletion logic is preserved while benefiting from the simplified parameter handling.

api/src/utils/types/lifecycle-hook-manager.types.ts (4)

21-23: LGTM: Clean utility types for parameter and return type extraction.

The Args<T> and R<T> utility types provide a clean way to extract function parameters and return types, enabling consistent lifecycle hook signatures across repositories.


25-44: LGTM: Comprehensive validation hook types.

The validation hook types cover both pre and post validation scenarios for create and update operations with appropriate parameter types and async return signatures.


45-70: LGTM: Well-structured CRUD operation hook types.

The create and update hook types provide comprehensive coverage with proper Mongoose query typing and generic document support.


71-91: LGTM: Properly typed delete operation hooks.

The delete hook types correctly use the DeleteResult type and support both single and bulk delete operations with appropriate Mongoose query typing.

api/src/chat/repositories/label.repository.ts (3)

11-11: LGTM: Clean import refactoring.

The imports have been properly updated to remove unused Mongoose types and add the necessary lifecycle hook manager types.

Also applies to: 14-18


46-46: LGTM: Consistent destructuring pattern for postCreate.

The method signature correctly uses the new Args<postCreate<Label>> pattern with proper destructuring to extract the created parameter.


74-74: LGTM: Proper parameter extraction in preDelete.

The method correctly destructures the arguments, ignoring the query parameter and extracting the criteria for deletion logic.

api/src/chat/repositories/subscriber.repository.ts (3)

11-11: LGTM: Consistent import refactoring.

The imports follow the same clean pattern as other repositories, removing unused Mongoose types and adding lifecycle hook manager types.

Also applies to: 15-19


45-45: LGTM: Proper postCreate refactoring.

The method signature correctly implements the new pattern while preserving the event emission logic.


62-64: LGTM: Correct preUpdate parameter extraction.

The method properly destructures the Args<preUpdate<Subscriber>> tuple, extracting the criteria and updates parameters while ignoring the query parameter.

api/src/user/repositories/user.repository.ts (3)

11-11: LGTM: Import cleanup follows established pattern.

The imports are properly updated to use the centralized lifecycle hook manager types.

Also applies to: 14-18


46-46: LGTM: Preserved security logic in preCreate.

The method signature is correctly updated while maintaining the critical password hashing functionality.


62-62: LGTM: Proper parameter extraction in preUpdate.

The method correctly extracts the query and updates parameters from the lifecycle hook arguments while preserving the password and resetToken hashing logic.

api/src/cms/repositories/content.repository.ts (1)

11-18: LGTM! Well-executed type refactoring that improves consistency.

The refactoring successfully centralizes lifecycle hook types while maintaining the existing logic. The parameter destructuring is correctly implemented:

  • preCreate properly extracts _doc from Args<preCreate<Content>>
  • preUpdate correctly destructures to get _query and _updates while skipping the middle parameter

Import cleanup removes unused Mongoose types, and the new pattern aligns with the broader codebase standardization.

Also applies to: 45-63

api/src/setting/repositories/setting.repository.ts (1)

12-20: LGTM! Clean refactoring with improved parameter naming.

The lifecycle hook method signatures have been successfully updated to use the centralized types:

  • Proper destructuring in preCreateValidate and preUpdateValidate
  • Good parameter renaming in postUpdate from setting to updated for better clarity
  • Import cleanup removes unused Mongoose types while adding the new lifecycle hook types

The refactoring maintains all existing logic while improving type consistency across the codebase.

Also applies to: 31-37, 67-73

api/src/nlp/repositories/nlp-entity.repository.ts (1)

11-19: LGTM! Consistent refactoring maintains all business logic.

The lifecycle hook methods have been properly updated to use the centralized type system:

  • Correct parameter destructuring in all three methods (postCreate, postUpdate, preDelete)
  • Import cleanup removes unused Mongoose types
  • All existing business logic preserved, including event emission for non-builtin entities and cascade deletion handling

The refactoring aligns perfectly with the codebase-wide standardization effort.

Also applies to: 54-59, 69-74, 85-101

api/src/nlp/repositories/nlp-value.repository.ts (1)

12-23: LGTM! Well-executed refactoring with appropriate import management.

The lifecycle hook methods have been correctly updated to use the centralized type system:

  • Proper parameter destructuring in all methods (postCreate, postUpdate, preDelete)
  • Selective import cleanup that retains necessary Mongoose types while removing unused ones
  • All existing business logic preserved, including event emission for non-builtin entities and cascade deletion handling

The refactoring maintains consistency with the broader codebase standardization while preserving all functionality.

Also applies to: 57-62, 70-75, 84-101

api/src/chat/repositories/block.repository.ts (3)

13-21: Well-structured imports for centralized lifecycle hook types.

The refactoring to import lifecycle hook types from a centralized location improves maintainability and follows the PR's objective effectively.


66-68: Good defensive programming with null check.

The addition of the null check before calling checkDeprecatedAttachmentUrl prevents potential runtime errors. The new signature pattern improves type safety.


77-104: Correct handling of update extraction and validation.

The method properly extracts updates from the $set operator and includes appropriate null checks before processing. The refactored signature maintains the same functionality with improved type safety.

api/src/utils/generics/base-repository.ts (1)

583-637: Excellent consistency in lifecycle hook refactoring.

The uniform application of the Args<> and R<> type patterns across all lifecycle hooks improves type safety and maintainability. The use of rest parameters with underscore for unused arguments follows TypeScript best practices.

Comment on lines +212 to 215
async postDelete(...[, result]: Args<postDelete<Block>>) {
if (result.deletedCount > 0) {
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove empty conditional block or implement the missing logic.

The method contains an empty conditional block that serves no purpose. Either implement the intended logic or remove the condition entirely.

-  async postDelete(...[, result]: Args<postDelete<Block>>) {
-    if (result.deletedCount > 0) {
-    }
-  }
+  async postDelete(...[, result]: Args<postDelete<Block>>) {
+    // Implementation can be added when needed
+  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async postDelete(...[, result]: Args<postDelete<Block>>) {
if (result.deletedCount > 0) {
}
}
async postDelete(...[, result]: Args<postDelete<Block>>) {
// Implementation can be added when needed
}
🤖 Prompt for AI Agents
In api/src/chat/repositories/block.repository.ts around lines 212 to 215, there
is an empty if statement checking if result.deletedCount is greater than 0 with
no logic inside. You should either implement the intended logic that should run
when deletions occur or remove the entire if condition and its block to avoid
having an empty conditional statement.

// Nothing ...
}

async preCreate(_doc: HydratedDocument<T>): Promise<void> {
async preCreate(..._: Args<preCreate<T>>): R<postCreate<T>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incorrect return types in lifecycle hook methods.

Two lifecycle hook methods have incorrect return types that don't match their method names. This breaks type safety and could lead to runtime issues.

-  async preCreate(..._: Args<preCreate<T>>): R<postCreate<T>> {
+  async preCreate(..._: Args<preCreate<T>>): R<preCreate<T>> {
-  async postUpdate(..._: Args<postUpdate<T>>): R<preDelete<T>> {
+  async postUpdate(..._: Args<postUpdate<T>>): R<postUpdate<T>> {

Also applies to: 627-627

🤖 Prompt for AI Agents
In api/src/utils/generics/base-repository.ts at lines 607 and 627, the lifecycle
hook methods preCreate and the other method at line 627 have incorrect return
types that do not align with their method names. Review the expected return
types for these lifecycle hooks and update the method signatures to use the
correct generic return types that match their lifecycle stage, ensuring type
safety and consistency.


export type Args<T extends (...args: any) => unknown> = Parameters<T>;

export type R<T extends (...args: any) => unknown> = ReturnType<T>;
Copy link
Contributor

@medchedli medchedli Jun 9, 2025

Choose a reason for hiding this comment

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

Is the R type alias unused ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The R type is already used
image

Copy link
Contributor

@medchedli medchedli left a comment

Choose a reason for hiding this comment

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

I tested the following hooks/scenarios to make sure the new implementation works properly :

  1. BlockRepository:
  • preDelete: Create two blocks, A and B. Attach block B to block A. Then, delete block B
  • preUpdate: Create two blocks, A and B. Attach block B to block A. Then, update block B to move it to a different category.
  1. CategoryRepository
  • preDelete: Prevent the deletion of categories that are not empty.
  1. ContentTypeRepository
  • preDelete: ensures that content types associated with blocks cannot be deleted.
  1. NlpEntityRepository
  • preDelete: Deletes to related NLP values and samples.

I didn't observe any issues during testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
file conflicts 🪄 Investigate Investigate old code to find any missing logic
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🤔 [ISSUE] - refactor lifecycle-hook-manager types
3 participants