Skip to content

TypeOrm entity loading#200

Open
Chinandrs11 wants to merge 1 commit intoStarShopCr:mainfrom
Chinandrs11:feat/typeORM_entity_loading
Open

TypeOrm entity loading#200
Chinandrs11 wants to merge 1 commit intoStarShopCr:mainfrom
Chinandrs11:feat/typeORM_entity_loading

Conversation

@Chinandrs11
Copy link

@Chinandrs11 Chinandrs11 commented Sep 30, 2025

🚀 StarShop Pull Request – Issue #198

Mark with an x all the checkboxes that apply (like [x]).

✅ Checklist

  • Closes TypeORM Entity Loading Optimization #198
  • Added tests (e2e: escrow listing, balances, validation)
  • Run tests (attach screenshot of npm run test:e2e)
  • Run formatting (npm run format / npm run lint:fix)
  • Evidence attached (add screenshots below)
  • Commented the code (service + controller additions)

📌 Type of Change

  • Documentation (README: Escrow Indexer Queries section)
  • Bug fix
  • Enhancement (new escrow querying + balances polling support)
  • Breaking change

📝 Changes Description

Implemented entitys loading

⏰ Time Spent Breakdown

1 hour

Summary by CodeRabbit

  • Refactor
    • Updated database configuration to load entities within individual feature modules instead of a central list.
    • Connection options and logging unchanged; schema synchronization remains disabled.
    • No changes to endpoints, UI, or data; application behavior remains the same across all features.
    • No migrations, downtime, or user action required.

@coderabbitai
Copy link

coderabbitai bot commented Sep 30, 2025

Walkthrough

Removed the centralized TypeORM entities array from TypeOrmModule.forRoot in AppModule. Entities are now expected to be registered via TypeOrmModule.forFeature within feature modules. Connection options (e.g., synchronize=false, logging) remain unchanged.

Changes

Cohort / File(s) Summary
TypeORM bootstrapping
src/app.module.ts
Dropped global entities array from TypeOrmModule.forRoot; shifts entity registration to per-module TypeOrmModule.forFeature. Other connection options unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant N as NestJS Runtime
  participant A as AppModule
  participant T as TypeOrmModule.forRoot
  participant F as FeatureModule(s)
  participant R as Repository Providers

  N->>A: Bootstrap application
  A->>T: Initialize DB connection (no global entities)
  Note right of T: Connection opts unchanged<br/>synchronize=false, logging as before
  A-->>F: Load feature modules
  F->>T: TypeOrmModule.forFeature(EntityX, EntityY, ...)
  T-->>R: Register repositories for feature entities
  N-->>F: Inject repositories into services/controllers
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

I twitched my whiskers, flipped a switch,
From one big list to modules rich.
Entities hop to where they live,
Repos nibble, features give.
Fewer carrots in one pot—
Now each garden grows its lot. 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title concisely identifies the core focus of the pull request—how TypeORM entities are loaded—without unnecessary noise or unrelated information.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (5)
src/app.module.ts (5)

21-21: Critical: Duplicate EscrowModule import will cause a runtime error.

EscrowModule is imported twice at lines 19 and 21, and also added to the imports array twice at lines 78 and 80. Additionally, there's an EscrowsModule imported at line 50 and added at line 82. This suggests a conflict between two different escrow implementations.

Remove the duplicate imports and determine which escrow module should be used:

 import { OffersModule } from './modules/offers/offers.module';
-import { EscrowModule } from './modules/escrow/escrow.module';
 import { SupabaseModule } from './modules/supabase/supabase.module';
 import { EscrowModule } from './modules/escrow/escrow.module';

And in the imports array:

     OffersModule,
     EscrowModule,
     SupabaseModule,
-  EscrowModule,
     StoresModule,
     EscrowsModule,

Note: Verify whether you need both EscrowModule and EscrowsModule, or if one should be removed entirely.

Also applies to: 80-80


45-45: Critical: Duplicate Escrow entity imports from different paths.

Escrow entity is imported from both ./modules/escrow/entities/escrow.entity (line 45) and ./modules/escrows/entities/escrow.entity (line 48). This will cause a naming conflict and prevent the file from compiling.

Remove one of the duplicate imports after determining which escrow implementation is correct:

-import { Escrow } from './modules/escrow/entities/escrow.entity';
 import { EscrowFundingTx } from './modules/escrow/entities/escrow-funding-tx.entity';
 import { Store } from './modules/stores/entities/store.entity';
 import { Escrow } from './modules/escrows/entities/escrow.entity';

Also applies to: 48-48


44-44: Critical: Duplicate Milestone entity imports from different paths.

Milestone entity is imported from both ./modules/escrow/entities/milestone.entity (line 44) and ./modules/escrows/entities/milestone.entity (line 49). This creates a naming conflict.

Remove one of the duplicate imports:

-import { Milestone } from './modules/escrow/entities/milestone.entity';
 import { Escrow } from './modules/escrow/entities/escrow.entity';
 import { EscrowFundingTx } from './modules/escrow/entities/escrow-funding-tx.entity';
 import { Store } from './modules/stores/entities/store.entity';
 import { Escrow } from './modules/escrows/entities/escrow.entity';
 import { Milestone } from './modules/escrows/entities/milestone.entity';

Also applies to: 49-49


