diff --git a/package-lock.json b/package-lock.json index 4b8f7a7..13e9074 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1110,6 +1110,14 @@ "@sinonjs/commons": "^1.7.0" } }, + "@types/axios": { + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/@types/axios/-/axios-0.14.0.tgz", + "integrity": "sha1-7CMA++fX3d1+udOr+HmZlkyvzkY=", + "requires": { + "axios": "*" + } + }, "@types/babel__core": { "version": "7.1.14", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.14.tgz", diff --git a/package.json b/package.json index b2a22ae..25a0876 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "@nestjs/common": "^7.5.1", "@nestjs/core": "^7.5.1", "@nestjs/platform-express": "^7.5.1", + "@types/axios": "^0.14.0", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", "rxjs": "^6.6.3" diff --git a/src/channels/http/http.channel.ts b/src/channels/http/http.channel.ts index 474ee58..f4f7890 100644 --- a/src/channels/http/http.channel.ts +++ b/src/channels/http/http.channel.ts @@ -5,19 +5,21 @@ import { } from '@nestjs/common'; import { HttpNotification } from './http-notification.interface'; import { NestJsNotificationChannel } from '../notification-channel.interface'; +import { AxiosResponse } from 'axios'; @Injectable() export class HttpChannel implements NestJsNotificationChannel { - constructor(private readonly httpService: HttpService) {} /** * Send the given notification * @param notification */ - public async send(notification: HttpNotification): Promise { + public async send( + notification: HttpNotification, + ): Promise> { const message = this.getData(notification); - await this.httpService.post(notification.httpUrl(), message).toPromise(); + return this.httpService.post(notification.httpUrl(), message).toPromise(); } /** diff --git a/src/channels/notification-channel.interface.ts b/src/channels/notification-channel.interface.ts index 9d1dd29..f40e69a 100644 --- a/src/channels/notification-channel.interface.ts +++ b/src/channels/notification-channel.interface.ts @@ -5,5 +5,5 @@ export interface NestJsNotificationChannel { * Send the given notification * @param notification */ - send(notification: NestJsNotification): Promise; + send(notification: NestJsNotification): Promise; } diff --git a/src/channels/sendgrid/sendgrid.channel.ts b/src/channels/sendgrid/sendgrid.channel.ts index 066b0d3..5480c11 100644 --- a/src/channels/sendgrid/sendgrid.channel.ts +++ b/src/channels/sendgrid/sendgrid.channel.ts @@ -6,6 +6,7 @@ import { import { SendGridNotification } from './sendgrid-notification.interface'; import { NestJsNotificationChannel } from '../notification-channel.interface'; import { SendGridApiUrl } from './constants'; +import { AxiosResponse } from 'axios'; @Injectable() export class SendGridChannel implements NestJsNotificationChannel { @@ -15,9 +16,11 @@ export class SendGridChannel implements NestJsNotificationChannel { * Send the given notification * @param notification */ - public async send(notification: SendGridNotification): Promise { + public async send( + notification: SendGridNotification, + ): Promise> { const data = this.getData(notification); - await this.httpService + return this.httpService .post(SendGridApiUrl, data, { headers: { Authorization: notification.sendGridApiKey(),