fix bug back navigation
This commit is contained in:
@@ -125,6 +125,7 @@ export default class UserProductHandler {
|
|||||||
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) {
|
||||||
@@ -136,7 +137,7 @@ export default class UserProductHandler {
|
|||||||
message_id: messageId,
|
message_id: messageId,
|
||||||
reply_markup: {
|
reply_markup: {
|
||||||
inline_keyboard: [[
|
inline_keyboard: [[
|
||||||
{ text: '« Back', callback_data: 'shop_start' }
|
{ text: '« Back', callback_data: `shop_city_${country}_${city}` }
|
||||||
]]
|
]]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,6 +145,12 @@ export default class UserProductHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Сохраняем текстовое представление локации в состоянии пользователя
|
||||||
|
userStates.set(chatId, {
|
||||||
|
location: `${country}_${city}_${district}`
|
||||||
|
});
|
||||||
|
|
||||||
|
// Получаем категории для выбранной локации
|
||||||
const categories = await CategoryService.getCategoriesByLocationId(location.id);
|
const categories = await CategoryService.getCategoriesByLocationId(location.id);
|
||||||
|
|
||||||
const keyboard = {
|
const keyboard = {
|
||||||
@@ -201,7 +208,7 @@ export default class UserProductHandler {
|
|||||||
{
|
{
|
||||||
reply_markup: {
|
reply_markup: {
|
||||||
inline_keyboard: [[
|
inline_keyboard: [[
|
||||||
{ text: '« Back', callback_data: `shop_district_${locationId}` }
|
{ text: '« Back', callback_data: `shop_district_${state.location}` }
|
||||||
]]
|
]]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,7 +228,7 @@ export default class UserProductHandler {
|
|||||||
|
|
||||||
// Добавляем кнопку "Назад"
|
// Добавляем кнопку "Назад"
|
||||||
keyboard.inline_keyboard.push([
|
keyboard.inline_keyboard.push([
|
||||||
{ text: '« Back', callback_data: `shop_district_${locationId}` }
|
{ text: '« Back', callback_data: `shop_district_${state.location}` }
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Отправляем сообщение с товарами
|
// Отправляем сообщение с товарами
|
||||||
|
|||||||
@@ -2,10 +2,16 @@ import db from "../config/database.js";
|
|||||||
|
|
||||||
class CategoryService {
|
class CategoryService {
|
||||||
static async getCategoriesByLocationId(locationId) {
|
static async getCategoriesByLocationId(locationId) {
|
||||||
return await db.allAsync(
|
try {
|
||||||
'SELECT id, name FROM categories WHERE location_id = ? ORDER BY name',
|
const categories = await db.allAsync(
|
||||||
[locationId]
|
'SELECT * FROM categories WHERE location_id = ?',
|
||||||
);
|
[locationId]
|
||||||
|
);
|
||||||
|
return categories;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching categories by location ID:', error);
|
||||||
|
throw new Error('Failed to fetch categories');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getSubcategoriesByCategoryId(categoryId) {
|
static async getSubcategoriesByCategoryId(categoryId) {
|
||||||
|
|||||||
@@ -20,10 +20,16 @@ class LocationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async getLocation(country, city, district) {
|
static async getLocation(country, city, district) {
|
||||||
return await db.getAsync(
|
try {
|
||||||
'SELECT id FROM locations WHERE country = ? AND city = ? AND district = ?',
|
const location = await db.getAsync(
|
||||||
[country, city, district]
|
'SELECT * FROM locations WHERE country = ? AND city = ? AND district = ?',
|
||||||
);
|
[country, city, district]
|
||||||
|
);
|
||||||
|
return location;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching location:', error);
|
||||||
|
throw new Error('Failed to fetch location');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getLocationById(locationId) {
|
static async getLocationById(locationId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user