25-50: Remove unused entity imports.

All entity imports (lines 25-50) are now unused since entities are loaded via TypeOrmModule.forFeature in feature modules. These unused imports add unnecessary clutter and increase the module's parsing time.

As per coding guidelines, remove all unused imports:

-// Entities
-import { User } from './modules/users/entities/user.entity';
-import { Order } from './modules/orders/entities/order.entity';
-import { OrderItem } from './modules/orders/entities/order-item.entity';
-import { UserRole } from './modules/auth/entities/user-role.entity';
-import { Role } from './modules/auth/entities/role.entity';
-import { Notification } from './modules/notifications/entities/notification.entity';
-import { Wishlist } from './modules/wishlist/entities/wishlist.entity';
-import { Product } from './modules/products/entities/product.entity';
-import { ProductType } from './modules/productTypes/entities/productTypes.entity';
-import { ProductVariant } from './modules/productVariants/entities/productVariants.entity';
-import { Attribute } from './modules/attributes/entities/attribute.entity';
-import { AttributeValue } from './modules/attributes/entities/attribute-value.entity';
-import { Coupon } from './modules/coupons/entities/coupon.entity';
-import { CouponUsage } from './modules/coupons/entities/coupon-usage.entity';
-import { BuyerRequest } from './modules/buyer-requests/entities/buyer-request.entity';
-import { Offer } from './modules/offers/entities/offer.entity';
-import { OfferAttachment } from './modules/offers/entities/offer-attachment.entity';
-import { EscrowAccount } from './modules/escrow/entities/escrow-account.entity';
-import { Milestone } from './modules/escrow/entities/milestone.entity';
-import { Escrow } from './modules/escrow/entities/escrow.entity';
-import { EscrowFundingTx } from './modules/escrow/entities/escrow-funding-tx.entity';
-import { Store } from './modules/stores/entities/store.entity';
-import { Escrow } from './modules/escrows/entities/escrow.entity';
-import { Milestone } from './modules/escrows/entities/milestone.entity';
-import { EscrowsModule } from './modules/escrows/escrows.module';

57-64: Add missing TypeOrmModule.forFeature import in notifications module
The notifications feature module currently lacks a TypeOrmModule.forFeature([...]) call, so its entities aren’t registered and their repositories will fail at runtime. In src/modules/notifications/notifications.module.ts, add:

imports: [
  TypeOrmModule.forFeature([NotificationEntity /*, …other entities*/]),
  // …other imports
],
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b80d6d8 and ff87925.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • src/app.module.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/**/*.ts

📄 CodeRabbit inference engine (.cursorrules)

src/**/*.ts: Do not access environment variables via process.env directly; import and use the config object from src/config/env
Provide explicit return types for all functions
Do not use the any type; use unknown or specific types instead
Create interfaces for complex object shapes
Type all function parameters explicitly
Do not use console.log; use proper logging (e.g., NestJS Logger)
Remove unused imports
Do not leave commented-out code in commits
Wrap risky operations in try-catch and handle errors appropriately
Add JSDoc comments for complex logic

Files:

  • src/app.module.ts
🧠 Learnings (1)
📚 Learning: 2025-09-29T16:06:54.363Z
Learnt from: CR
PR: StarShopCr/StarShop-Backend#0
File: .cursorrules:0-0
Timestamp: 2025-09-29T16:06:54.363Z
Learning: Applies to src/modules/**/entities/**/*.entity.ts : Define persistence entities in entities/*.entity.ts

Applied to files:

  • src/app.module.ts

Comment on lines 59 to 60
url: process.env.DATABASE_URL,
ssl: process.env.DB_SSL === 'true' ? { rejectUnauthorized: false } : undefined,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Replace direct process.env access with config object.

Direct access to process.env violates the coding guidelines. Environment variables should be accessed via the config object from src/config/env.

As per coding guidelines, import and use the config object:

+import { config } from './config/env';
+
 import './config/crypto-global';
 import { Module } from '@nestjs/common';

Then update the TypeOrmModule configuration:

     TypeOrmModule.forRoot({
       type: 'postgres',
-      url: process.env.DATABASE_URL,
-      ssl: process.env.DB_SSL === 'true' ? { rejectUnauthorized: false } : undefined,
+      url: config.DATABASE_URL,
+      ssl: config.DB_SSL === 'true' ? { rejectUnauthorized: false } : undefined,
   // entities property removed for modularization. Now entities are loaded via TypeOrmModule.forFeature in each feature module.
       synchronize: false,
-      logging: process.env.NODE_ENV === 'development',
+      logging: config.NODE_ENV === 'development',
     }),

Also applies to: 63-63

🤖 Prompt for AI Agents
In src/app.module.ts around lines 59-60 (also apply to line 63), replace direct
process.env usage with the project's config object from src/config/env: import
the config instance at the top of the file, then use config.get('DATABASE_URL')
in place of process.env.DATABASE_URL and use config.get('DB_SSL') === 'true' (or
a boolean helper from the config if available) to decide the ssl value instead
of process.env.DB_SSL; update the TypeOrmModule configuration accordingly so ssl
is set to { rejectUnauthorized: false } when the config indicates true and
undefined otherwise, and make the same replacement for the other occurrence on
line 63.

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.

TypeORM Entity Loading Optimization

1 participant