258 lines
8.0 KiB
TypeScript
258 lines
8.0 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Patch,
|
|
Put,
|
|
Delete,
|
|
Body,
|
|
Param,
|
|
Query,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { Prisma } from '@prisma/client';
|
|
import { SettingsService, ScientificTermData } from './settings.service';
|
|
import { SmsLogQueryDto } from './dto/sms-log-query.dto';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
import { RolesGuard } from '../common/guards/roles.guard';
|
|
import { Roles } from '../common/decorators/roles.decorator';
|
|
import {
|
|
ApiTags,
|
|
ApiOperation,
|
|
ApiBearerAuth,
|
|
ApiOkResponse,
|
|
} from '@nestjs/swagger';
|
|
|
|
@ApiTags('Settings - تنظیمات متون پویا، تنظیمات سئو، مالی، سیستم و پیامک')
|
|
@Controller('settings')
|
|
export class SettingsController {
|
|
constructor(private readonly settingsService: SettingsService) {}
|
|
|
|
@Get('ui-texts')
|
|
@ApiOperation({ summary: 'دریافت تمامی متون و پیکربندیهای رابط کاربری' })
|
|
@ApiOkResponse({
|
|
description:
|
|
'یک آبجکت کلید-مقدار حاوی تمامی متون، شعارها و برچسبهای دکمهها',
|
|
})
|
|
getUiTexts() {
|
|
return this.settingsService.getUiTexts();
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Put('ui-texts/:key')
|
|
@ApiOperation({ summary: 'ویرایش یا ثبت متن یک کلید در رابط کاربری با متد PUT' })
|
|
putUiText(@Param('key') key: string, @Body() body: any) {
|
|
const val =
|
|
typeof body === 'object' && body !== null && 'value' in body
|
|
? body.value
|
|
: typeof body === 'string'
|
|
? body
|
|
: JSON.stringify(body);
|
|
return this.settingsService.updateUiText(key, String(val ?? ''));
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Patch('ui-texts/:key')
|
|
@ApiOperation({ summary: 'ویرایش یا ثبت متن یک کلید در رابط کاربری با متد PATCH' })
|
|
patchUiText(@Param('key') key: string, @Body() body: any) {
|
|
const val =
|
|
typeof body === 'object' && body !== null && 'value' in body
|
|
? body.value
|
|
: typeof body === 'string'
|
|
? body
|
|
: JSON.stringify(body);
|
|
return this.settingsService.updateUiText(key, String(val ?? ''));
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Put('ui-texts')
|
|
@ApiOperation({ summary: 'ویرایش گروهی متون رابط کاربری' })
|
|
putBulkUiTexts(@Body() body: Record<string, string>) {
|
|
return this.settingsService.updateBulkUiTexts(body);
|
|
}
|
|
|
|
@Get('scientific-terms')
|
|
@ApiOperation({ summary: 'دریافت تمامی اصطلاحات واژهنامه علمی' })
|
|
getScientificTerms() {
|
|
return this.settingsService.getScientificTerms();
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Put('scientific-terms/:key')
|
|
@ApiOperation({ summary: 'ثبت یا ویرایش یک اصطلاح علمی' })
|
|
upsertScientificTerm(
|
|
@Param('key') key: string,
|
|
@Body() data: ScientificTermData,
|
|
) {
|
|
return this.settingsService.upsertScientificTerm(key, data);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Delete('scientific-terms/:key')
|
|
@ApiOperation({ summary: 'حذف یک اصطلاح علمی' })
|
|
deleteScientificTerm(@Param('key') key: string) {
|
|
return this.settingsService.deleteScientificTerm(key);
|
|
}
|
|
|
|
// SEO Settings
|
|
@Get('seo')
|
|
@ApiOperation({ summary: 'دریافت تنظیمات سئو' })
|
|
getSeoSettings() {
|
|
return this.settingsService.getCategorySetting('seo');
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Patch('seo')
|
|
@ApiOperation({ summary: 'بهروزرسانی تنظیمات سئو' })
|
|
updateSeoSettings(@Body() body: Prisma.InputJsonValue) {
|
|
return this.settingsService.updateCategorySetting('seo', body);
|
|
}
|
|
|
|
// Financial Settings
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Get('financial')
|
|
@ApiOperation({ summary: 'دریافت تنظیمات مالی' })
|
|
getFinancialSettings() {
|
|
return this.settingsService.getCategorySetting('financial');
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Patch('financial')
|
|
@ApiOperation({ summary: 'بهروزرسانی تنظیمات مالی' })
|
|
updateFinancialSettings(@Body() body: Prisma.InputJsonValue) {
|
|
return this.settingsService.updateCategorySetting('financial', body);
|
|
}
|
|
|
|
// System Settings
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Get('system')
|
|
@ApiOperation({ summary: 'دریافت تنظیمات سیستم' })
|
|
getSystemSettings() {
|
|
return this.settingsService.getCategorySetting('system');
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Patch('system')
|
|
@ApiOperation({ summary: 'بهروزرسانی تنظیمات سیستم' })
|
|
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);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Get('sms/patterns')
|
|
@ApiOperation({
|
|
summary: 'دریافت لیست تمامی پترنهای تعریف شده در ملی پیامک',
|
|
})
|
|
getPatterns() {
|
|
return this.settingsService.getPatterns();
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Post('sms/patterns')
|
|
@ApiOperation({ summary: 'درج الگوی جدید در سامانه ملی پیامک' })
|
|
addPattern(
|
|
@Body('title') title: string,
|
|
@Body('body') body: string,
|
|
@Body('blackListId') blackListId?: number,
|
|
) {
|
|
return this.settingsService.addPattern(title, body, blackListId);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Put('sms/patterns/:bodyId')
|
|
@ApiOperation({
|
|
summary: 'ویرایش الگوی رد شده یا در حال ویرایش در ملی پیامک',
|
|
})
|
|
editPattern(@Param('bodyId') bodyId: string, @Body('body') body: string) {
|
|
return this.settingsService.editPattern(Number(bodyId), body);
|
|
}
|
|
|
|
// SMS Logs & Tracking Endpoints
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Get('sms/logs')
|
|
@ApiOperation({
|
|
summary: 'دریافت گزارشات و لاگهای کامل پیامکهای ارسالی با فیلتر و جستجو',
|
|
})
|
|
getSmsLogs(@Query() query: SmsLogQueryDto) {
|
|
return this.settingsService.getSmsLogs(query);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Delete('sms/logs/:id')
|
|
@ApiOperation({ summary: 'حذف یک رکورد لاگ پیامک' })
|
|
deleteSmsLog(@Param('id') id: string) {
|
|
return this.settingsService.deleteSmsLog(id);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Delete('sms/logs')
|
|
@ApiOperation({ summary: 'پاکسازی تمامی لاگهای پیامک' })
|
|
clearAllSmsLogs() {
|
|
return this.settingsService.clearAllSmsLogs();
|
|
}
|
|
}
|