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

[Feat] Tag Type #8692

Merged
merged 5 commits into from
Jan 6, 2025
Merged

[Feat] Tag Type #8692

merged 5 commits into from
Jan 6, 2025

Conversation

samuelmbabhazi
Copy link
Contributor

@samuelmbabhazi samuelmbabhazi commented Jan 3, 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

Release Notes

  • New Features

    • Added support for tag types, allowing more detailed categorization of tags.
    • Introduced predefined tag type categories like Equipment, Income, Invoice, Payment, and more.
    • Added new endpoints for managing tag types, including retrieval and counting.
  • Improvements

    • Enhanced tag data model to include optional tag type associations.
    • Expanded API to support tag type management and retrieval.
  • Technical Updates

    • Implemented new repositories and services for tag type handling.
    • Added database seeding for default tag types across organizations.
    • Introduced a new module for tag type management.
    • Created a migration for the tag_type table in the database.

Copy link
Contributor

coderabbitai bot commented Jan 3, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request implements a comprehensive tag type system in the Gauzy application, introducing new interfaces, entities, services, controllers, and modules to support tag type functionality. Key changes include updates to the tag model, the creation of a new TagType entity, the implementation of repositories for different ORMs, and the addition of default tag types. These enhancements facilitate detailed categorization and association of tags with specific types throughout the application.

Changes

File Change Summary
packages/contracts/src/lib/tag.model.ts Updated ITag and ITagFindInput interfaces; added new ITagType interface.
packages/core/src/index.ts Added exports for TagTypeModule and TagTypeService.
packages/core/src/lib/core/entities/index.ts Added TagType to entity imports and exports.
packages/core/src/lib/core/entities/internal.ts Added export for tag-type.entity.
packages/core/src/lib/tag-type/default-tag-types.ts Created DEFAULT_TAG_TYPES constant with predefined tag types.
packages/core/src/lib/tag-type/index.ts Exported all entities from tag-type.module and tag-type.service.
packages/core/src/lib/tag-type/repository/mikro-orm-tag-type.repository.ts Added MikroOrmTagTypeRepository class.
packages/core/src/lib/tag-type/repository/type-orm-tag-type.repository.ts Added TypeOrmTagTypeRepository class.
packages/core/src/lib/tag-type/tag-type.controller.ts Added TagTypeController class with endpoints for tag types.
packages/core/src/lib/tag-type/tag-type.entity.ts Added TagType entity class.
packages/core/src/lib/tag-type/tag-type.module.ts Added TagTypeModule configuration.
packages/core/src/lib/tag-type/tag-type.seed.ts Added functions for seeding tag types.
packages/core/src/lib/tag-type/tag-type.service.ts Added TagTypeService class for managing tag types.
packages/core/src/lib/tags/tag.entity.ts Added tagType and tagTypeId properties to Tag entity.
packages/core/src/lib/database/migrations/1736155704913-CreateTagTypeTable.ts Added migration class for creating tag_type table.

Possibly Related PRs

Suggested Reviewers

  • GloireMutaliko21

Poem

🐰 Hop, hop, through the code we go,
Tags now have a type, don't you know!
From Equipment to Task, we'll categorize,
With repositories that optimize,
A tagging system that makes developers glow! 🏷️


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 23ccf2c and 2883b91.

📒 Files selected for processing (2)
  • packages/core/src/lib/database/migrations/1736155704913-CreateTagTypeTable.ts (1 hunks)
  • packages/core/src/lib/tags/tag.entity.ts (5 hunks)

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. (Beta)
  • @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

nx-cloud bot commented Jan 3, 2025

View your CI Pipeline Execution ↗ for commit 2883b91.

Command Status Duration Result
nx build desktop --base-href ./ ✅ Succeeded 1m 40s View ↗
nx build desktop-api --output-path=dist/apps/de... ✅ Succeeded 25s View ↗
nx run api:desktop-api ✅ Succeeded 1m 10s View ↗
nx build gauzy -c=production --prod --verbose ✅ Succeeded 4m 14s View ↗
nx run gauzy:desktop-ui --base-href ./ ✅ Succeeded 3m 41s View ↗
nx build api -c=production --prod ✅ Succeeded 1m 8s View ↗
nx build desktop-ui-lib --configuration=develop... ✅ Succeeded 30s View ↗
nx build plugin-integration-wakatime ✅ Succeeded <1s View ↗
Additional runs (53) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-01-06 10:38:49 UTC

