Allow turning SMS blocking off even when the wallet is empty.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+5
-23
@@ -128790,15 +128790,6 @@ var require_sms_wallet_service = __commonJS({
|
|||||||
}
|
}
|
||||||
async canSend() {
|
async canSend() {
|
||||||
const wallet = await this.ensure();
|
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;
|
return !wallet.blocked;
|
||||||
}
|
}
|
||||||
async recordSend(parts) {
|
async recordSend(parts) {
|
||||||
@@ -128808,11 +128799,12 @@ var require_sms_wallet_service = __commonJS({
|
|||||||
const wallet = await this.ensure(tx);
|
const wallet = await this.ensure(tx);
|
||||||
const costToman = parts * wallet.pricePerPart;
|
const costToman = parts * wallet.pricePerPart;
|
||||||
const balanceToman = wallet.balanceToman - costToman;
|
const balanceToman = wallet.balanceToman - costToman;
|
||||||
|
const crossedToEmpty = wallet.balanceToman > 0 && balanceToman <= 0;
|
||||||
await tx.smsWallet.update({
|
await tx.smsWallet.update({
|
||||||
where: { id: WALLET_ID },
|
where: { id: WALLET_ID },
|
||||||
data: {
|
data: {
|
||||||
balanceToman,
|
balanceToman,
|
||||||
blocked: balanceToman <= 0 ? true : wallet.blocked
|
blocked: crossedToEmpty ? true : wallet.blocked
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await tx.smsUsage.create({ data: { parts, costToman } });
|
await tx.smsUsage.create({ data: { parts, costToman } });
|
||||||
@@ -128823,7 +128815,7 @@ var require_sms_wallet_service = __commonJS({
|
|||||||
return {
|
return {
|
||||||
balanceToman: wallet.balanceToman,
|
balanceToman: wallet.balanceToman,
|
||||||
balanceRial: wallet.balanceToman * TOMAN_TO_RIAL,
|
balanceRial: wallet.balanceToman * TOMAN_TO_RIAL,
|
||||||
blocked: wallet.blocked || wallet.balanceToman <= 0,
|
blocked: wallet.blocked,
|
||||||
yellowThreshold: wallet.yellowThreshold,
|
yellowThreshold: wallet.yellowThreshold,
|
||||||
redThreshold: wallet.redThreshold,
|
redThreshold: wallet.redThreshold,
|
||||||
deposit: {
|
deposit: {
|
||||||
@@ -128884,12 +128876,8 @@ var require_sms_wallet_service = __commonJS({
|
|||||||
if (yellow < red) {
|
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");
|
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 != 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");
|
|
||||||
}
|
|
||||||
data.blocked = dto.blocked;
|
data.blocked = dto.blocked;
|
||||||
}
|
|
||||||
if (Object.keys(data).length) {
|
if (Object.keys(data).length) {
|
||||||
await this.prisma.smsWallet.update({ where: { id: WALLET_ID }, data });
|
await this.prisma.smsWallet.update({ where: { id: WALLET_ID }, data });
|
||||||
}
|
}
|
||||||
@@ -128904,7 +128892,7 @@ var require_sms_wallet_service = __commonJS({
|
|||||||
where: { id: WALLET_ID },
|
where: { id: WALLET_ID },
|
||||||
data: {
|
data: {
|
||||||
balanceToman,
|
balanceToman,
|
||||||
blocked: balanceToman <= 0 ? true : wasBroke ? false : wallet.blocked
|
blocked: balanceToman > 0 && wasBroke ? false : wallet.blocked
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
this.prisma.smsTopUp.create({
|
this.prisma.smsTopUp.create({
|
||||||
@@ -128922,12 +128910,6 @@ var require_sms_wallet_service = __commonJS({
|
|||||||
update: {},
|
update: {},
|
||||||
create: { id: WALLET_ID }
|
create: { id: WALLET_ID }
|
||||||
});
|
});
|
||||||
if (wallet.balanceToman <= 0 && !wallet.blocked) {
|
|
||||||
return db.smsWallet.update({
|
|
||||||
where: { id: WALLET_ID },
|
|
||||||
data: { blocked: true }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return wallet;
|
return wallet;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -57,15 +57,6 @@ export class SmsWalletService {
|
|||||||
|
|
||||||
async canSend(): Promise<boolean> {
|
async canSend(): Promise<boolean> {
|
||||||
const wallet = await this.ensure();
|
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;
|
return !wallet.blocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,11 +67,12 @@ export class SmsWalletService {
|
|||||||
const wallet = await this.ensure(tx);
|
const wallet = await this.ensure(tx);
|
||||||
const costToman = parts * wallet.pricePerPart;
|
const costToman = parts * wallet.pricePerPart;
|
||||||
const balanceToman = wallet.balanceToman - costToman;
|
const balanceToman = wallet.balanceToman - costToman;
|
||||||
|
const crossedToEmpty = wallet.balanceToman > 0 && balanceToman <= 0;
|
||||||
await tx.smsWallet.update({
|
await tx.smsWallet.update({
|
||||||
where: { id: WALLET_ID },
|
where: { id: WALLET_ID },
|
||||||
data: {
|
data: {
|
||||||
balanceToman,
|
balanceToman,
|
||||||
blocked: balanceToman <= 0 ? true : wallet.blocked,
|
blocked: crossedToEmpty ? true : wallet.blocked,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await tx.smsUsage.create({ data: { parts, costToman } });
|
await tx.smsUsage.create({ data: { parts, costToman } });
|
||||||
@@ -92,7 +84,7 @@ export class SmsWalletService {
|
|||||||
return {
|
return {
|
||||||
balanceToman: wallet.balanceToman,
|
balanceToman: wallet.balanceToman,
|
||||||
balanceRial: wallet.balanceToman * TOMAN_TO_RIAL,
|
balanceRial: wallet.balanceToman * TOMAN_TO_RIAL,
|
||||||
blocked: wallet.blocked || wallet.balanceToman <= 0,
|
blocked: wallet.blocked,
|
||||||
yellowThreshold: wallet.yellowThreshold,
|
yellowThreshold: wallet.yellowThreshold,
|
||||||
redThreshold: wallet.redThreshold,
|
redThreshold: wallet.redThreshold,
|
||||||
deposit: {
|
deposit: {
|
||||||
@@ -159,14 +151,7 @@ export class SmsWalletService {
|
|||||||
throw new BadRequestException('آستانه زرد باید بزرگتر یا مساوی آستانه قرمز باشد');
|
throw new BadRequestException('آستانه زرد باید بزرگتر یا مساوی آستانه قرمز باشد');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dto.blocked != null) {
|
if (dto.blocked != null) data.blocked = dto.blocked;
|
||||||
if (dto.blocked === false && wallet.balanceToman <= 0) {
|
|
||||||
throw new BadRequestException(
|
|
||||||
'با موجودی صفر یا منفی، مسدودسازی برداشته نمیشود',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
data.blocked = dto.blocked;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Object.keys(data).length) {
|
if (Object.keys(data).length) {
|
||||||
await this.prisma.smsWallet.update({ where: { id: WALLET_ID }, data });
|
await this.prisma.smsWallet.update({ where: { id: WALLET_ID }, data });
|
||||||
@@ -183,7 +168,7 @@ export class SmsWalletService {
|
|||||||
where: { id: WALLET_ID },
|
where: { id: WALLET_ID },
|
||||||
data: {
|
data: {
|
||||||
balanceToman,
|
balanceToman,
|
||||||
blocked: balanceToman <= 0 ? true : wasBroke ? false : wallet.blocked,
|
blocked: balanceToman > 0 && wasBroke ? false : wallet.blocked,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
this.prisma.smsTopUp.create({
|
this.prisma.smsTopUp.create({
|
||||||
@@ -202,12 +187,6 @@ export class SmsWalletService {
|
|||||||
update: {},
|
update: {},
|
||||||
create: { id: WALLET_ID },
|
create: { id: WALLET_ID },
|
||||||
});
|
});
|
||||||
if (wallet.balanceToman <= 0 && !wallet.blocked) {
|
|
||||||
return db.smsWallet.update({
|
|
||||||
where: { id: WALLET_ID },
|
|
||||||
data: { blocked: true },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return wallet;
|
return wallet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user