Complete the code to import the TypeORM module in a NestJS module.
import { Module } from '@nestjs/common'; import { TypeOrmModule } from '[1]'; @Module({ imports: [TypeOrmModule.forRoot()], }) export class AppModule {}
You import TypeOrmModule from @nestjs/typeorm to use TypeORM in NestJS.
Complete the code to configure the TypeORM connection with a PostgreSQL database.
TypeOrmModule.forRoot({
type: '[1]',
host: 'localhost',
port: 5432,
username: 'user',
password: 'pass',
database: 'testdb',
entities: [],
synchronize: true,
})The type property should be set to postgres for a PostgreSQL database.
Fix the error in the entities array to include the User entity correctly.
import { User } from './user.entity'; TypeOrmModule.forRoot({ type: 'postgres', host: 'localhost', port: 5432, username: 'user', password: 'pass', database: 'testdb', entities: [[1]], synchronize: true, })
The entities array should contain the class reference User, not a string.
Fill both blanks to import and register the User entity in the feature module.
import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { [1] } from './user.entity'; @Module({ imports: [TypeOrmModule.forFeature([[2]])], }) export class UserModule {}
You import the User class and register it in forFeature using the same class name.
Fill all three blanks to inject the UserRepository and use it in the service constructor.
import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { [1] } from './user.entity'; @Injectable() export class UserService { constructor( @InjectRepository([2]) private readonly [3]: Repository<User>, ) {} }
You import the User entity, inject its repository with @InjectRepository(User), and name the repository variable userRepository.