feat(admin,sms): add dynamic sms settings management and live tester in admin panel

This commit is contained in:
parsa aghaei committed 2026-08-16 11:48:40 +03:30
1 parent 8992060cb7
commit 09fd339e89
7 files changed
+755 -40

No files matched your search

+35 -1
View File
@@ -1,6 +1,7 @@
import {
Controller,
Get,
Post,
Patch,
Put,
Delete,
@@ -20,7 +21,7 @@ import {
ApiOkResponse,
} from '@nestjs/swagger';
@ApiTags('Settings - تنظیمات متون پویا، تنظیمات سئو، مالی و سیستم')
@ApiTags('Settings - تنظیمات متون پویا، تنظیمات سئو، مالی، سیستم و پیامک')
@Controller('settings')
export class SettingsController {
constructor(private readonly settingsService: SettingsService) {}
@@ -125,4 +126,37 @@ export class SettingsController {
updateSystemSettings(@Body() body: Prisma.InputJsonValue) {
return this.settingsService.updateCategorySetting('system', body);
}
// SMS Gateway Settings
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('Admin')
@ApiBearerAuth()
@Get('sms')
@ApiOperation({ summary: 'دریافت تنظیمات درگاه پیامک و کدهای پترن' })
getSmsSettings() {
return this.settingsService.getSmsSettings();
}
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('Admin')
@ApiBearerAuth()
@Patch('sms')
@ApiOperation({ summary: 'به‌روزرسانی تنظیمات درگاه پیامک و کدهای پترن' })
updateSmsSettings(@Body() body: Prisma.InputJsonValue) {
return this.settingsService.updateSmsSettings(body);
}
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('Admin')
@ApiBearerAuth()
@Post('sms/test')
@ApiOperation({ summary: 'ارسال پیامک آزمایشی پترن به شماره دلخواه' })
testSms(
@Body('phone') phone: string,
@Body('patternId') patternId?: number,
@Body('args') args?: string[],
) {
return this.settingsService.testSms(phone, patternId, args);
}
}
+23 -1
View File
@@ -1,6 +1,7 @@
import { Injectable } from '@nestjs/common';
import { Prisma } from '@prisma/client';
import { PrismaService } from '../prisma/prisma.service';
import { SmsService } from '../common/services/sms.service';
export class ScientificTermData {
term?: string;
@@ -10,7 +11,10 @@ export class ScientificTermData {
@Injectable()
export class SettingsService {
constructor(private prisma: PrismaService) {}
constructor(
private prisma: PrismaService,
private smsService: SmsService,
) {}
async getUiTexts() {
const [uiTexts, settings] = await Promise.all([
@@ -82,4 +86,22 @@ export class SettingsService {
create: { key, category, value },
});
}
async getSmsSettings() {
return this.smsService.getSmsConfig();
}
async updateSmsSettings(value: Prisma.InputJsonValue) {
const key = 'sms_config';
return this.prisma.setting.upsert({
where: { key },
update: { category: 'sms', value },
create: { key, category: 'sms', value },
});
}
async testSms(targetPhone: string, patternId?: number, args?: string[]) {
return this.smsService.testSms(targetPhone, patternId, args);
}
}