mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 05:18:11 +00:00
Merge branch 'alpha' of https://github.com/Tria-plc/edr-platform into alpha
This commit is contained in:
@@ -11,7 +11,10 @@ export class EmailClientService implements OnApplicationBootstrap {
|
||||
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'))
|
||||
@@ -19,10 +22,8 @@ export class EmailClientService implements OnApplicationBootstrap {
|
||||
}
|
||||
|
||||
async sendEmail(dto: SendEmail) {
|
||||
this.emailServiceClient.emit('send-email', {
|
||||
...dto,
|
||||
appKey: 'EDR-PASSENGER-API',
|
||||
});
|
||||
if (!this.enabled) return {};
|
||||
this.emailServiceClient.emit('send-email', { ...dto, appKey: 'EDR-PASSENGER-API' });
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { DynamicModule, Module } from '@nestjs/common';
|
||||
import { HttpModule } from '@nestjs/axios';
|
||||
import { ClientsModule, Transport } from '@nestjs/microservices';
|
||||
import { NotificationsController } from './notifications.controller';
|
||||
@@ -38,17 +38,37 @@ import { SmsClientService } from './sms-client.service';
|
||||
queueOptions: { durable: true },
|
||||
},
|
||||
},
|
||||
]),
|
||||
],
|
||||
controllers: [NotificationsController],
|
||||
providers: [
|
||||
NotificationsService,
|
||||
EmailAdapter,
|
||||
SmsAdapter,
|
||||
PushAdapter,
|
||||
EmailClientService,
|
||||
SmsClientService,
|
||||
],
|
||||
exports: [NotificationsService, EmailClientService, SmsClientService],
|
||||
})
|
||||
export class NotificationsModule {}
|
||||
}),
|
||||
},
|
||||
]);
|
||||
|
||||
@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],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,10 @@ export class SmsClientService implements OnApplicationBootstrap {
|
||||
private smsClient: ClientProxy,
|
||||
) {}
|
||||
|
||||
private readonly enabled = process.env.RABBITMQ_ENABLED !== 'false';
|
||||
|
||||
async onApplicationBootstrap() {
|
||||
if (!this.enabled) return;
|
||||
this.smsClient
|
||||
.connect()
|
||||
.then(() => {
|
||||
@@ -28,18 +31,14 @@ export class SmsClientService implements OnApplicationBootstrap {
|
||||
}
|
||||
|
||||
async sendSms(dto: SendMessage) {
|
||||
this.smsClient.emit('send-sms', {
|
||||
...dto,
|
||||
appKey: 'EDR-PASSENGER-API',
|
||||
});
|
||||
if (!this.enabled) return {};
|
||||
this.smsClient.emit('send-sms', { ...dto, appKey: 'EDR-PASSENGER-API' });
|
||||
return {};
|
||||
}
|
||||
|
||||
async sendBulkMessages(dto: BulkMessagesDto) {
|
||||
this.smsClient.emit('ozeking-bulk-sms', {
|
||||
...dto,
|
||||
appKey: 'EDR-PASSENGER-API',
|
||||
});
|
||||
if (!this.enabled) return {};
|
||||
this.smsClient.emit('ozeking-bulk-sms', { ...dto, appKey: 'EDR-PASSENGER-API' });
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user