@samuelmbabhazi samuelmbabhazi marked this pull request as ready for review January 6, 2025 06:26
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 (10)
packages/core/src/lib/tag-type/repository/mikro-orm-tag-type.repository.ts (1)

4-4: Consider adding custom repository methods for TagType-specific queries.
At the moment, the repository class only extends the base repository with no additional functionality. If custom needs arise (e.g., domain-specific queries, aggregations, or validations), consider adding methods here instead of scattering them elsewhere.

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

6-11: Injecting the repository is correct; consider adding specialized methods.
Currently, this class implements the repository for TagType without additional domain-specific logic. If you need specialized queries or business logic (e.g., retrieving tag types by organizational criteria), consider encapsulating them here.

packages/core/src/lib/tag-type/default-tag-types.ts (1)

3-40: Centralized default tag types are beneficial; watch for future duplicates.
Defining default tag types is a neat addition. However, watch for potential future duplication across different modules. If you find that these default types are used in multiple places with slight variations, consider categorizing them or allowing for dynamic extension so that the code doesn’t become overly rigid.

packages/core/src/lib/tag-type/tag-type.seed.ts (2)

1-2: Consider grouping imports.
The imports look fine, but grouping them by domain (e.g., TypeORM vs Gauzy vs local libs) can make them easier to scan.


11-20: Use array methods consistently.
Mixing forEach and for in the same loop is slightly inconsistent. You could change the outer iteration to a for loop or map instead of forEach for clarity.

- DEFAULT_TAG_TYPES.forEach(({ type }) => {
-   for (const organization of organizations) {
-     // ...
-   }
- });
+ for (const { type } of DEFAULT_TAG_TYPES) {
+   for (const organization of organizations) {
+     // ...
+   }
+ }
packages/core/src/lib/tag-type/tag-type.module.ts (1)

21-23: Ensure consistent module exports.
It’s good practice to export only what other modules need. Check if external modules truly need direct access to both TypeOrmModule and MikroOrmModule.

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

1-7: Naming of entity can be more descriptive.
TagType is straightforward, but consider if a more specific name (e.g., TagCategory or TagClassification) might better reflect the domain.

packages/contracts/src/lib/tag.model.ts (1)

25-25: Extend filter capabilities.
Including tagTypeId in ITagFindInput is helpful. Consider also adding more advanced filtering (e.g., partial name search) if the product road map calls for it.

packages/core/src/lib/tag-type/tag-type.controller.ts (2)

35-37: Handle large datasets carefully.
While counting records is straightforward, be mindful of potential performance implications if FindOptionsWhere grows complex. Consider indexing or caching strategies to handle large data sets efficiently.


58-60: Possibility to add advanced filtering or searching.
Returning all TagType records is acceptable, but you might want to accept more refined query parameters (beyond pagination) for advanced filtering or search. This can help limit payload size and improve user experience.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2188b19 and f27d7d4.

