Delet subcategory function in handleCategorySelection

This commit is contained in:
NW 2024-12-13 18:24:24 +00:00
parent 95d5fe644d
commit a400d12d16

View File

@ -179,21 +179,18 @@ export default class UserProductHandler {
const [locationId, categoryId] = callbackQuery.data.replace('shop_category_', '').split('_');
try {
const subcategories = await CategoryService.getSubcategoriesByCategoryId(categoryId);
const location = await LocationService.getLocationById(locationId);
// Получаем товары для выбранной категории
const products = await ProductService.getProductsByCategoryId(categoryId);
if (subcategories.length === 0) {
if (products.length === 0) {
await bot.editMessageText(
'No products available in this category yet.',
'No products available in this category.',
{
chat_id: chatId,
message_id: messageId,
reply_markup: {
inline_keyboard: [[
{
text: '« Back to Categories',
callback_data: `shop_district_${location.country}_${location.city}_${location.district}`
}
{ text: '« Back', callback_data: `shop_district_${locationId}` }
]]
}
}
@ -201,21 +198,24 @@ export default class UserProductHandler {
return;
}
// Создаем клавиатуру с товарами
const keyboard = {
inline_keyboard: [
...subcategories.map(sub => [{
text: sub.name,
callback_data: `shop_subcategory_${locationId}_${categoryId}_${sub.id}`
}]),
[{
text: '« Back to Categories',
callback_data: `shop_district_${location.country}_${location.city}_${location.district}`
}]
]
inline_keyboard: products.map(product => [
{
text: `${product.name} - $${product.price}`,
callback_data: `shop_product_${product.id}`
}
])
};
// Добавляем кнопку "Назад"
keyboard.inline_keyboard.push([
{ text: '« Back', callback_data: `shop_district_${locationId}` }
]);
// Отправляем сообщение с товарами
await bot.editMessageText(
'📦 Select subcategory:',
'Select a product:',
{
chat_id: chatId,
message_id: messageId,
@ -224,7 +224,7 @@ export default class UserProductHandler {
);
} catch (error) {
console.error('Error in handleCategorySelection:', error);
await bot.sendMessage(chatId, 'Error loading subcategories. Please try again.');
await bot.sendMessage(chatId, 'Error loading products. Please try again.');
}
}