diff --git a/backend/src/admin/admin.controller.ts b/backend/src/admin/admin.controller.ts index d8687ba3..7557326a 100644 --- a/backend/src/admin/admin.controller.ts +++ b/backend/src/admin/admin.controller.ts @@ -354,4 +354,19 @@ export class AdminController { await this.settingsService.updateBulkUiTexts(body); return { success: true, data: body }; } + + @Get("symptoms") + @ApiOperation({ summary: "لیست کامل علائم درمانی به همراه تعداد محصولات متصل" }) + async getAllSymptoms() { + const data = await this.adminService.getAllSymptoms(); + return { success: true, data }; + } + + @Put("symptoms/rename") + @ApiOperation({ summary: "تغییر نام یکپارچه یک علامت در سراسر محصولات و دیتابیس" }) + async renameSymptom(@Body() body: { oldName: string; newName: string }) { + const result = await this.adminService.renameSymptom(body.oldName, body.newName); + return { success: true, ...result }; + } + } diff --git a/backend/src/admin/admin.service.ts b/backend/src/admin/admin.service.ts index 706629b1..ed2af0ae 100644 --- a/backend/src/admin/admin.service.ts +++ b/backend/src/admin/admin.service.ts @@ -1869,4 +1869,65 @@ export class AdminService { }; }); } + + async getAllSymptoms() { + const rawSymptoms = await this.prisma.productSymptom.groupBy({ + by: ['symptom'], + _count: { + productId: true, + }, + orderBy: { + symptom: 'asc', + }, + }); + + return rawSymptoms.map((s) => ({ + name: s.symptom, + productsCount: s._count.productId, + })); + } + + async renameSymptom(oldName: string, newName: string) { + if (!oldName?.trim() || !newName?.trim()) { + throw new BadRequestException('نام قبلی و جدید علامت الزامی است'); + } + const cleanOld = oldName.trim(); + const cleanNew = newName.trim(); + + return await this.prisma.(async (tx) => { + // 1. Rename in product_symptoms join table + const updatedJoin = await tx.` + UPDATE product_symptoms + SET symptom = ${cleanNew} + WHERE symptom = ${cleanOld}; + `; + + // 2. Cascade rename in products.dosage_config->'symptoms' jsonb array + await tx.` + UPDATE products + SET dosage_config = jsonb_set( + dosage_config, + '{symptoms}', + ( + SELECT jsonb_agg( + CASE + WHEN elem::text = to_jsonb(${cleanOld}::text)::text THEN to_jsonb(${cleanNew}::text) + ELSE elem + END + ) + FROM jsonb_array_elements(dosage_config->'symptoms') AS elem + ) + ) + WHERE dosage_config ? 'symptoms' + AND dosage_config->'symptoms' @> to_jsonb(${cleanOld}::text); + `; + + return { + success: true, + message: \`علامت «${cleanOld}» با موفقیت به «${cleanNew}» در سراسر سیستم تغییر یافت\`, + updatedCount: updatedJoin, + }; + }); + } + } diff --git a/frontend/admin-panel/src/pages/Orders.tsx b/frontend/admin-panel/src/pages/Orders.tsx index 0cd0189f..c2e322e7 100644 --- a/frontend/admin-panel/src/pages/Orders.tsx +++ b/frontend/admin-panel/src/pages/Orders.tsx @@ -31,6 +31,7 @@ import api from '../services/api'; export interface OrderItem { + requiresRx?: boolean; id?: string; name?: string; priceValue?: number; @@ -758,6 +759,12 @@ export default function Orders() { سفارش جدید )} + {(order.orderItems || order.items || []).some(it => it.product?.requiresRx) && ( + + Rx + هماهنگی نسخه + + )}
ارسال سفارش تنها پس از تماس تلفنی کارشناس پشتیبانی و تایید نسخه معتبر انجام شود.
+