Reputation: 43569
I have:
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/sequelize';
import { Conversation } from './conversation.model'
import { FindConversationsDto } from '../dto/conversations.find'
@Injectable()
export class ConversationsService {
constructor(
@InjectModel(Conversation)
private conversationModel: typeof Conversation
) { }
async findConversations(queryParams: FindConversationsDto): Promise<Conversation[]> {
return new Promise((resolve) => [])
// return await this.conversationModel.findAll();
}
}
And I get this weird error:
Nest can't resolve dependencies of the ConversationsService (?). Please make sure that the argument ConversationRepository at index [0] is available in the ConversationsModule context.
Potential solutions:
- If ConversationRepository is a provider, is it part of the current ConversationsModule?
- If ConversationRepository is exported from a separate @Module, is that module imported within ConversationsModule?
@Module({
imports: [ /* the Module containing ConversationRepository */ ]
})
ConversationModule
is:
import { Module } from '@nestjs/common';
import { ConversationsController } from './conversations.controller';
import { ConversationsService } from './conversations.service';
@Module({
controllers: [ConversationsController],
providers: [ConversationsService]
})
export class ConversationsModule {}
Not sure what ConversationRepository
is referring to.
Upvotes: 7
Views: 9125
Reputation: 70450
You need to add in the SequelizeModule.forFeature()
to your ConversationModule
's imports
array, to tell Nest that in the context of this module, I have access to the ConversationRepository
. The terminology is borrowed from TypeORM, as with TypeO you have Entities and Repositories, but whereas with Sequelize you have Models and Tables, but the ideas are the same overall. Your ConverstationModule
should probably look something like this:
@Module({
imports: [SequelizeModule.forFeature([Conversation])],
providers: [ConversationService],
controllers: [ConversationController]
})
export class ConversationModule {}
Upvotes: 6