mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 02:00:56 +00:00
75 lines
2.2 KiB
TypeScript
75 lines
2.2 KiB
TypeScript
import { DynamicModule, Module } from '@nestjs/common';
|
|
import { HttpModule } from '@nestjs/axios';
|
|
import { ClientsModule, Transport } from '@nestjs/microservices';
|
|
import { NotificationsController } from './notifications.controller';
|
|
import { NotificationsService } from './notifications.service';
|
|
import { EmailAdapter, SmsAdapter, PushAdapter } from './notification.adapters';
|
|
import { EmailClientService } from './email-client.service';
|
|
import { SmsClientService } from './sms-client.service';
|
|
|
|
@Module({
|
|
imports: [
|
|
HttpModule.register({ timeout: 10_000 }),
|
|
ClientsModule.register([
|
|
{
|
|
name: 'SMS_SERVICE',
|
|
transport: Transport.RMQ,
|
|
options: {
|
|
urls: [process.env.RABBITMQ_URL as string],
|
|
queue: 'sms_queue',
|
|
queueOptions: { durable: true },
|
|
},
|
|
},
|
|
{
|
|
name: 'EMAIL_SERVICE',
|
|
transport: Transport.RMQ,
|
|
options: {
|
|
urls: [process.env.RABBITMQ_URL as string],
|
|
queue: 'email_queue',
|
|
queueOptions: { durable: true },
|
|
},
|
|
},
|
|
{
|
|
name: 'NOTIFICATION_SERVICE',
|
|
transport: Transport.RMQ,
|
|
options: {
|
|
urls: [process.env.RABBITMQ_URL as string],
|
|
queue: 'notification_queue',
|
|
queueOptions: { durable: true },
|
|
},
|
|
},
|
|
}),
|
|
},
|
|
]);
|
|
|
|
@Module({})
|
|
export class NotificationsModule {
|
|
static register(): DynamicModule {
|
|
const rmqEnabled = process.env.RABBITMQ_ENABLED !== 'false';
|
|
|
|
return {
|
|
module: NotificationsModule,
|
|
imports: [
|
|
HttpModule.register({ timeout: 10_000 }),
|
|
...(rmqEnabled ? [rmqClientsModule] : []),
|
|
],
|
|
controllers: [NotificationsController],
|
|
providers: [
|
|
NotificationsService,
|
|
EmailAdapter,
|
|
SmsAdapter,
|
|
PushAdapter,
|
|
...(rmqEnabled
|
|
? [EmailClientService, SmsClientService]
|
|
: [
|
|
{ provide: 'EMAIL_SERVICE', useValue: null },
|
|
{ provide: 'SMS_SERVICE', useValue: null },
|
|
EmailClientService,
|
|
SmsClientService,
|
|
]),
|
|
],
|
|
exports: [NotificationsService, EmailClientService, SmsClientService],
|
|
};
|
|
}
|
|
}
|