gpt4 book ai didi

javascript - 类型错误 : Repository method is not a function (NestJS/TypeORM)

转载 作者:行者123 更新时间:2023-12-04 14:45:16 26 4
gpt4 key购买 nike

我正在使用 NestJS 和 TypeORM。尝试调用存储库的 createMailLogEntry 方法时,我收到以下错误:TypeError: this.mailLogEntryRepository.createMailLogEntry is not a function
我不知道出了什么问题。

mailing.service.ts

@Injectable()
export class MailingService {

constructor(@InjectRepository(MailLogEntryRepository) private mailLogEntryRepository: MailLogEntryRepository) { }

// ...

if(transferResult) {
await this.mailLogEntryRepository.createMailLogEntry({
creationDate: new Date(Date.now()),
from: mailContent.from,
to: mailContent.to,
subject: mailContent.subject,
text: mailContent.text,
html: mailContent.html,
cc: mailContent.cc,
bcc: mailContent.bcc,
});
}
}
}

邮件日志条目.repository.ts
@EntityRepository(MailLogEntry)
export class MailLogEntryRepository extends Repository<MailLogEntry> {

async createMailLogEntry(mailLogEntryDto: MailLogEntryDto): Promise<MailLogEntry> {
const mailLogEntry = MailLogEntryRepository.createMailLogEntryFromDto(mailLogEntryDto);
return await mailLogEntry.save();
}

private static createMailLogEntryFromDto(mailLogEntryDto: MailLogEntryDto): MailLogEntry {
const mailLogEntry = new MailLogEntry();
mailLogEntry.from = mailLogEntryDto.from;
mailLogEntry.to = mailLogEntryDto.to;
mailLogEntry.subject = mailLogEntryDto.subject;
mailLogEntry.text = mailLogEntryDto.text;
mailLogEntry.html = mailLogEntryDto.html;
mailLogEntry.cc = mailLogEntryDto.cc;
mailLogEntry.bcc = mailLogEntryDto.bcc;

return mailLogEntry;
}
}

最佳答案

我也遇到过这个问题。
确保将存储库导入到模块中。

这是您的模块应该看起来的样子。

@Module({
imports: [TypeOrmModule.forFeature([TeamRepository])],
providers: [TeamService],
controllers: [TeamController]
})
export class TeamModule {}

关于javascript - 类型错误 : Repository method is not a function (NestJS/TypeORM),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60777204/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com