From 5a2c4cabfd52262bd39ce4b9cd53d7ce39fefdfa Mon Sep 17 00:00:00 2001 From: safavimohadeseh78 Date: Tue, 29 Sep 2026 22:02:03 +0330 Subject: [PATCH] 7/7/405 --- src/notifications/notification-events.ts | 10 ++++++++++ src/orders/dto/order.dto.ts | 11 ----------- src/orders/orders.service.ts | 23 +++++++++-------------- src/suggestions/suggestions.service.ts | 10 ++++++++++ 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/notifications/notification-events.ts b/src/notifications/notification-events.ts index 3055ae3..91a5140 100644 --- a/src/notifications/notification-events.ts +++ b/src/notifications/notification-events.ts @@ -3,6 +3,7 @@ import { NotificationTone, OrderStatus } from '@prisma/client'; /** رویدادهایی که برای مشتری اعلان و پیامک تولید می‌کنند. */ export type CustomerEvent = | 'order_submitted' + | 'order_registered_by_admin' | 'invoice_priced' | 'checks_approved' | 'checks_need_fix' @@ -87,6 +88,15 @@ export const CUSTOMER_EVENTS: Record = { tone: NotificationTone.info, smsSwitch: 'smsOrderRegistered', }, + order_registered_by_admin: { + title: 'پیش‌سفارش برای شما ثبت شد', + body: (c) => + `پیش‌سفارش ${c.orderNumber} توسط کارشناسان ما ثبت شد و برای قیمت‌گذاری در صف بررسی است.`, + sms: (c) => + `پیش‌سفارش ${c.orderNumber} در ${c.appName} برای شما ثبت شد. پس از قیمت‌گذاری مطلع می‌شوید.`, + tone: NotificationTone.info, + smsSwitch: 'smsOrderRegistered', + }, invoice_priced: { title: 'فاکتور سفارش شما صادر شد', body: (c) => diff --git a/src/orders/dto/order.dto.ts b/src/orders/dto/order.dto.ts index e634f77..1344167 100644 --- a/src/orders/dto/order.dto.ts +++ b/src/orders/dto/order.dto.ts @@ -1,7 +1,6 @@ import { ArrayMinSize, IsArray, - IsBoolean, IsDateString, IsEnum, IsNumber, @@ -262,16 +261,6 @@ export class UpdateOrderStatusDto { @IsOptional() @IsString() note?: string; - - @IsOptional() - @IsString() - reason?: string; - - /** عبور از ماشین وضعیت؛ فقط با ذکر دلیل و با ثبت در تاریخچه. */ - @IsOptional() - @Type(() => Boolean) - @IsBoolean() - force?: boolean; } export class UpdateOrderChecksDto { diff --git a/src/orders/orders.service.ts b/src/orders/orders.service.ts index e8bc466..a48807f 100644 --- a/src/orders/orders.service.ts +++ b/src/orders/orders.service.ts @@ -327,6 +327,11 @@ export class OrdersService { }), ); + this.notifications.dispatchOrderEvent( + order.id, + 'order_registered_by_admin', + ); + return this.mapOrder(order, true); } @@ -511,15 +516,7 @@ export class OrdersService { return this.mapOrder(order, true); } - if (dto.force) { - if (!dto.reason?.trim()) { - throw new BadRequestException( - 'برای تغییر دستی وضعیت، ذکر دلیل الزامی است', - ); - } - } else { - assertTransition(order.status, dto.status); - } + assertTransition(order.status, dto.status); // فاکتور بدون مبلغ نباید برای مشتری ارسال شود if ( @@ -550,10 +547,8 @@ export class OrdersService { fromStatus: order.status, toStatus: dto.status, changedBy: `admin:${adminId}`, - note: dto.force - ? `تغییر دستی وضعیت${dto.note ? ` — ${dto.note}` : ''}` - : dto.note || null, - reason: dto.reason || null, + note: dto.note || null, + reason: null, }, }); @@ -568,7 +563,7 @@ export class OrdersService { const event = eventForStatus(dto.status); if (event) { this.notifications.dispatchOrderEvent(id, event, { - note: dto.reason ?? dto.note ?? null, + note: dto.note ?? null, }); } diff --git a/src/suggestions/suggestions.service.ts b/src/suggestions/suggestions.service.ts index 1efbf95..2c93e11 100644 --- a/src/suggestions/suggestions.service.ts +++ b/src/suggestions/suggestions.service.ts @@ -17,6 +17,8 @@ const PRODUCT_INCLUDE = { isNew: true, colorsJson: true, imageUrlsJson: true, + widthCm: true, + composition: true, catalog: { select: { name: true, code: true } }, }, }, @@ -143,11 +145,15 @@ export class SuggestionsService { isNew: boolean; colorsJson: unknown; imageUrlsJson: unknown; + widthCm: number | null; + composition: string | null; catalog: { name: string; code: string } | null; }; }) { const colorEntries = parseColorEntries(r.product.colorsJson, r.product.color); const images = mergeProductImages(colorEntries, r.product.imageUrlsJson); + const colors = colorEntries.map((entry) => entry.name); + const colorImages = colorEntries.map((entry) => entry.imageUrl ?? null); const catalogName = r.product.catalog?.name; const subtitle = r.product.subtitle?.trim() || @@ -167,6 +173,10 @@ export class SuggestionsService { color: r.product.color, subtitle, imageUrl: images[0] ?? undefined, + colors, + colorImages, + widthCm: r.product.widthCm ?? undefined, + composition: r.product.composition?.trim() || undefined, isNew: r.product.isNew, note: r.note ?? undefined, isActive: r.isActive,