mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
40 lines
1006 B
TypeScript
40 lines
1006 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: "IFHCRS-LICENSE-MANAGEMENT",
|
|
});
|
|
return {};
|
|
}
|
|
}
|