feat(backend): implement Phase A database models and controllers for cross-boundary dependencies
Deploy Canina / deploy (push) Failing after 28s

This commit is contained in:
parsa committed 2026-08-06 23:45:51 +03:30
1 parent 74fcaa6a4e
commit 1ae4c99ffc
26 files changed
+1205 -345

No files matched your search

+44 -88
View File
@@ -7,7 +7,6 @@ import {
Body,
Param,
UseGuards,
HttpStatus,
} from '@nestjs/common';
import { SettingsService } from './settings.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
@@ -17,12 +16,10 @@ import {
ApiTags,
ApiOperation,
ApiBearerAuth,
ApiResponse,
ApiOkResponse,
ApiUnauthorizedResponse,
} from '@nestjs/swagger';
@ApiTags('Settings - تنظیمات متون پویا و واژه‌نامه علمی')
@ApiTags('Settings - تنظیمات متون پویا، تنظیمات سئو، مالی و سیستم')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('Admin')
@Controller('settings')
@@ -32,15 +29,7 @@ export class SettingsController {
@Get('ui-texts')
@ApiOperation({ summary: 'دریافت تمامی متون و پیکربندی‌های رابط کاربری' })
@ApiOkResponse({
description:
'یک آبجکت کلید-مقدار حاوی تمامی متون، شعارها و برچسب‌های دکمه‌ها',
schema: {
example: {
hero_badge: 'تخصص دارویی از آلمان',
hero_title: 'تخصص آلمانی در خدمت سلامت پت‌های خانگی',
hero_desc: 'بیش از ۴۰ سال تجربه نوآورانه...',
},
},
description: 'یک آبجکت کلید-مقدار حاوی تمامی متون، شعارها و برچسب‌های دکمه‌ها',
})
getUiTexts() {
return this.settingsService.getUiTexts();
@@ -49,45 +38,13 @@ export class SettingsController {
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@Patch('ui-texts/:key')
@ApiOperation({ summary: 'ویرایش متن یک کلید در رابط کاربری (نیازمند توکن)' })
@ApiOkResponse({
description: 'متن با موفقیت به‌روزرسانی شد',
schema: {
example: {
key: 'hero_badge',
value: 'تخصص دارویی ممتاز از آلمان',
},
},
})
@ApiUnauthorizedResponse({
description: 'عدم دسترسی به دلیل عدم احراز هویت',
schema: {
example: {
success: false,
message: 'Unauthorized',
code: 'UNAUTHORIZED',
},
},
})
@ApiOperation({ summary: 'ویرایش متن یک کلید در رابط کاربری' })
updateUiText(@Param('key') key: string, @Body('value') value: string) {
return this.settingsService.updateUiText(key, value);
}
@Get('scientific-terms')
@ApiOperation({ summary: 'دریافت تمامی اصطلاحات واژه‌نامه علمی' })
@ApiOkResponse({
description: 'لیست کامل اصطلاحات علمی به همراه تعاریف و شناسه‌ها',
schema: {
example: [
{
key: 'green-mussel',
term: 'صدف لب‌سبز (Perna Canaliculus)',
definition: 'این صدف بومی سواحل بکر نیوزیلند است...',
wikiId: 'general',
},
],
},
})
getScientificTerms() {
return this.settingsService.getScientificTerms();
}
@@ -95,28 +52,7 @@ export class SettingsController {
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@Put('scientific-terms/:key')
@ApiOperation({ summary: 'ثبت یا ویرایش یک اصطلاح علمی (نیازمند توکن)' })
@ApiOkResponse({
description: 'اصطلاح علمی ثبت یا ویرایش شد',
schema: {
example: {
key: 'green-mussel',
term: 'صدف لب‌سبز اصل نیوزیلند',
definition: 'این صدف بومی سواحل بکر نیوزیلند است...',
wikiId: 'general',
},
},
})
@ApiUnauthorizedResponse({
description: 'عدم دسترسی',
schema: {
example: {
success: false,
message: 'Unauthorized',
code: 'UNAUTHORIZED',
},
},
})
@ApiOperation({ summary: 'ثبت یا ویرایش یک اصطلاح علمی' })
upsertScientificTerm(@Param('key') key: string, @Body() data: any) {
return this.settingsService.upsertScientificTerm(key, data);
}
@@ -124,27 +60,47 @@ export class SettingsController {
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@Delete('scientific-terms/:key')
@ApiOperation({ summary: 'حذف یک اصطلاح علمی (نیازمند توکن)' })
@ApiOkResponse({
description: 'اصطلاح علمی حذف شد',
schema: {
example: {
success: true,
message: 'Scientific term successfully deleted',
},
},
})
@ApiUnauthorizedResponse({
description: 'عدم دسترسی',
schema: {
example: {
success: false,
message: 'Unauthorized',
code: 'UNAUTHORIZED',
},
},
})
@ApiOperation({ summary: 'حذف یک اصطلاح علمی' })
deleteScientificTerm(@Param('key') key: string) {
return this.settingsService.deleteScientificTerm(key);
}
// SEO Settings
@Get('seo')
@ApiOperation({ summary: 'دریافت تنظیمات سئو' })
getSeoSettings() {
return this.settingsService.getCategorySetting('seo');
}
@Patch('seo')
@ApiOperation({ summary: 'به‌روزرسانی تنظیمات سئو' })
updateSeoSettings(@Body() body: any) {
return this.settingsService.updateCategorySetting('seo', body);
}
// Financial Settings
@Get('financial')
@ApiOperation({ summary: 'دریافت تنظیمات مالی' })
getFinancialSettings() {
return this.settingsService.getCategorySetting('financial');
}
@Patch('financial')
@ApiOperation({ summary: 'به‌روزرسانی تنظیمات مالی' })
updateFinancialSettings(@Body() body: any) {
return this.settingsService.updateCategorySetting('financial', body);
}
// System Settings
@Get('system')
@ApiOperation({ summary: 'دریافت تنظیمات سیستم' })
getSystemSettings() {
return this.settingsService.getCategorySetting('system');
}
@Patch('system')
@ApiOperation({ summary: 'به‌روزرسانی تنظیمات سیستم' })
updateSystemSettings(@Body() body: any) {
return this.settingsService.updateCategorySetting('system', body);
}
}
+26 -6
View File
@@ -22,18 +22,22 @@ export class SettingsService {
}
async upsertScientificTerm(key: string, data: any) {
const term = String(data?.term || '');
const definition = String(data?.definition || '');
const wikiId = String(data?.wikiId || 'general');
return this.prisma.scientificTerm.upsert({
where: { key },
update: {
term: data.term,
definition: data.definition,
wikiId: data.wikiId || 'general',
term,
definition,
wikiId,
},
create: {
key,
term: data.term,
definition: data.definition,
wikiId: data.wikiId || 'general',
term,
definition,
wikiId,
},
});
}
@@ -43,4 +47,20 @@ export class SettingsService {
where: { key },
});
}
async getCategorySetting(category: string) {
const setting = await this.prisma.setting.findFirst({
where: { category },
});
return setting ? setting.value : {};
}
async updateCategorySetting(category: string, value: any) {
const key = `${category}_config`;
return this.prisma.setting.upsert({
where: { key },
update: { category, value },
create: { key, category, value },
});
}
}