Skip to content

Conversation

@LaGodxy
Copy link
Contributor

@LaGodxy LaGodxy commented Jun 28, 2025

Volunchain Pull Reques


Type of Change

  • Documentation (updates to README, docs, or comments)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Changes description

This PR implements a comprehensive refactoring to relocate all entities from the centralized src/entities/ directory to their corresponding domain modules under src/modules/<domain>/domain/entities/. This change aligns with Domain-Driven Design (DDD) principles and significantly improves code organization.

Key Changes Made:

Entity Relocations:

  • User Entitysrc/modules/user/domain/entities/user.entity.ts
  • Project Entitysrc/modules/project/domain/entities/project.entity.ts
  • Volunteer Entitysrc/modules/volunteer/domain/entities/volunteer.entity.ts
  • NFT Entitysrc/modules/nft/domain/entities/nft.entity.ts
  • Photo Entitysrc/modules/photo/domain/entities/photo.entity.ts
  • UserVolunteer Entitysrc/modules/user/domain/entities/user-volunteer.entity.ts
  • TestItem Entitysrc/modules/shared/domain/entities/test-item.entity.ts
  • BaseEntity & Entitysrc/modules/shared/domain/entities/base.entity.ts

Domain Logic Enhancements:

  • Project Entity: Added status management (DRAFT → ACTIVE → COMPLETED/CANCELLED) with methods activate(), complete(), cancel()
  • Volunteer Entity: Implemented factory method create(), update() method with validation, and toObject() serialization
  • NFT Entity: Added mint() functionality, metadata management, and ownership verification
  • Photo Entity: Enhanced URL validation, metadata management with updateMetadata()
  • User Entity: Improved email verification token management and wallet integration

Comprehensive Test Coverage:

Created unit tests for all entities covering:

  • Entity creation and validation
  • Domain method functionality
  • Error handling and edge cases
  • Business rule enforcement
  • Factory method validation

Technical Improvements:

  • Preserved all TypeORM decorators and relationships
  • Added comprehensive input validation
  • Implemented proper domain exceptions
  • Added static factory methods with validation
  • Enhanced business logic within entities

Breaking Changes:

  • Import paths for entities have changed
  • Factory methods are now the preferred way to create entities
  • Some entity interfaces have been enhanced

Migration Guide:

// Before
import { User } from '../entities/User'

// After  
import { User } from '../modules/user/domain/entities/user.entity'

// Preferred entity creation (new)
const volunteer = Volunteer.create({
  name: 'Community Cleanup',
  description: 'Help clean local park',
  requirements: 'Bring gloves',
  projectId: 'project-123'
})

Summary by CodeRabbit

  • New Features

    • Introduced new entity classes for User, Project, Volunteer, Photo, NFT, TestItem, and UserVolunteer with domain logic, validation, and relationship mappings.
    • Added domain methods for project status management, NFT minting and ownership checks, metadata updates, and volunteer updates.
  • Bug Fixes

    • Enhanced validation and error handling during entity creation and updates.
  • Refactor

    • Centralized entity implementations and restructured modules for improved maintainability.
    • Updated import paths and re-exported entities to streamline module organization.
    • Removed deprecated or redundant entity files.
  • Tests

    • Added comprehensive test suites covering creation, updates, validation, and domain behaviors for User, Project, Volunteer, Photo, NFT, TestItem, and UserVolunteer entities.
  • Chores

    • Upgraded development dependencies, including eslint, to latest versions.
    • Updated .gitignore to exclude macOS system files.

@coderabbitai
Copy link

coderabbitai bot commented Jun 28, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (4)
  • .DS_Store is excluded by !**/.DS_Store
  • src/.DS_Store is excluded by !**/.DS_Store
  • src/modules/.DS_Store is excluded by !**/.DS_Store
  • src/modules/volunteer/.DS_Store is excluded by !**/.DS_Store

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This change migrates all entity classes from the shared src/entities/ directory into their respective domain module directories under domain/entities/. All import paths throughout the codebase are updated to reference the new locations. Associated test files are added or moved to the correct module test directories. The original src/entities/ files are deleted.

Changes

