Bill all platform SMS (including OTP), allow negative balance with manual/auto cutoffs, and support own-panel bypass without wallet debit.
28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
import { Controller, Get, UseGuards } from '@nestjs/common';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
import { CurrentUser } from '../auth/current-user.decorator';
|
|
import { SmsWalletService } from './sms-wallet.service';
|
|
|
|
@Controller('sms-wallet')
|
|
@UseGuards(JwtAuthGuard)
|
|
export class OrgSmsController {
|
|
constructor(private readonly wallet: SmsWalletService) {}
|
|
|
|
/** خلاصه برای نشان اعتبار در هدر CRM */
|
|
@Get('summary')
|
|
async summary(@CurrentUser() user: { organizationId: string }) {
|
|
const account = await this.wallet.ensureAccount(user.organizationId);
|
|
const billingEnabled = this.wallet.isBillingEnabled(account);
|
|
return {
|
|
billingEnabled,
|
|
balanceRials: account.balanceRials,
|
|
pricePerPartRials: account.pricePerPartRials,
|
|
isBlocked: account.isBlocked,
|
|
autoBlocked: this.wallet.isAutoBlocked(account),
|
|
balanceLevel: this.wallet.balanceLevel(account),
|
|
panelMode: account.panelMode,
|
|
chargeInfo: billingEnabled ? this.wallet.chargeInfoOf(account) : null,
|
|
};
|
|
}
|
|
}
|