diff --git a/apps/edr-passenger-api/src/modules/notifications/dtos/sms.dto.ts b/apps/edr-passenger-api/src/modules/notifications/dtos/sms.dto.ts index 2841597fc..e50cf6c64 100644 --- a/apps/edr-passenger-api/src/modules/notifications/dtos/sms.dto.ts +++ b/apps/edr-passenger-api/src/modules/notifications/dtos/sms.dto.ts @@ -19,6 +19,24 @@ export class SendMessage { from?: string; } +export class SingleMessageDto { + @ApiProperty({ + description: 'Recipient phone number', + example: '+1234567890', + }) + @IsString() + @IsNotEmpty() + to: string; + + @ApiProperty({ + description: 'Message content', + example: 'Test Single SMS from', + }) + @IsString() + @IsNotEmpty() + sms: string; +} + export class BulkMessagesDto { @ApiProperty({ type: [SendMessage] }) @IsArray() diff --git a/apps/edr-passenger-api/src/modules/notifications/email-client.service.ts b/apps/edr-passenger-api/src/modules/notifications/email-client.service.ts index f925920cb..34879ed0a 100644 --- a/apps/edr-passenger-api/src/modules/notifications/email-client.service.ts +++ b/apps/edr-passenger-api/src/modules/notifications/email-client.service.ts @@ -1,29 +1,39 @@ -import { Inject, Injectable, Logger, OnApplicationBootstrap } from '@nestjs/common'; -import { ClientProxy } from '@nestjs/microservices'; -import { SendEmail } from './dtos/email.dto'; +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') + @Inject("EMAIL_SERVICE") private readonly emailServiceClient: ClientProxy, ) {} - private readonly enabled = process.env.RABBITMQ_ENABLED !== 'false'; + 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)); + .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' }); + this.emailServiceClient.emit("send-email", { + ...dto, + appKey: "IFHCRS-LICENSE-MANAGEMENT", + }); return {}; } } diff --git a/apps/edr-passenger-api/src/modules/notifications/notifications.controller.ts b/apps/edr-passenger-api/src/modules/notifications/notifications.controller.ts index 0b7798a04..b622e3b7d 100644 --- a/apps/edr-passenger-api/src/modules/notifications/notifications.controller.ts +++ b/apps/edr-passenger-api/src/modules/notifications/notifications.controller.ts @@ -7,7 +7,7 @@ import { TestNotificationDto } from './notifications.dto'; import { EmailClientService } from './email-client.service'; import { SmsClientService } from './sms-client.service'; import { SendEmail } from './dtos/email.dto'; -import { BulkMessagesDto, SendMessage } from './dtos/sms.dto'; +import { BulkMessagesDto, SingleMessageDto } from './dtos/sms.dto'; @ApiTags('Notifications') @Controller('notifications') @@ -51,8 +51,8 @@ export class NotificationsController { @UseGuards(IamGuard) @IamRoles('ADMIN', 'STAFF') @ApiOperation({ summary: 'Send a direct SMS via the SMS microservice' }) - @ApiBody({ type: SendMessage }) - sendSms(@Body() dto: SendMessage) { + @ApiBody({ type: SingleMessageDto }) + sendSms(@Body() dto: SingleMessageDto) { return this.smsClient.sendSms(dto); } diff --git a/apps/edr-passenger-api/src/modules/notifications/notifications.service.ts b/apps/edr-passenger-api/src/modules/notifications/notifications.service.ts index 595633e93..8960f1a87 100644 --- a/apps/edr-passenger-api/src/modules/notifications/notifications.service.ts +++ b/apps/edr-passenger-api/src/modules/notifications/notifications.service.ts @@ -21,7 +21,7 @@ export class NotificationsService { ) { this.channels = new Map([ ['EMAIL', { send: (to, subject, body) => this.emailClient.sendEmail({ to, subject, text: body }).then(() => true) }], - ['SMS', { send: (to, _subject, body) => this.smsClient.sendSms({ to, message: body }).then(() => true) }], + ['SMS', { send: (to, _subject, body) => this.smsClient.sendSms({ to, sms: body }).then(() => true) }], ['PUSH', this.pushAdapter as NotificationChannel], ]); } diff --git a/apps/edr-passenger-api/src/modules/notifications/sms-client.service.ts b/apps/edr-passenger-api/src/modules/notifications/sms-client.service.ts index 7b18212cb..ef2758686 100644 --- a/apps/edr-passenger-api/src/modules/notifications/sms-client.service.ts +++ b/apps/edr-passenger-api/src/modules/notifications/sms-client.service.ts @@ -3,42 +3,48 @@ import { Injectable, Logger, OnApplicationBootstrap, -} from '@nestjs/common'; -import { ClientProxy } from '@nestjs/microservices'; -import { BulkMessagesDto, SendMessage } from './dtos/sms.dto'; +} from "@nestjs/common"; +import { ClientProxy } from "@nestjs/microservices"; +import { BulkMessagesDto, SingleMessageDto } from "./dtos/sms.dto"; @Injectable() export class SmsClientService implements OnApplicationBootstrap { private readonly logger = new Logger(SmsClientService.name); constructor( - @Inject('SMS_SERVICE') + @Inject("SMS_SERVICE") private smsClient: ClientProxy, ) {} - private readonly enabled = process.env.RABBITMQ_ENABLED !== 'false'; + private readonly enabled = process.env.RABBITMQ_ENABLED !== "false"; async onApplicationBootstrap() { if (!this.enabled) return; this.smsClient .connect() .then(() => { - this.logger.log('connected to SMS service'); + this.logger.log("connected to SMS service"); }) .catch((err) => { - console.error('Error happened at SMS service', err); + console.error("Error happened at SMS service", err); }); } - async sendSms(dto: SendMessage) { + async sendSms(dto: SingleMessageDto) { if (!this.enabled) return {}; - this.smsClient.emit('send-sms', { ...dto, appKey: 'EDR-PASSENGER-API' }); + this.smsClient.emit("send-sms", { + ...dto, + appKey: "IFHCRS-LICENSE-MANAGEMENT", + }); return {}; } async sendBulkMessages(dto: BulkMessagesDto) { if (!this.enabled) return {}; - this.smsClient.emit('ozeking-bulk-sms', { ...dto, appKey: 'EDR-PASSENGER-API' }); + this.smsClient.emit("ozeking-bulk-sms", { + ...dto, + appKey: "IFHCRS-LICENSE-MANAGEMENT", + }); return {}; } }