Files/Groups Change Summary
src/entities/*.ts Deleted all entity files (User, Volunteer, Organization, Project, NFT, Photo, TestItem, userVolunteer.entity).
src/modules/<domain>/domain/entities/*.ts (User, Volunteer, Organization, Project, NFT, etc.) Recreated entity classes with TypeORM decorators in their respective module directories.
src/modules/shared/domain/entities/base.entity.ts, entity.ts, test-item.entity.ts Refactored and added base and utility entity classes, including generic Entity<T> and TestItem.
src/modules/<domain>/domain/entities/*.ts (Photo, NFT, Project, User, Volunteer, etc.) Implemented or refactored domain entity logic, with validation, methods, and persistence decorators.
src/modules/<domain>/__tests__/domain/entities/*.test.ts Added or moved unit tests for each entity to the appropriate domain test directories.
src/modules/<domain>/use-cases/*.ts, repositories/*.ts, services/*.ts Updated import paths to use new entity locations.
src/modules/photo/entities/photo.entity.ts, src/modules/user/domain/entities/User.ts Changed to re-export entities from new domain locations.
package.json Updated eslint devDependency version.
src/config/prisma.ts Removed obsolete ESLint directive comment.

Changes Table (Grouped)

Files/Groups Change Summary
src/entities/*.ts Deleted all shared entity files.
src/modules/*/domain/entities/*.ts Added or refactored entity classes with TypeORM decorators and domain logic in module-specific directories.
src/modules/*/__tests__/domain/entities/*.test.ts Added or moved unit tests for entities to module test directories.
src/modules/*/use-cases/*.ts, repositories/*.ts, etc. Updated all import paths to reference new entity locations.
src/modules/photo/entities/photo.entity.ts, ... Changed to re-export entities from new domain locations.
package.json, src/config/prisma.ts Minor dependency and comment cleanup.

Sequence Diagram(s)

sequenceDiagram
  participant Service/UseCase
  participant Domain Entity (in domain/entities)
  participant Database (via TypeORM)

  Service/UseCase->>Domain Entity (in domain/entities): Import and instantiate entity
  Domain Entity (in domain/entities)->>Domain Entity (in domain/entities): Apply validation/business logic
  Domain Entity (in domain/entities)->>Database (via TypeORM): Persist or query entity
  Database (via TypeORM)-->>Domain Entity (in domain/entities): Return entity instance/data
  Domain Entity (in domain/entities)-->>Service/UseCase: Return processed entity
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Move entities from src/entities/ to src/modules/<domain>/domain/entities/ (#127)
Refactor imports across all layers to new entity locations (#127)
Write or move unit tests for each entity to src/modules/<domain>/__tests__/domain/entities/ (#127)
Delete src/entities/ when done (#127)

Assessment against linked issues: Out-of-scope changes

Code Change (file_path) Explanation
Update eslint version in devDependencies (package.json) Updating ESLint is not related to the entity migration objective.
Remove ESLint directive comment (src/config/prisma.ts) Removing a linter directive is unrelated to entity relocation.

Poem

In burrows deep, the entities hop,
Each finds a home in its own domain shop.
With tests in tow and imports anew,
The codebase shines, its structure true.
No more wandering, all in their place—
This bunny’s proud of your organized space!
🐇✨


🪧 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.

Copy link

@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: 19

🔭 Outside diff range comments (2)
src/modules/volunteer/use-cases/update-volunteer.use-case.ts (1)

16-18: Replace generic Error with a domain-specific exception
Throwing new Error("Volunteer not found") couples callers to a string literal and makes typed error handling impossible. Introduce a VolunteerNotFoundError extends Error (or equivalent) and throw that instead.

-      throw new Error("Volunteer not found");
+      throw new VolunteerNotFoundError(id);
src/modules/organization/domain/entities/organization.entity.ts (1)

29-35: Remove unused constructor parameters.

The constructor accepts id, createdAt, and updatedAt parameters but doesn't use them. Since super() is called without arguments (indicating the new BaseEntity uses TypeORM decorators), these parameters should be removed for consistency.

  constructor(
-    props: OrganizationProps,
-    id?: string,
-    createdAt?: Date,
-    updatedAt?: Date
+    props: OrganizationProps
  ) {
    super();

Also update the static factory method and update method calls accordingly:

  public static create(props: OrganizationProps, id?: string): Organization {
-    return new Organization(props, id);
+    return new Organization(props);
  }

  public update(props: Partial<OrganizationProps>): Organization {
    return new Organization(
      {
        id: this.id,
        name: props.name ?? this.name,
        email: props.email ?? this.email,
        description: props.description ?? this.description,
        category: props.category ?? this.category,
        website: props.website ?? this.website,
        address: props.address ?? this.address,
        phone: props.phone ?? this.phone,
        isVerified: props.isVerified ?? this.isVerified,
        logoUrl: props.logoUrl ?? this.logoUrl,
        walletAddress: props.walletAddress ?? this.walletAddress,
-      },
-      this.id,
-      this.createdAt,
-      new Date()
+      }
    );
  }
🧹 Nitpick comments (9)
src/modules/volunteer/use-cases/create-volunteer.use-case.ts (1)

8-12: Surface domain-level validation errors instead of raw exceptions
Volunteer.create() may throw validation errors. Consider catching these and mapping them to a domain-specific error (e.g., VolunteerValidationError) so the application layer can react appropriately instead of leaking low-level exceptions.

src/modules/volunteer/use-cases/get-volunteers-by-project.use-case.ts (1)

17-24: Potential N+1 database hit—consider batching
findByProjectId(...) and count(...) are executed sequentially. If your Prisma client supports aggregate queries, you can fetch both the list and the count in a single round-trip to reduce latency.

src/modules/user/use-cases/userUseCase.ts (1)

11-13: Switch to non-blocking password hashing
bcrypt.hashSync blocks the event loop. Use the async variant to avoid performance degradation under load.

-const hashedPassword = bcrypt.hashSync(data.password, 10);
+const hashedPassword = await bcrypt.hash(data.password, 10);
src/modules/volunteer/repositories/implementations/volunteer-prisma.repository.ts (1)

8-10: Instantiate PrismaClient once, reuse via DI
Creating a new PrismaClient per repository instance can exhaust database connections. Inject a shared client (e.g., via NestJS provider or singleton) instead.

src/modules/user/__tests__/domain/entities/user-volunteer.entity.test.ts (2)

17-33: Enhance validation test coverage for edge cases.

Consider adding test cases for null and undefined values to ensure robust validation:

+    it("should throw error if userId is null or undefined", () => {
+      expect(() => UserVolunteer.create(null as any, validVolunteerId)).toThrow("User ID and Volunteer ID are required")
+      expect(() => UserVolunteer.create(undefined as any, validVolunteerId)).toThrow("User ID and Volunteer ID are required")
+    })
+
+    it("should throw error if volunteerId is null or undefined", () => {
+      expect(() => UserVolunteer.create(validUserId, null as any)).toThrow("User ID and Volunteer ID are required")
+      expect(() => UserVolunteer.create(validUserId, undefined as any)).toThrow("User ID and Volunteer ID are required")
+    })

54-63: Consider improving timestamp test reliability.

The current timestamp test may be flaky due to timing precision. Consider using Jest's fake timers or a more robust approach:

-  describe("Timestamps", () => {
-    it("should set joinedAt timestamp on creation", () => {
-      const beforeCreation = new Date()
-      const userVolunteer = UserVolunteer.create(validUserId, validVolunteerId)
-      const afterCreation = new Date()
-
-      expect(userVolunteer.joinedAt.getTime()).toBeGreaterThanOrEqual(beforeCreation.getTime())
-      expect(userVolunteer.joinedAt.getTime()).toBeLessThanOrEqual(afterCreation.getTime())
-    })
-  })
+  describe("Timestamps", () => {
+    it("should set joinedAt timestamp on creation", () => {
+      const userVolunteer = UserVolunteer.create(validUserId, validVolunteerId)
+      const now = new Date()
+      const timeDifference = Math.abs(userVolunteer.joinedAt.getTime() - now.getTime())
+      
+      expect(userVolunteer.joinedAt).toBeInstanceOf(Date)
+      expect(timeDifference).toBeLessThan(1000) // Allow 1 second tolerance
+    })
+  })
src/modules/user/__tests__/domain/entities/user.entity.test.ts (1)

1-60: Consider adopting factory method pattern for consistency.

Unlike other entity tests in this PR, the User entity tests use direct constructor instantiation instead of a factory method. Consider implementing a factory method like other entities for consistency and better validation:

-    it("should create a user with valid properties", () => {
-      const user = new User()
-      user.name = "John"
-      user.lastName = "Doe"
-      user.email = "[email protected]"
-      user.password = "hashedPassword"
-      user.wallet = "GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
-      user.isVerified = false
+    it("should create a user with valid properties", () => {
+      const userProps = {
+        name: "John",
+        lastName: "Doe", 
+        email: "[email protected]",
+        password: "hashedPassword",
+        wallet: "GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
+      }
+      const user = User.create(userProps)

This would also enable adding validation tests for required fields and invalid inputs.

src/modules/nft/domain/entities/nft.entity.ts (2)

49-51: Add validation and business logic to updateMetadata.

The updateMetadata method lacks validation and doesn't check if the NFT is minted before allowing updates.

Consider adding validation and business logic:

   public updateMetadata(metadataUri: string): void {
+    if (!this.isMinted) {
+      throw new Error("Cannot update metadata for unminted NFT")
+    }
+
+    if (!metadataUri || !metadataUri.trim()) {
+      throw new Error("Metadata URI cannot be empty")
+    }
+
     this.metadataUri = metadataUri
   }

58-67: Clarify the purpose of NFTDomain class and consider deprecation strategy.

Having both NFT and NFTDomain classes in the same file could cause confusion. The comment mentions it's kept for use cases, but this dual structure needs clearer documentation.

Consider adding deprecation notice or clearer documentation:

 // Keep the simple domain class for use cases
+/**
+ * @deprecated This class is maintained for backward compatibility with existing use cases.
+ * New code should use the NFT entity class instead.
+ * TODO: Migrate use cases to use the NFT entity and remove this class.
+ */
 export class NFTDomain {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8444abe and b53ecbd.

⛔ Files ignored due to path filters (3)
  • .DS_Store is excluded by !**/.DS_Store
  • package-lock.json is excluded by !**/package-lock.json
  • src/.DS_Store is excluded by !**/.DS_Store
📒 Files selected for processing (40)
  • package.json (1 hunks)
  • src/config/prisma.ts (1 hunks)
  • src/entities/BaseEntity.ts (0 hunks)
  • src/entities/NFT.ts (0 hunks)
  • src/entities/Organization.ts (0 hunks)
  • src/entities/Photo.ts (0 hunks)
  • src/entities/Project.ts (0 hunks)
  • src/entities/TestItem.ts (0 hunks)
  • src/entities/User.ts (0 hunks)
  • src/entities/Volunteer.ts (0 hunks)
  • src/entities/userVolunteer.entity.ts (0 hunks)
  • src/modules/nft/__tests__/domain/entities/nft.entity.test.ts (1 hunks)
  • src/modules/nft/domain/entities/nft.entity.ts (1 hunks)
  • src/modules/organization/domain/entities/organization.entity.ts (3 hunks)
  • src/modules/photo/__tests__/domain/entities/photo.entity.test.ts (1 hunks)
  • src/modules/photo/__tests__/photo.entity.test.ts (0 hunks)
  • src/modules/photo/domain/entities/photo.entity.ts (1 hunks)
  • src/modules/photo/entities/photo.entity.ts (1 hunks)
  • src/modules/project/__tests__/domain/entities/project.entity.test.ts (1 hunks)
  • src/modules/project/domain/Project.ts (1 hunks)
  • src/modules/project/domain/entities/project.entity.ts (1 hunks)
  • src/modules/shared/__tests__/domain/entities/test-item.entity.test.ts (1 hunks)
  • src/modules/shared/domain/entities/base.entity.ts (1 hunks)
  • src/modules/shared/domain/entities/test-item.entity.ts (1 hunks)
  • src/modules/user/__tests__/domain/entities/user-volunteer.entity.test.ts (1 hunks)
  • src/modules/user/__tests__/domain/entities/user.entity.test.ts (1 hunks)
  • src/modules/user/__tests__/user.test.ts (2 hunks)
  • src/modules/user/domain/entities/User.entity.ts (1 hunks)
  • src/modules/user/domain/entities/User.ts (1 hunks)
  • src/modules/user/domain/entities/user-volunteer.entity.ts (1 hunks)
  • src/modules/user/use-cases/userUseCase.ts (1 hunks)
  • src/modules/volunteer/__tests__/domain/volunteer.entity.test.ts (3 hunks)
  • src/modules/volunteer/domain/entities/volunteer.entity.ts (1 hunks)
  • src/modules/volunteer/domain/volunteer.entity.ts (0 hunks)
  • src/modules/volunteer/repositories/implementations/volunteer-prisma.repository.ts (1 hunks)
  • src/modules/volunteer/repositories/interfaces/volunteer-repository.interface.ts (1 hunks)
  • src/modules/volunteer/use-cases/create-volunteer.use-case.ts (1 hunks)
  • src/modules/volunteer/use-cases/get-volunteers-by-project.use-case.ts (1 hunks)
  • src/modules/volunteer/use-cases/update-volunteer.use-case.ts (1 hunks)
  • src/services/VolunteerService.ts (1 hunks)
💤 Files with no reviewable changes (11)
  • src/entities/Project.ts
  • src/entities/Volunteer.ts
  • src/entities/BaseEntity.ts
  • src/entities/NFT.ts
  • src/entities/Organization.ts
  • src/entities/User.ts
  • src/entities/Photo.ts
  • src/entities/TestItem.ts
  • src/modules/photo/tests/photo.entity.test.ts
  • src/entities/userVolunteer.entity.ts
  • src/modules/volunteer/domain/volunteer.entity.ts
🧰 Additional context used
🧬 Code Graph Analysis (4)
src/modules/photo/domain/entities/photo.entity.ts (1)
src/modules/user/domain/entities/User.entity.ts (1)
  • Entity (3-31)
src/modules/nft/__tests__/domain/entities/nft.entity.test.ts (1)
src/modules/organization/domain/entities/organization.entity.ts (1)
  • Organization (17-72)
src/modules/project/__tests__/domain/entities/project.entity.test.ts (1)
src/modules/project/domain/Project.ts (1)
  • Project (20-60)
src/modules/nft/domain/entities/nft.entity.ts (2)
src/modules/user/domain/entities/User.entity.ts (1)
  • Entity (3-31)
src/modules/organization/domain/entities/organization.entity.ts (1)
  • Organization (17-72)
🔇 Additional comments (27)
package.json (1)

72-75: ESLint & @typescript-eslint versions are compatible
@typescript-eslint/[email protected] and @typescript-eslint/[email protected] both declare a peerDependency of "eslint": "^8.57.0 || ^9.0.0", so using eslint@^9.30.0 is valid—no need to downgrade ESLint or move to a non-existent v9 of the TypeScript-ESLint packages.

Please note:

  • package.json lines 72–75: version alignment is already correct.
  • package.json line 86: there’s a "typescript-eslint": "^8.22.0" entry—there’s no such npm package, so remove it if it was added unintentionally.

Optionally, you may bump both @typescript-eslint packages to the latest v8.x (currently 8.35.0) for the newest bug fixes.

Likely an incorrect or invalid review comment.

src/modules/volunteer/use-cases/create-volunteer.use-case.ts (1)

1-1: Import path update looks correct
The new path reflects the relocation to domain/entities; compilation should succeed.

src/modules/volunteer/use-cases/update-volunteer.use-case.ts (1)

1-1: Import path update confirmed
No further action required.

src/modules/volunteer/use-cases/get-volunteers-by-project.use-case.ts (1)

1-1: Import path update verified
The change is minimal and correct.

src/modules/user/use-cases/userUseCase.ts (1)

13-19: Bypassing entity factory may skip validations
Instantiating new User() directly circumvents any invariants enforced by a User.create() factory method introduced in the refactor. Prefer the factory for consistency and validation.

src/modules/volunteer/repositories/implementations/volunteer-prisma.repository.ts (1)

2-2: Import path update acknowledged
No issues detected.

src/modules/volunteer/repositories/interfaces/volunteer-repository.interface.ts (1)

1-1: Import path correctly updated for entity relocation.

The import path update properly reflects the new directory structure where entities are organized under domain/entities/. This change aligns with the DDD refactoring objectives.

src/services/VolunteerService.ts (1)

1-1: Import path correctly updated for entity relocation.

The import path update properly reflects the new entity location. The service correctly uses the entity's domain methods (like update() on line 53), which demonstrates good domain-driven design.

src/modules/user/__tests__/user.test.ts (1)

1-62: Code formatting improvements enhance consistency.

The removal of trailing semicolons and standardization of line endings improves code consistency. The test logic remains unchanged and properly covers user CRUD operations with appropriate setup/teardown.

src/modules/volunteer/__tests__/domain/volunteer.entity.test.ts (2)

1-1: Import path correctly updated for entity relocation.

The import path update properly reflects the new nested directory structure for entities.


96-102: Excellent addition of validation testing for update method.

The new test case ensures that the entity's update() method properly validates input data and throws appropriate errors for invalid values. This strengthens the test coverage for domain validation logic.

src/modules/user/domain/entities/User.ts (1)

1-2: Clean re-export proxy pattern approved

  • Verified that src/modules/user/domain/entities/User.entity.ts exists.
  • Confirmed it contains the full TypeORM entity definition with @Entity, @PrimaryGeneratedColumn, @Column decorators.

No further changes are needed.

src/modules/user/__tests__/domain/entities/user-volunteer.entity.test.ts (1)

1-64: Well-structured test suite with good DDD practices.

The test suite effectively covers the core functionality of the UserVolunteer entity with clear separation of concerns and proper use of factory methods.

src/modules/photo/__tests__/domain/entities/photo.entity.test.ts (2)

1-118: Excellent comprehensive test suite with robust validation.

This test suite demonstrates excellent coverage of the Photo entity's functionality, including proper validation, metadata management, and serialization. The URL validation is particularly well-implemented, covering both HTTP and HTTPS protocols and invalid formats.


88-99: Well-designed metadata merging test.

The test properly verifies that metadata updates merge with existing metadata without overwriting, which is crucial for maintaining data integrity.

src/modules/shared/__tests__/domain/entities/test-item.entity.test.ts (1)

1-90: Well-structured test suite with comprehensive validation coverage.

The TestItem entity tests demonstrate good practices with thorough validation testing, including edge cases like whitespace-only names and zero values. The business logic methods are properly tested with clear expectations.

src/modules/photo/entities/photo.entity.ts (1)

1-2: Excellent architectural improvement following DDD principles.

The refactoring to re-export from the domain layer centralizes entity logic and improves code organization while maintaining backward compatibility. This pattern aligns well with Domain-Driven Design principles.

src/modules/organization/domain/entities/organization.entity.ts (1)

52-71: LGTM: Proper immutable update pattern.

The update method correctly preserves entity identity by including the current id and creates a new instance with updated properties. This immutable approach is excellent for domain entities.

src/modules/project/__tests__/domain/entities/project.entity.test.ts (1)

31-81: Excellent test coverage for domain behavior.

The test suite comprehensively covers:

  • Status transitions with validation
  • Error conditions with specific error messages
  • Status check methods
  • Business rule enforcement

This demonstrates good domain-driven design testing practices.

src/modules/shared/domain/entities/test-item.entity.ts (2)

16-35: Excellent validation and factory method implementation.

The static create method demonstrates good domain validation practices:

  • Input validation with specific error messages
  • Clear business rules enforcement
  • Proper entity instantiation

The validation logic is comprehensive and user-friendly.


37-46: Well-designed domain methods.

The domain methods maintain consistency with the validation rules established in the factory method. The updateValue method properly validates input, and incrementAge provides a clear domain operation.

src/modules/nft/__tests__/domain/entities/nft.entity.test.ts (1)

43-81: Comprehensive NFT domain behavior testing.

The test suite effectively covers:

  • Minting functionality with validation
  • Error handling for invalid operations
  • Metadata management
  • Ownership verification

This provides good confidence in the NFT entity's domain logic.

src/modules/user/domain/entities/User.entity.ts (1)

8-30: Well-designed column structure for user domain.

The column definitions demonstrate good domain modeling:

  • Appropriate unique constraints on email and wallet
  • Sensible defaults for verification status
  • Proper nullable fields for verification workflow
  • Clear field types and constraints
src/modules/project/domain/Project.ts (1)

1-60: LGTM! Clean domain model implementation.

The formatting improvements and domain model structure follow good DDD practices with private constructor, factory method, and proper encapsulation of domain logic.

src/modules/shared/domain/entities/base.entity.ts (1)

3-12: LGTM! Clean TypeORM base entity.

The TypeORM decorators properly handle common entity fields with automatic UUID generation and timestamp management.

src/modules/project/domain/entities/project.entity.ts (1)

1-74: Excellent domain entity implementation!

This is a well-designed TypeORM entity that properly encapsulates business logic:

  • Clean status transition management with proper validation
  • Good use of enum for type safety
  • Appropriate error handling for invalid state transitions
  • Clear domain methods that enforce business rules

The implementation follows DDD principles effectively.

src/modules/volunteer/domain/entities/volunteer.entity.ts (1)

41-52: Well-implemented factory method pattern.

The static create method properly validates inputs before constructing the entity, following good domain-driven design practices.

Copy link
Member

@Villarley Villarley left a comment

Choose a reason for hiding this comment

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

LGTM

@Villarley Villarley merged commit 4589688 into VolunChain:main Jul 8, 2025
1 of 2 checks passed
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.

Relocate All Entities to Their Corresponding Modules (domain/entities)

2 participants