From d0122ab08bd47c690cf0fe0d586d25b81a825345 Mon Sep 17 00:00:00 2001 From: adonis Date: Sat, 26 Sep 2026 10:48:07 +0330 Subject: [PATCH] Allow turning SMS blocking off even when the wallet is empty. Co-authored-by: Cursor --- runtime/server.cjs | 28 +++++----------------------- src/sms/sms-wallet.service.ts | 31 +++++-------------------------- 2 files changed, 10 insertions(+), 49 deletions(-) diff --git a/runtime/server.cjs b/runtime/server.cjs index c77f7ff..3ec52a1 100644 --- a/runtime/server.cjs +++ b/runtime/server.cjs @@ -128790,15 +128790,6 @@ var require_sms_wallet_service = __commonJS({ } async canSend() { const wallet = await this.ensure(); - if (wallet.balanceToman <= 0) { - if (!wallet.blocked) { - await this.prisma.smsWallet.update({ - where: { id: WALLET_ID }, - data: { blocked: true } - }); - } - return false; - } return !wallet.blocked; } async recordSend(parts) { @@ -128808,11 +128799,12 @@ var require_sms_wallet_service = __commonJS({ const wallet = await this.ensure(tx); const costToman = parts * wallet.pricePerPart; const balanceToman = wallet.balanceToman - costToman; + const crossedToEmpty = wallet.balanceToman > 0 && balanceToman <= 0; await tx.smsWallet.update({ where: { id: WALLET_ID }, data: { balanceToman, - blocked: balanceToman <= 0 ? true : wallet.blocked + blocked: crossedToEmpty ? true : wallet.blocked } }); await tx.smsUsage.create({ data: { parts, costToman } }); @@ -128823,7 +128815,7 @@ var require_sms_wallet_service = __commonJS({ return { balanceToman: wallet.balanceToman, balanceRial: wallet.balanceToman * TOMAN_TO_RIAL, - blocked: wallet.blocked || wallet.balanceToman <= 0, + blocked: wallet.blocked, yellowThreshold: wallet.yellowThreshold, redThreshold: wallet.redThreshold, deposit: { @@ -128884,12 +128876,8 @@ var require_sms_wallet_service = __commonJS({ if (yellow < red) { throw new common_12.BadRequestException("\u0622\u0633\u062A\u0627\u0646\u0647 \u0632\u0631\u062F \u0628\u0627\u06CC\u062F \u0628\u0632\u0631\u06AF\u200C\u062A\u0631 \u06CC\u0627 \u0645\u0633\u0627\u0648\u06CC \u0622\u0633\u062A\u0627\u0646\u0647 \u0642\u0631\u0645\u0632 \u0628\u0627\u0634\u062F"); } - if (dto.blocked != null) { - if (dto.blocked === false && wallet.balanceToman <= 0) { - throw new common_12.BadRequestException("\u0628\u0627 \u0645\u0648\u062C\u0648\u062F\u06CC \u0635\u0641\u0631 \u06CC\u0627 \u0645\u0646\u0641\u06CC\u060C \u0645\u0633\u062F\u0648\u062F\u0633\u0627\u0632\u06CC \u0628\u0631\u062F\u0627\u0634\u062A\u0647 \u0646\u0645\u06CC\u200C\u0634\u0648\u062F"); - } + if (dto.blocked != null) data.blocked = dto.blocked; - } if (Object.keys(data).length) { await this.prisma.smsWallet.update({ where: { id: WALLET_ID }, data }); } @@ -128904,7 +128892,7 @@ var require_sms_wallet_service = __commonJS({ where: { id: WALLET_ID }, data: { balanceToman, - blocked: balanceToman <= 0 ? true : wasBroke ? false : wallet.blocked + blocked: balanceToman > 0 && wasBroke ? false : wallet.blocked } }), this.prisma.smsTopUp.create({ @@ -128922,12 +128910,6 @@ var require_sms_wallet_service = __commonJS({ update: {}, create: { id: WALLET_ID } }); - if (wallet.balanceToman <= 0 && !wallet.blocked) { - return db.smsWallet.update({ - where: { id: WALLET_ID }, - data: { blocked: true } - }); - } return wallet; } }; diff --git a/src/sms/sms-wallet.service.ts b/src/sms/sms-wallet.service.ts index e5a2539..5f874c9 100644 --- a/src/sms/sms-wallet.service.ts +++ b/src/sms/sms-wallet.service.ts @@ -57,15 +57,6 @@ export class SmsWalletService { async canSend(): Promise { const wallet = await this.ensure(); - if (wallet.balanceToman <= 0) { - if (!wallet.blocked) { - await this.prisma.smsWallet.update({ - where: { id: WALLET_ID }, - data: { blocked: true }, - }); - } - return false; - } return !wallet.blocked; } @@ -76,11 +67,12 @@ export class SmsWalletService { const wallet = await this.ensure(tx); const costToman = parts * wallet.pricePerPart; const balanceToman = wallet.balanceToman - costToman; + const crossedToEmpty = wallet.balanceToman > 0 && balanceToman <= 0; await tx.smsWallet.update({ where: { id: WALLET_ID }, data: { balanceToman, - blocked: balanceToman <= 0 ? true : wallet.blocked, + blocked: crossedToEmpty ? true : wallet.blocked, }, }); await tx.smsUsage.create({ data: { parts, costToman } }); @@ -92,7 +84,7 @@ export class SmsWalletService { return { balanceToman: wallet.balanceToman, balanceRial: wallet.balanceToman * TOMAN_TO_RIAL, - blocked: wallet.blocked || wallet.balanceToman <= 0, + blocked: wallet.blocked, yellowThreshold: wallet.yellowThreshold, redThreshold: wallet.redThreshold, deposit: { @@ -159,14 +151,7 @@ export class SmsWalletService { throw new BadRequestException('آستانه زرد باید بزرگ‌تر یا مساوی آستانه قرمز باشد'); } - if (dto.blocked != null) { - if (dto.blocked === false && wallet.balanceToman <= 0) { - throw new BadRequestException( - 'با موجودی صفر یا منفی، مسدودسازی برداشته نمی‌شود', - ); - } - data.blocked = dto.blocked; - } + if (dto.blocked != null) data.blocked = dto.blocked; if (Object.keys(data).length) { await this.prisma.smsWallet.update({ where: { id: WALLET_ID }, data }); @@ -183,7 +168,7 @@ export class SmsWalletService { where: { id: WALLET_ID }, data: { balanceToman, - blocked: balanceToman <= 0 ? true : wasBroke ? false : wallet.blocked, + blocked: balanceToman > 0 && wasBroke ? false : wallet.blocked, }, }), this.prisma.smsTopUp.create({ @@ -202,12 +187,6 @@ export class SmsWalletService { update: {}, create: { id: WALLET_ID }, }); - if (wallet.balanceToman <= 0 && !wallet.blocked) { - return db.smsWallet.update({ - where: { id: WALLET_ID }, - data: { blocked: true }, - }); - } return wallet; } }