Allow SMS send with negative balance; only block switch stops sending.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+3
-15
@@ -1,8 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
ForbiddenException,
|
ForbiddenException,
|
||||||
HttpException,
|
|
||||||
HttpStatus,
|
|
||||||
Injectable,
|
Injectable,
|
||||||
NotFoundException,
|
NotFoundException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
@@ -256,11 +254,12 @@ export class SmsService {
|
|||||||
let reason: string | null = null;
|
let reason: string | null = null;
|
||||||
let allowed = true;
|
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) {
|
if (account.isBlocked && !isAlert) {
|
||||||
allowed = false;
|
allowed = false;
|
||||||
reason = 'blocked';
|
reason = 'blocked';
|
||||||
} else if (!isAlert && account.balanceRials < estimatedCostRials) {
|
} else if (!isAlert && account.balanceRials < estimatedCostRials) {
|
||||||
allowed = false;
|
|
||||||
reason = 'insufficient_balance';
|
reason = 'insufficient_balance';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,18 +305,7 @@ export class SmsService {
|
|||||||
|
|
||||||
const costRials = parts * account.pricePerPartRials;
|
const costRials = parts * account.pricePerPartRials;
|
||||||
|
|
||||||
if (!isAlert && account.balanceRials < costRials) {
|
// Allow negative wallet (same as product panels): only isBlocked stops send/consume.
|
||||||
throw new HttpException(
|
|
||||||
{
|
|
||||||
message: 'موجودی کیف پول پیامک کافی نیست',
|
|
||||||
reason: 'insufficient_balance',
|
|
||||||
balanceRials: account.balanceRials,
|
|
||||||
costRials,
|
|
||||||
},
|
|
||||||
HttpStatus.PAYMENT_REQUIRED,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const nextBalance = account.balanceRials - costRials;
|
const nextBalance = account.balanceRials - costRials;
|
||||||
|
|
||||||
const updated = await tx.smsAccount.update({
|
const updated = await tx.smsAccount.update({
|
||||||
|
|||||||
Reference in New Issue
Block a user