Bird
0
0

Consider this custom repository definition in NestJS:

medium📝 Debug Q7 of 15
NestJS - Database with TypeORM
Consider this custom repository definition in NestJS:
@EntityRepository(Product)
export class ProductRepository extends Repository {
  findAvailable() {
    return this.find({ where: { available: true } });
  }
}

What is the main issue with this code in the context of recent TypeORM and NestJS versions?
AThe @EntityRepository decorator is deprecated and should not be used.
BThe findAvailable method should be static to be accessible.
CThe class must implement an interface to extend Repository.
DThe method findAvailable should return a Promise explicitly.
Step-by-Step Solution
Solution:
  1. Step 1: Check @EntityRepository Usage

    Recent TypeORM versions have deprecated @EntityRepository decorator.
  2. Step 2: Recommended Approach

    Custom repositories should now be implemented as regular classes and injected manually or use DataSource.getRepository.
  3. Final Answer:

    The @EntityRepository decorator is deprecated and should not be used. -> Option A
  4. Quick Check:

    @EntityRepository is deprecated in latest TypeORM versions. [OK]
Quick Trick: @EntityRepository is deprecated; use DataSource or custom providers [OK]
Common Mistakes:
  • Assuming @EntityRepository is still recommended
  • Thinking methods must be static
  • Forgetting to return Promise explicitly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes