mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-01 17:03:27 +00:00
30 lines
956 B
TypeScript
30 lines
956 B
TypeScript
import { Inject, Injectable, Logger, OnApplicationBootstrap } from '@nestjs/common';
|
|
import { ClientProxy } from '@nestjs/microservices';
|
|
import { SendEmail } from './dtos/email.dto';
|
|
|
|
@Injectable()
|
|
export class EmailClientService implements OnApplicationBootstrap {
|
|
private readonly logger = new Logger(EmailClientService.name);
|
|
|
|
constructor(
|
|
@Inject('EMAIL_SERVICE')
|
|
private readonly emailServiceClient: ClientProxy,
|
|
) {}
|
|
|
|
private readonly enabled = process.env.RABBITMQ_ENABLED !== 'false';
|
|
|
|
async onApplicationBootstrap() {
|
|
if (!this.enabled) return;
|
|
this.emailServiceClient
|
|
.connect()
|
|
.then(() => this.logger.log('Connected to Email service'))
|
|
.catch((err) => this.logger.error('Error connecting to Email service', err));
|
|
}
|
|
|
|
async sendEmail(dto: SendEmail) {
|
|
if (!this.enabled) return {};
|
|
this.emailServiceClient.emit('send-email', { ...dto, appKey: 'EDR-PASSENGER-API' });
|
|
return {};
|
|
}
|
|
}
|