I'm working with NestJS and TypeORM. When trying to call the createMailLogEntry method of the repository, I'm getting the following error: TypeError: this.mailLogEntryRepository.createMailLogEntry is not a function
I can't figure out what's going wrong.
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,
});
}
}
}
mail-log-entry.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;
}
}
I came across this problem as well. Make sure you're importing the repository into the module.
Here's what your module should probably look like.
@Module({
imports: [TypeOrmModule.forFeature([TeamRepository])],
providers: [TeamService],
controllers: [TeamController]
})
export class TeamModule {}
I had the same problem, I'll tell you what got me out of it if it helps someone else!
If your repository is handmade (not generated by an ORM) then you can't use the Repository injection :

Instead just use the repository as you would for a service (just remove the @InjectRepository(People)):

I hope this will help!Happy coding !
PS : Personnes is my entity and the helper has nothing to do with the issue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With