Allow turning SMS blocking off even when the wallet is empty.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-26 10:48:07 +03:30
co-authored by Cursor
parent e5bb1c1c52
commit d0122ab08b
2 changed files with 10 additions and 49 deletions
+5 -23
View File
@@ -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;
}
};