forked from Yara724/api
sms logging in mongo part was added
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Injectable, Logger, OnModuleInit } from "@nestjs/common";
|
||||
import { SmsSendLogService } from "../entities/db-service/sms-send-log.service";
|
||||
import { KavenegarSmsGateway } from "./kavenegar-sms.gateway";
|
||||
import { ParsianSmsGateway } from "./parsian-sms.gateway";
|
||||
import { getSmsProvider } from "./sms-provider.config";
|
||||
@@ -13,6 +14,7 @@ export class SmsGatewayService implements OnModuleInit {
|
||||
constructor(
|
||||
private readonly kavenegar: KavenegarSmsGateway,
|
||||
private readonly parsian: ParsianSmsGateway,
|
||||
private readonly smsSendLogService: SmsSendLogService,
|
||||
) {}
|
||||
|
||||
onModuleInit() {
|
||||
@@ -20,11 +22,43 @@ export class SmsGatewayService implements OnModuleInit {
|
||||
}
|
||||
|
||||
async sendMessage(data: SendMessage) {
|
||||
return this.activeGateway().sendMessage(data);
|
||||
const startedAt = Date.now();
|
||||
try {
|
||||
const result = await this.activeGateway().sendMessage(data);
|
||||
await this.smsSendLogService.recordGatewaySend({
|
||||
data,
|
||||
startedAt,
|
||||
result,
|
||||
});
|
||||
return result;
|
||||
} catch (error) {
|
||||
await this.smsSendLogService.recordGatewaySend({
|
||||
data,
|
||||
startedAt,
|
||||
error,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async verifyLookUp(data: VerifyLookUpMessage) {
|
||||
return this.activeGateway().verifyLookUp(data);
|
||||
const startedAt = Date.now();
|
||||
try {
|
||||
const result = await this.activeGateway().verifyLookUp(data);
|
||||
await this.smsSendLogService.recordGatewayVerifyLookup({
|
||||
data,
|
||||
startedAt,
|
||||
result,
|
||||
});
|
||||
return result;
|
||||
} catch (error) {
|
||||
await this.smsSendLogService.recordGatewayVerifyLookup({
|
||||
data,
|
||||
startedAt,
|
||||
error,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
private activeGateway(): KavenegarSmsGateway | ParsianSmsGateway {
|
||||
|
||||
Reference in New Issue
Block a user