diff --git a/apps/edr-freight-api/src/modules/notifications/notifications.module.ts b/apps/edr-freight-api/src/modules/notifications/notifications.module.ts index 2ff2f9727..70e00c9ac 100644 --- a/apps/edr-freight-api/src/modules/notifications/notifications.module.ts +++ b/apps/edr-freight-api/src/modules/notifications/notifications.module.ts @@ -1,14 +1,14 @@ import { Module } from "@nestjs/common"; +import { ConfigModule } from "@nestjs/config"; import { NotificationsService } from "./notifications.service"; import { EmailNotificationStrategy } from "./strategies/notification.email.strategy"; import { SmsNotificationStrategy } from "./strategies/notification.sms.strategy"; -import { HttpModule } from "@nestjs/axios"; @Module({ - imports: [HttpModule], + imports: [ConfigModule], controllers: [], providers: [EmailNotificationStrategy, SmsNotificationStrategy, NotificationsService], exports: [NotificationsService], }) -export class NotificationsModule { } +export class NotificationsModule {} diff --git a/apps/edr-freight-api/src/modules/notifications/strategies/notification.sms.strategy.ts b/apps/edr-freight-api/src/modules/notifications/strategies/notification.sms.strategy.ts index d77aac350..127eae5cd 100644 --- a/apps/edr-freight-api/src/modules/notifications/strategies/notification.sms.strategy.ts +++ b/apps/edr-freight-api/src/modules/notifications/strategies/notification.sms.strategy.ts @@ -1,28 +1,36 @@ -import { Injectable} from "@nestjs/common"; -import { NotificationStrategy } from "./notification.strategy"; -import { HttpService } from '@nestjs/axios'; +import { Injectable } from "@nestjs/common"; import { ConfigService } from "@nestjs/config"; -import { firstValueFrom } from 'rxjs'; +import axios from "axios"; + +import { NotificationStrategy } from "./notification.strategy"; @Injectable() export class SmsNotificationStrategy implements NotificationStrategy { - constructor(private readonly httpService: HttpService, private readonly configService: ConfigService) { } - async send(recipient: string, message: string) { - const url = this.configService.get("OZIKING_SMS_URL"); - const body = { - to: recipient, - sourceId: this.configService.get("OZIKING_SOURCE_ID") ?? "EDR", - sourceName: this.configService.get("OZIKING_SOURCE_NAME") ?? "EDR Freight", - appKey: this.configService.get("OZIKING_APP_KEY") ?? "", - text: message, - callbackUrl: "", - }; - const response = await firstValueFrom( - this.httpService.post(url, body, { - headers: { accept: "*/*", "Content-Type": "application/json" }, - }), - ); + constructor(private readonly configService: ConfigService) {} - return response.status === 201; - } + async send(recipient: string, message: string): Promise { + const url = + this.configService.get("OZIKING_SMS_URL") ?? + "https://notification-dev.license.aafda.gov.et/api/sms-services/ozeking/sms"; + + await axios.post( + url, + { + to: recipient, + sourceId: this.configService.get("OZIKING_SOURCE_ID") ?? "EDR", + sourceName: this.configService.get("OZIKING_SOURCE_NAME") ?? "EDR Freight", + appKey: this.configService.get("OZIKING_APP_KEY") ?? "", + text: message, + callbackUrl: "", + }, + { + headers: { + accept: "*/*", + "Content-Type": "application/json", + }, + }, + ); + + return true; + } }