mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 16:28:12 +00:00
29 lines
1.2 KiB
TypeScript
29 lines
1.2 KiB
TypeScript
import { Injectable, Logger } from "@nestjs/common";
|
|
import { NotificationStrategy } from "./notification.strategy";
|
|
import { EmailClientService } from "../email-client.service";
|
|
|
|
@Injectable()
|
|
export class EmailNotificationStrategy implements NotificationStrategy {
|
|
private readonly logger = new Logger(EmailNotificationStrategy.name);
|
|
constructor(private readonly emailClient: EmailClientService) { }
|
|
async send(recipient: string, message: string): Promise<boolean> {
|
|
try {
|
|
// Route through the shared email client (RabbitMQ hand-off). `queued`
|
|
// reflects whether the message was accepted for delivery; a false or
|
|
// a thrown result is a real failure the caller must observe.
|
|
const { queued } = await this.emailClient.sendEmail({
|
|
to: recipient,
|
|
subject: "EDR Freight notification",
|
|
text: message,
|
|
});
|
|
return queued;
|
|
} catch (err) {
|
|
this.logger.error(
|
|
`Failed to send email to ${recipient}: ${err instanceof Error ? err.message : String(err)}`,
|
|
err instanceof Error ? err.stack : undefined,
|
|
);
|
|
return false;
|
|
}
|
|
}
|
|
}
|