Update DistrictSelection back button

This commit is contained in:
NW 2024-12-14 13:16:22 +00:00
parent 207b9a829c
commit 12d29c66b9

View File

@ -123,42 +123,39 @@ export default class UserProductHandler {
const chatId = callbackQuery.message.chat.id; const chatId = callbackQuery.message.chat.id;
const messageId = callbackQuery.message.message_id; const messageId = callbackQuery.message.message_id;
const [country, city, district] = callbackQuery.data.replace('shop_district_', '').split('_'); const [country, city, district] = callbackQuery.data.replace('shop_district_', '').split('_');
try { try {
const location = await LocationService.getLocation(country, city, district); const location = await LocationService.getLocation(country, city, district);
if (!location) { if (!location) {
throw new Error('Location not found'); // Если локация не найдена, вернуть пользователя к предыдущему шагу
}
const categories = await CategoryService.getCategoriesByLocationId(location.id);
if (categories.length === 0) {
await bot.editMessageText( await bot.editMessageText(
'No products available in this location yet.', 'Location not found. Returning to previous menu.',
{ {
chat_id: chatId, chat_id: chatId,
message_id: messageId, message_id: messageId,
reply_markup: { reply_markup: {
inline_keyboard: [[ inline_keyboard: [[
{text: '« Back to Districts', callback_data: `shop_city_${country}_${city}`} { text: '« Back', callback_data: 'shop_start' }
]] ]]
} }
} }
); );
return; return;
} }
const categories = await CategoryService.getCategoriesByLocationId(location.id);
const keyboard = { const keyboard = {
inline_keyboard: [ inline_keyboard: [
...categories.map(cat => [{ ...categories.map(cat => [{
text: cat.name, text: cat.name,
callback_data: `shop_category_${location.id}_${cat.id}` 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( await bot.editMessageText(
'📦 Select category:', '📦 Select category:',
{ {