0
0
NestJSframework~10 mins

Why TypeORM integrates seamlessly with NestJS - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the TypeORM module in a NestJS module.

NestJS
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '[1]';

@Module({
  imports: [TypeOrmModule.forRoot()],
})
export class AppModule {}
Drag options to blanks, or click blank then click option'
A@nestjs/typeorm
Btypeorm
C@nestjs/common
Dtypeorm-nest
Attempts:
3 left
💡 Hint
Common Mistakes
Importing directly from 'typeorm' instead of '@nestjs/typeorm'.
Using '@nestjs/common' which is unrelated to TypeORM integration.
2fill in blank
medium

Complete the code to register an entity with TypeORM in a NestJS module.

NestJS
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from './user.entity';

@Module({
  imports: [TypeOrmModule.forFeature([[1]])],
})
export class UsersModule {}
Drag options to blanks, or click blank then click option'
ATypeOrmModule
BUsersModule
CUser
DAppModule
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the module name instead of the entity.
Passing the TypeOrmModule itself.
3fill in blank
hard

Fix the error in the service constructor to inject the repository correctly.

NestJS
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { User } from './user.entity';

@Injectable()
export class UsersService {
  constructor(
    private readonly [1] repository: Repository<User>,
  ) {}
}
Drag options to blanks, or click blank then click option'
Arepository
B@InjectRepository()
CInjectRepository
D@InjectRepository(User)
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the decorator.
Using the decorator without specifying the entity.
Using the decorator as a type instead of a decorator.
4fill in blank
hard

Fill both blanks to configure TypeORM connection options in NestJS.

NestJS
TypeOrmModule.forRoot({
  type: '[1]',
  host: '[2]',
  port: 5432,
  username: 'user',
  password: 'pass',
  database: 'testdb',
  entities: [__dirname + '/**/*.entity{.ts,.js}'],
  synchronize: true,
})
Drag options to blanks, or click blank then click option'
Apostgres
Blocalhost
Cmysql
D127.0.0.1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'mysql' when the project uses PostgreSQL.
Using IP address instead of 'localhost' for host.
5fill in blank
hard

Fill all three blanks to create a repository method that finds a user by email.

NestJS
async findByEmail([1]: string): Promise<User | null> {
  return this.userRepository.[2]({ where: { [3] } });
}
Drag options to blanks, or click blank then click option'
Aemail
BfindOne
Dfind
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'find' instead of 'findOne' which returns an array.
Mismatching parameter and query key names.