163 lines
5.0 KiB
TypeScript
163 lines
5.0 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Patch,
|
|
Put,
|
|
Delete,
|
|
Body,
|
|
Param,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { Prisma } from '@prisma/client';
|
|
import { SettingsService, ScientificTermData } from './settings.service';
|
|
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()
|
|
@Patch('ui-texts/:key')
|
|
@Put('ui-texts/:key')
|
|
@ApiOperation({ summary: 'ویرایش یا ثبت متن یک کلید در رابط کاربری' })
|
|
updateUiText(@Param('key') key: string, @Body('value') value: string) {
|
|
return this.settingsService.updateUiText(key, value);
|
|
}
|
|
|
|
@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);
|
|
}
|
|
}
|
|
|