📒 Files selected for processing (14)
  • packages/contracts/src/lib/tag.model.ts (2 hunks)
  • packages/core/src/index.ts (1 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/tag-type/default-tag-types.ts (1 hunks)
  • packages/core/src/lib/tag-type/index.ts (1 hunks)
  • packages/core/src/lib/tag-type/repository/mikro-orm-tag-type.repository.ts (1 hunks)
  • packages/core/src/lib/tag-type/repository/type-orm-tag-type.repository.ts (1 hunks)
  • packages/core/src/lib/tag-type/tag-type.controller.ts (1 hunks)
  • packages/core/src/lib/tag-type/tag-type.entity.ts (1 hunks)
  • packages/core/src/lib/tag-type/tag-type.module.ts (1 hunks)
  • packages/core/src/lib/tag-type/tag-type.seed.ts (1 hunks)
  • packages/core/src/lib/tag-type/tag-type.service.ts (1 hunks)
  • packages/core/src/lib/tags/tag.entity.ts (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/core/src/lib/tag-type/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (19)
packages/core/src/lib/tag-type/repository/mikro-orm-tag-type.repository.ts (1)

1-2: Existing base repository usage looks good.
The import statements for both the base repository and the TagType entity are appropriate and consistent with the intended usage.

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

1-3: Imports are clearly separated and consistent.
The use of @InjectRepository with the TagType entity is logically correct and follows the NestJS typing guidelines.

packages/core/src/lib/tag-type/tag-type.seed.ts (2)

6-10: Validate potential repeated creation of tag type entries.
If createTagTypes is called multiple times with overlapping organizations, there’s a possibility of duplicates. Consider adding checks or unique constraints on type, organization, and tenant to avoid duplicate records.


21-24: Check error handling on insert.
Since insertLevels returns a promise, consider wrapping it in proper try/catch blocks or letting errors propagate to a higher layer to ensure that failures are handled gracefully.

packages/core/src/lib/tag-type/tag-type.module.ts (2)

1-10: Module dependencies look good.
All required modules and imports appear appropriate for TagTypeModule. Good job organizing them.


11-20: Verify route path correctness.
The router path is set to /tag-types. Double-check that your frontend is expecting this endpoint and that no further path segments are needed.

packages/core/src/lib/tag-type/tag-type.entity.ts (2)

9-11: Consider marking type as unique.
If each organization’s tag types need to be uniquely named, adding a uniqueness constraint can prevent duplicates. If not, ignore.


19-24: Ensure relationships are flushed in correct order.
If you plan on creating Tag entries that reference this entity, confirm the seeding or creation order so that TagType is always persisted before referencing it.

packages/contracts/src/lib/tag.model.ts (2)

15-16: Optional chaining for tag types.
Marking tagTypeId and tagType as optional is sensible, ensuring that existing tags are not forced to adopt a tag type.


30-33: ITagType interface is well-defined.
The ITagType interface covers the essential fields. If future extension is expected, ensure compatibility with your service logic and the entity.

packages/core/src/lib/tag-type/tag-type.controller.ts (3)

1-2: Imports look good.
Your import statements cover all the necessary NestJS, Swagger, TypeORM, and contracts modules. Everything seems in order for this controller.


7-11: Confirm permission scopes.
The combination of TenantPermissionGuard and PermissionGuard looks correct for a multi-tenant setup, but please verify that you have the appropriate roles and permissions in place to ensure only authorized users can manage TagType.


14-16: Constructor correctly extends the CrudController.
By invoking the superclass with tagTypesService, you inherit standard CRUD methods without duplicating code. This is a solid approach.

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

103-103: Exporting TagTypeModule & TagTypeService is consistent with the pattern.
This ensures the new module and service are publicly available. Good move for modular design.

packages/core/src/lib/tags/tag.entity.ts (3)

2-2: Check for any unused imports.
JoinColumn is used, but confirm that other imported decorators like RelationId are still needed throughout. Housekeeping can help maintain clarity.


77-77: Import of TagType is appropriate.
The reference to TagType matches the new relationship property. This lines up well with the newly introduced entity.


119-135: Ensure orphaned tags are properly handled.
Using onDelete: 'SET NULL' is fine if you want to preserve tags after a TagType removal. Confirm that your business logic is OK with tags not having a type if the parent TagType is deleted.

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

134-134: Exporting TagType as part of core entities is consistent.
This aligns with the standard practice of centralizing entity exports in internal.ts. Your approach is clear and maintainable.

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

133-133: LGTM! Clean integration of the TagType entity.

The TagType entity has been properly integrated into both the imports and exports sections, maintaining alphabetical order and following the established patterns in the file.

Also applies to: 290-290

packages/core/src/lib/tag-type/tag-type.service.ts Outdated Show resolved Hide resolved
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/tag-type/tag-type.service.ts (1)

11-15: Fix inconsistent spacing in constructor parameters.

There's an extra blank line between the constructor parameters. Maintain consistent spacing for better readability.

 	constructor(
 		@InjectRepository(TagType)
 		typeOrmTagTypeRepository: TypeOrmTagTypeRepository,
-
 		mikroOrmTagTypeRepository: MikroOrmTagTypeRepository
 	) {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f27d7d4 and df66212.

📒 Files selected for processing (1)
  • packages/core/src/lib/tag-type/tag-type.service.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test
  • GitHub Check: build
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (2)
packages/core/src/lib/tag-type/tag-type.service.ts (2)

11-12: Consider renaming the repository parameter for clarity.

The parameter name typeOrmTagTypeRepository would better reflect its purpose, maintaining consistency with the entity it manages.


1-18: LGTM! The service implementation follows best practices.

The service is well-structured with proper dependency injection, extends the appropriate base class, and correctly implements the repository pattern with support for both TypeORM and MikroORM.

@rahul-rocket rahul-rocket changed the title [Enhancement] Tag Type (implement backend logic and entity creation for Tag T…) [Feat] Tag Type Jan 6, 2025
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: 3

🧹 Nitpick comments (4)
packages/core/src/lib/tag-type/default-tag-types.ts (2)

22-35: Consider sorting tag types and improving naming consistency.

The tag types array would benefit from:

  1. Alphabetical sorting for easier maintenance
  2. Consistent naming (e.g., "Organization Contact" vs "Employee" - consider using consistent prefixes)

17-19: Enhance documentation example.

The current example (console.log) doesn't demonstrate practical usage. Consider showing how to use these tag types in a real scenario.

Replace with a more meaningful example:

// Example of using default tag types to initialize database
async function seedDefaultTagTypes(tagTypeService: TagTypeService) {
  await Promise.all(
    DEFAULT_TAG_TYPES.map(tagType => tagTypeService.create(tagType))
  );
}
packages/contracts/src/lib/tag.model.ts (2)

2-2: Consider making tagType required if tagTypeId is present

The relationship between tagTypeId and tagType properties in the ITag interface could be more strictly typed to ensure data consistency.

Consider using a union type to enforce this relationship:

export interface ITag extends IBasePerTenantAndOrganizationEntityModel, IRelationalOrganizationTeam {
  // ... other properties
  tagTypeId?: ID;
  tagType?: tagTypeId extends undefined ? undefined : ITagType;
}

Also applies to: 15-16


30-33: Add validation constraints to ITagType

The ITagType interface could benefit from additional constraints to ensure data integrity.

Consider adding these constraints:

export interface ITagType {
  type: string & { minLength: 1; maxLength: 255 }; // Ensure non-empty and reasonable length
  tags?: ITag[] & { unique: true }; // Ensure no duplicate tags
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between df66212 and 23ccf2c.

📒 Files selected for processing (8)
  • packages/contracts/src/lib/tag.model.ts (3 hunks)
  • packages/core/src/lib/tag-type/default-tag-types.ts (1 hunks)
  • packages/core/src/lib/tag-type/tag-type.controller.ts (1 hunks)
  • packages/core/src/lib/tag-type/tag-type.entity.ts (1 hunks)
  • packages/core/src/lib/tag-type/tag-type.module.ts (1 hunks)
  • packages/core/src/lib/tag-type/tag-type.seed.ts (1 hunks)
  • packages/core/src/lib/tag-type/tag-type.service.ts (1 hunks)
  • packages/core/src/lib/tags/tag.entity.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/core/src/lib/tags/tag.entity.ts
  • packages/core/src/lib/tag-type/tag-type.entity.ts
  • packages/core/src/lib/tag-type/tag-type.controller.ts
🧰 Additional context used
🪛 Biome (1.9.4)
packages/core/src/lib/tag-type/tag-type.service.ts

[error] 9-14: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: test
  • GitHub Check: build
🔇 Additional comments (4)
packages/core/src/lib/tag-type/tag-type.service.ts (2)

9-14: Constructor is necessary for dependency injection.

While the static analysis tool flags this as an unnecessary constructor, it's actually required for NestJS dependency injection to work properly. The constructor properly initializes the parent class with both ORM repositories.

🧰 Tools
🪛 Biome (1.9.4)

[error] 9-14: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)


10-10: Naming alignment and injection consistency could be improved.

The injected repository parameter name typeOrmTagTypeRepository should align with the class's purpose.

packages/contracts/src/lib/tag.model.ts (1)

25-25: LGTM! Type changes look good

The changes to use ID type instead of string in both ITagFindInput and ITagUpdateInput are consistent with the base entity model.

Also applies to: 36-36

packages/core/src/lib/tag-type/tag-type.seed.ts (1)

6-33: Great documentation!

The JSDoc comments are comprehensive and include excellent examples. This helps maintain code quality and improves developer experience.

@rahul-rocket rahul-rocket merged commit d159f87 into develop Jan 6, 2025
13 of 16 checks passed
@rahul-rocket rahul-rocket deleted the enhancement/tag-type branch January 6, 2025 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants