Rename services
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
|
||||
import { SendMailOptions } from 'nodemailer';
|
||||
|
||||
import { MessageQueue } from 'src/integrations/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/integrations/message-queue/services/message-queue.service';
|
||||
import { EmailJob } from 'src/integrations/email/email.job';
|
||||
|
||||
@Injectable()
|
||||
export class EmailJobService {
|
||||
constructor(
|
||||
@Inject(MessageQueue.emailQueue)
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
) {}
|
||||
|
||||
async send(sendMailOptions: SendMailOptions): Promise<void> {
|
||||
await this.messageQueueService.add<SendMailOptions>(
|
||||
EmailJob.name,
|
||||
sendMailOptions,
|
||||
{ retryLimit: 3 },
|
||||
);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -4,15 +4,15 @@ import { SendMailOptions } from 'nodemailer';
|
||||
|
||||
import { MessageQueueJob } from 'src/integrations/message-queue/interfaces/message-queue-job.interface';
|
||||
|
||||
import { EmailService } from 'src/integrations/email/email.service';
|
||||
import { EmailSenderService } from 'src/integrations/email/email-sender.service';
|
||||
|
||||
@Injectable()
|
||||
export class EmailJob implements MessageQueueJob<SendMailOptions> {
|
||||
constructor(private readonly emailService: EmailService) {}
|
||||
export class EmailSenderJob implements MessageQueueJob<SendMailOptions> {
|
||||
constructor(private readonly emailSenderService: EmailSenderService) {}
|
||||
|
||||
async handle(data: SendMailOptions): Promise<void> {
|
||||
console.log('sending email', data);
|
||||
await this.emailService.send(data);
|
||||
await this.emailSenderService.send(data);
|
||||
console.log('done');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
|
||||
import { SendMailOptions } from 'nodemailer';
|
||||
|
||||
import { EmailDriver } from 'src/integrations/email/drivers/interfaces/email-driver.interface';
|
||||
|
||||
import { EMAIL_DRIVER } from 'src/integrations/email/email.constants';
|
||||
|
||||
@Injectable()
|
||||
export class EmailSenderService implements EmailDriver {
|
||||
constructor(@Inject(EMAIL_DRIVER) private driver: EmailDriver) {}
|
||||
|
||||
async send(sendMailOptions: SendMailOptions): Promise<void> {
|
||||
await this.driver.send(sendMailOptions);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import { EMAIL_DRIVER } from 'src/integrations/email/email.constants';
|
||||
import { LoggerDriver } from 'src/integrations/email/drivers/logger.driver';
|
||||
import { SmtpDriver } from 'src/integrations/email/drivers/smtp.driver';
|
||||
import { EmailService } from 'src/integrations/email/email.service';
|
||||
import { EmailJobService } from 'src/integrations/email/email-job.service';
|
||||
import { EmailSenderService } from 'src/integrations/email/email-sender.service';
|
||||
|
||||
@Global()
|
||||
export class EmailModule {
|
||||
@@ -23,8 +23,8 @@ export class EmailModule {
|
||||
|
||||
return {
|
||||
module: EmailModule,
|
||||
providers: [EmailService, EmailJobService, provider],
|
||||
exports: [EmailService, EmailJobService],
|
||||
providers: [EmailSenderService, EmailService, provider],
|
||||
exports: [EmailSenderService, EmailService],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,22 @@ import { Inject, Injectable } from '@nestjs/common';
|
||||
|
||||
import { SendMailOptions } from 'nodemailer';
|
||||
|
||||
import { EmailDriver } from 'src/integrations/email/drivers/interfaces/email-driver.interface';
|
||||
|
||||
import { EMAIL_DRIVER } from 'src/integrations/email/email.constants';
|
||||
import { MessageQueue } from 'src/integrations/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/integrations/message-queue/services/message-queue.service';
|
||||
import { EmailSenderJob } from 'src/integrations/email/email-sender.job';
|
||||
|
||||
@Injectable()
|
||||
export class EmailService implements EmailDriver {
|
||||
constructor(@Inject(EMAIL_DRIVER) private driver: EmailDriver) {}
|
||||
export class EmailService {
|
||||
constructor(
|
||||
@Inject(MessageQueue.emailQueue)
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
) {}
|
||||
|
||||
async send(sendMailOptions: SendMailOptions): Promise<void> {
|
||||
await this.driver.send(sendMailOptions);
|
||||
await this.messageQueueService.add<SendMailOptions>(
|
||||
EmailSenderJob.name,
|
||||
sendMailOptions,
|
||||
{ retryLimit: 3 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import { ObjectMetadataModule } from 'src/metadata/object-metadata/object-metada
|
||||
import { DataSourceModule } from 'src/metadata/data-source/data-source.module';
|
||||
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';
|
||||
import { FetchWorkspaceMessagesModule } from 'src/workspace/messaging/services/fetch-workspace-messages.module';
|
||||
import { EmailJob } from 'src/integrations/email/email.job';
|
||||
import { EmailSenderJob } from 'src/integrations/email/email-sender.job';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -35,8 +35,8 @@ import { EmailJob } from 'src/integrations/email/email.job';
|
||||
useClass: CallWebhookJob,
|
||||
},
|
||||
{
|
||||
provide: EmailJob.name,
|
||||
useClass: EmailJob,
|
||||
provide: EmailSenderJob.name,
|
||||
useClass: EmailSenderJob,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
@@ -2,13 +2,13 @@ import { Command, CommandRunner } from 'nest-commander';
|
||||
import { render } from '@react-email/render';
|
||||
|
||||
import CleanInactiveWorkspaceEmail from 'src/workspace/emails/clean-inactive-workspace.email';
|
||||
import { EmailJobService } from 'src/integrations/email/email-job.service';
|
||||
import { EmailService } from 'src/integrations/email/email.service';
|
||||
|
||||
@Command({
|
||||
name: 'test-send-email',
|
||||
})
|
||||
export class TotoCommand extends CommandRunner {
|
||||
constructor(private readonly emailJobService: EmailJobService) {
|
||||
constructor(private readonly emailService: EmailService) {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ export class TotoCommand extends CommandRunner {
|
||||
const html = render(CleanInactiveWorkspaceEmail(), { pretty: true });
|
||||
const text = render(CleanInactiveWorkspaceEmail(), { plainText: true });
|
||||
|
||||
await this.emailJobService.send({ to: 'martmull@hotmail.fr', html, text });
|
||||
await this.emailService.send({ to: 'martmull@hotmail.fr', html, text });
|
||||
//await this.emailService.send({ to: 'martmull@hotmail.fr', html, text });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user