Complete the code to import the Repository class from TypeORM.
import { [1] } from 'typeorm';
The Repository class is imported from typeorm to use the repository pattern in NestJS.
Complete the code to inject the repository for the User entity using @InjectRepository.
constructor(@InjectRepository([1]) private userRepository: Repository<User>) {}The @InjectRepository decorator takes the entity class, here User, to inject its repository.
Fix the error in the method to find a user by id using the repository.
async findUserById(id: number): Promise<User | null> {
return await this.userRepository.[1]({ id });
}The correct method to find one entity by id in TypeORM repository is findOne.
Fill both blanks to create a new user entity and save it using the repository.
const newUser = this.userRepository.[1](userData); await this.userRepository.[2](newUser);
Use create to make a new entity instance and save to store it in the database.
Fill all three blanks to update a user's email by id using the repository.
await this.userRepository.[1]({ id: userId }, { [2]: [3] });
The update method takes a condition object and a partial entity with fields to update. Here, we update the email field to newEmail.