From 12513e496790ab9652518ac56ac4b048c749232f Mon Sep 17 00:00:00 2001 From: Mahdi Date: Wed, 5 Aug 2026 22:24:20 +0330 Subject: [PATCH] Allow SMS send with negative balance; only block switch stops sending. Co-authored-by: Cursor --- src/sms/sms.service.ts | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/sms/sms.service.ts b/src/sms/sms.service.ts index 9f4aac3..0d02a2d 100644 --- a/src/sms/sms.service.ts +++ b/src/sms/sms.service.ts @@ -1,8 +1,6 @@ import { BadRequestException, ForbiddenException, - HttpException, - HttpStatus, Injectable, NotFoundException, } from '@nestjs/common'; @@ -256,11 +254,12 @@ export class SmsService { let reason: string | null = null; let allowed = true; + // Only the explicit block switch stops sending (parity with Hamkar/Khanegi panels). + // Negative / low balance is allowed; UI can still show balanceLevel as warning. if (account.isBlocked && !isAlert) { allowed = false; reason = 'blocked'; } else if (!isAlert && account.balanceRials < estimatedCostRials) { - allowed = false; reason = 'insufficient_balance'; } @@ -306,18 +305,7 @@ export class SmsService { const costRials = parts * account.pricePerPartRials; - if (!isAlert && account.balanceRials < costRials) { - throw new HttpException( - { - message: 'موجودی کیف پول پیامک کافی نیست', - reason: 'insufficient_balance', - balanceRials: account.balanceRials, - costRials, - }, - HttpStatus.PAYMENT_REQUIRED, - ); - } - + // Allow negative wallet (same as product panels): only isBlocked stops send/consume. const nextBalance = account.balanceRials - costRials; const updated = await tx.smsAccount.update({