Allow SMS send with negative balance; only block switch stops sending.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-05 22:24:20 +03:30
co-authored by Cursor
parent 17a54774ae
commit 12513e4967
+3 -15
View File
@@ -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({