Sha*_*oon 7 node.js sequelize.js nestjs
我有:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
我收到这个奇怪的错误:
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 */ ]
})
Run Code Online (Sandbox Code Playgroud)
ConversationModule是:
import { Module } from '@nestjs/common';
import { ConversationsController } from './conversations.controller';
import { ConversationsService } from './conversations.service';
@Module({
controllers: [ConversationsController],
providers: [ConversationsService]
})
export class ConversationsModule {}
Run Code Online (Sandbox Code Playgroud)
不确定ConversationRepository指的是什么。
您需要将 添加到SequelizeModule.forFeature()您的ConversationModule数组中imports,以告诉 Nest 在该模块的上下文中,我可以访问ConversationRepository. 该术语是从 TypeORM 借用的,与 TypeO 一样,您有实体和存储库,而在 Sequelize 中,您有模型和表,但总体想法是相同的。你的应该ConverstationModule看起来像这样:
@Module({
imports: [SequelizeModule.forFeature([Conversation])],
providers: [ConversationService],
controllers: [ConversationController]
})
export class ConversationModule {}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8713 次 |
| 最近记录: |