Allow turning SMS blocking off even when the wallet is empty.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -57,15 +57,6 @@ export class SmsWalletService {
|
||||
|
||||
async canSend(): Promise<boolean> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user