OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

TypeError: Repository method is not a function (NestJS / TypeORM)

  • Thread starter Thread starter Noniq
  • Start date Start date
N

Noniq

Guest
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

Code:
@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

Code:
@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;
    }
}

<p>I'm working with NestJS and TypeORM. When trying to call the createMailLogEntry method of the repository, I'm getting the following error: <code>TypeError: this.mailLogEntryRepository.createMailLogEntry is not a function</code></p>

<p>I can't figure out what's going wrong.</p>

<p><strong>mailing.service.ts</strong></p>

<pre><code>@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,
});
}
}
}
</code></pre>

<p><strong>mail-log-entry.repository.ts</strong></p>

<pre><code>@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;
}
}
</code></pre>
 
Top