From 37c28353a99fb186f8c622c035c50e41af870199 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Wed, 20 Aug 2025 17:59:36 +0300 Subject: [PATCH] feat: enhance Telegram notification to include total service cost - Updated the Telegram notification message to display the total cost of services associated with an order, improving transparency for clients and masters. - Added logic to calculate the total price based on individual service prices and formatted the price for better readability. --- .../order/content-types/order/lifecycles.ts | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/api/order/content-types/order/lifecycles.ts b/src/api/order/content-types/order/lifecycles.ts index fc0d274..876ba9d 100644 --- a/src/api/order/content-types/order/lifecycles.ts +++ b/src/api/order/content-types/order/lifecycles.ts @@ -107,16 +107,28 @@ async function sendTelegramNotification(orderEntity: Order, isUpdate = false) { const clientName = order.client?.name || '-'; const masterName = slot.master?.name || '-'; - // Формируем список всех услуг - const servicesList = order.services?.length - ? order.services.map(service => service.name).join(', ') - : '-'; + // Формируем список всех услуг и вычисляем общую стоимость + let servicesList = '-'; + let totalPrice = 0; + + if (order.services?.length) { + servicesList = order.services.map(service => service.name).join(', '); + + // Вычисляем общую стоимость + totalPrice = order.services.reduce((sum, service) => { + return sum + (service.price || 0); + }, 0); + } + + // Форматируем цену для отображения + const priceText = totalPrice > 0 ? `${totalPrice.toLocaleString('ru-RU')} ₽` : 'Не указана'; const messageForMaster = `${heading} Дата: ${date} Время: ${timeStartString} - ${timeEndString} Клиент: ${clientName} Услуги: ${servicesList} +Стоимость: ${priceText} Статус: ${emojiForState} ${stateLabel}`; const messageForClient = `${heading} @@ -124,6 +136,7 @@ async function sendTelegramNotification(orderEntity: Order, isUpdate = false) { Время: ${timeStartString} - ${timeEndString} Мастер: ${masterName} Услуги: ${servicesList} +Стоимость: ${priceText} Статус: ${emojiForState} ${stateLabel}`; if (masterTelegramId) {