Browse Source

chore(api): update billing permission check logic

pull/58/head
isra el 12 months ago
parent
commit
39296aa06b
  1. 35
      api/src/gateway/gateway.service.ts

35
api/src/gateway/gateway.service.ts

@ -115,12 +115,6 @@ export class GatewayService {
const message = smsData.message || smsData.smsBody const message = smsData.message || smsData.smsBody
const recipients = smsData.recipients || smsData.receivers const recipients = smsData.recipients || smsData.receivers
await this.billingService.canPerformAction(
device.user.toString(),
'send_sms',
recipients.length,
)
if (!message) { if (!message) {
throw new HttpException( 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 // TODO: Implement a queue to send the SMS if recipients are too many
let smsBatch: SMSBatch 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 ( if (
!Array.isArray(body.messages) || !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 { messageTemplate, messages } = body
const smsBatch = await this.smsBatchModel.create({ const smsBatch = await this.smsBatchModel.create({
@ -381,12 +382,6 @@ export class GatewayService {
) )
} }
await this.billingService.canPerformAction(
device.user.toString(),
'receive_sms',
1,
)
if ( if (
(!dto.receivedAt && !dto.receivedAtInMillis) || (!dto.receivedAt && !dto.receivedAtInMillis) ||
!dto.sender || !dto.sender ||
@ -402,6 +397,12 @@ export class GatewayService {
) )
} }
await this.billingService.canPerformAction(
device.user.toString(),
'receive_sms',
1,
)
const receivedAt = dto.receivedAtInMillis const receivedAt = dto.receivedAtInMillis
? new Date(dto.receivedAtInMillis) ? new Date(dto.receivedAtInMillis)
: dto.receivedAt : dto.receivedAt

Loading…
Cancel
Save