diff --git a/api/src/gateway/gateway.service.ts b/api/src/gateway/gateway.service.ts index 31d1f8d..100d95a 100644 --- a/api/src/gateway/gateway.service.ts +++ b/api/src/gateway/gateway.service.ts @@ -115,12 +115,6 @@ export class GatewayService { const message = smsData.message || smsData.smsBody const recipients = smsData.recipients || smsData.receivers - await this.billingService.canPerformAction( - device.user.toString(), - 'send_sms', - recipients.length, - ) - if (!message) { throw new HttpException( { @@ -141,6 +135,12 @@ export class GatewayService { ) } + await this.billingService.canPerformAction( + device.user.toString(), + 'send_sms', + recipients.length, + ) + // TODO: Implement a queue to send the SMS if recipients are too many let smsBatch: SMSBatch @@ -249,11 +249,6 @@ export class GatewayService { ) } - await this.billingService.canPerformAction( - device.user.toString(), - 'bulk_send_sms', - body.messages.map((m) => m.recipients).flat().length, - ) if ( !Array.isArray(body.messages) || @@ -269,6 +264,12 @@ export class GatewayService { ) } + await this.billingService.canPerformAction( + device.user.toString(), + 'bulk_send_sms', + body.messages.map((m) => m.recipients).flat().length, + ) + const { messageTemplate, messages } = body const smsBatch = await this.smsBatchModel.create({ @@ -381,12 +382,6 @@ export class GatewayService { ) } - await this.billingService.canPerformAction( - device.user.toString(), - 'receive_sms', - 1, - ) - if ( (!dto.receivedAt && !dto.receivedAtInMillis) || !dto.sender || @@ -402,6 +397,12 @@ export class GatewayService { ) } + await this.billingService.canPerformAction( + device.user.toString(), + 'receive_sms', + 1, + ) + const receivedAt = dto.receivedAtInMillis ? new Date(dto.receivedAtInMillis) : dto.receivedAt