From 12d29c66b93ab82e4c87be9782a1c4ba5ae21577 Mon Sep 17 00:00:00 2001 From: NW Date: Sat, 14 Dec 2024 13:16:22 +0000 Subject: [PATCH] Update DistrictSelection back button --- .../userHandlers/userProductHandler.js | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/handlers/userHandlers/userProductHandler.js b/src/handlers/userHandlers/userProductHandler.js index 401ebf4..99dd1b7 100644 --- a/src/handlers/userHandlers/userProductHandler.js +++ b/src/handlers/userHandlers/userProductHandler.js @@ -123,42 +123,39 @@ export default class UserProductHandler { const chatId = callbackQuery.message.chat.id; const messageId = callbackQuery.message.message_id; const [country, city, district] = callbackQuery.data.replace('shop_district_', '').split('_'); - + try { const location = await LocationService.getLocation(country, city, district); - + if (!location) { - throw new Error('Location not found'); - } - - const categories = await CategoryService.getCategoriesByLocationId(location.id); - - if (categories.length === 0) { + // Если локация не найдена, вернуть пользователя к предыдущему шагу await bot.editMessageText( - 'No products available in this location yet.', + 'Location not found. Returning to previous menu.', { chat_id: chatId, message_id: messageId, reply_markup: { inline_keyboard: [[ - {text: '« Back to Districts', callback_data: `shop_city_${country}_${city}`} + { text: '« Back', callback_data: 'shop_start' } ]] } } ); return; } - + + const categories = await CategoryService.getCategoriesByLocationId(location.id); + const keyboard = { inline_keyboard: [ ...categories.map(cat => [{ text: cat.name, callback_data: `shop_category_${location.id}_${cat.id}` }]), - [{text: '« Back to Districts', callback_data: `shop_city_${country}_${city}`}] + [{ text: '« Back', callback_data: `shop_city_${country}_${city}` }] ] }; - + await bot.editMessageText( '📦 Select category:', {