Estoy aprendiendo a usar NestJS, to me estaba marchando bien hasta que me apareció un error, y sinceramente no encontré respuestas contundentes que me dieran una solución, cuando trato de correr mediante npm run start:dev
me aparece este error, estuve buscando soluciones pero no encuentro alguna.
[ExceptionHandler] Nest can't resolve dependencies of the userRepository (?). Please make sure that the argument Connection at index [0] is available in the TypeOrmModule context.
Error: Nest can't resolve dependencies of the userRepository (?). Please make sure that the argument Connection at index [0] is available in the TypeOrmModule context.
Potential solutions:
- If Connection is a provider, is it part of the current TypeOrmModule?
- If Connection is exported from a separate @Module, is that module imported within TypeOrmModule?
+
user.module
@Module({
imports: [
TypeOrmModule.forFeature([user])
],
controllers: [UserController],
providers: [UserService, ]
})
export class UserModule {}
user.service
@Injectable()
export class UserService {
constructor(
@InjectRepository(user)
private readonly userRepository: Repository<user>
){}
async getMany(){
return await this.userRepository.find()
}
async getOne(id: number){
const user = await this.userRepository.findOne(id);
if(!user) throw new NotFoundException ('User doesnt exist')
return user;
}
async createOne(dto: CreateUserDto){
const newUser = this.userRepository.create(dto)
return await this.userRepository.save(newUser)
}
async editOne(){}
async deleteOne(){}
}