Check bug delet category
This commit is contained in:
parent
99137e4e97
commit
057d1536bb
@ -227,7 +227,7 @@ export default class AdminLocationHandler {
|
||||
const keyboard = {
|
||||
inline_keyboard: locations.map(loc => [{
|
||||
text: `${loc.country} > ${loc.city} > ${loc.district} (P:${loc.product_count} C:${loc.category_count})`,
|
||||
callback_data: `confirm_delete_location_${loc.country}_${loc.city}_${loc.district}`
|
||||
callback_data: `confirm_delete_location_${loc.id}` // Используем ID локации вместо строки
|
||||
}])
|
||||
};
|
||||
|
||||
@ -254,23 +254,27 @@ export default class AdminLocationHandler {
|
||||
}
|
||||
|
||||
const chatId = callbackQuery.message.chat.id;
|
||||
const [country, city, district] = callbackQuery.data
|
||||
.replace('confirm_delete_location_', '')
|
||||
.split('_');
|
||||
const locationId = callbackQuery.data.replace('confirm_delete_location_', '');
|
||||
|
||||
try {
|
||||
const location = await db.getAsync('SELECT * FROM locations WHERE id = ?', [locationId]);
|
||||
|
||||
if (!location) {
|
||||
throw new Error('Location not found');
|
||||
}
|
||||
|
||||
await db.runAsync('BEGIN TRANSACTION');
|
||||
|
||||
const result = await db.runAsync(
|
||||
'DELETE FROM locations WHERE country = ? AND city = ? AND district = ?',
|
||||
[country, city, district]
|
||||
'DELETE FROM locations WHERE id = ?',
|
||||
[locationId]
|
||||
);
|
||||
|
||||
await db.runAsync('COMMIT');
|
||||
|
||||
if (result.changes > 0) {
|
||||
await bot.editMessageText(
|
||||
`✅ Location deleted successfully!\n\nCountry: ${country}\nCity: ${city}\nDistrict: ${district}`,
|
||||
`✅ Location deleted successfully!\n\nCountry: ${location.country}\nCity: ${location.city}\nDistrict: ${location.district}`,
|
||||
{
|
||||
chat_id: chatId,
|
||||
message_id: callbackQuery.message.message_id,
|
||||
|
@ -890,7 +890,6 @@ export default class AdminProductHandler {
|
||||
|
||||
const locationId = product.location_id;
|
||||
const categoryId = product.category_id;
|
||||
const subcategoryId = product.subcategory_id;
|
||||
|
||||
const sampleProduct = {
|
||||
name: product.name,
|
||||
@ -911,7 +910,6 @@ export default class AdminProductHandler {
|
||||
action: 'edit_product',
|
||||
locationId,
|
||||
categoryId,
|
||||
subcategoryId,
|
||||
productId
|
||||
});
|
||||
|
||||
@ -923,13 +921,13 @@ export default class AdminProductHandler {
|
||||
inline_keyboard: [[
|
||||
{
|
||||
text: '❌ Cancel',
|
||||
callback_data: `prod_subcategory_${locationId}_${categoryId}_${subcategoryId}`
|
||||
callback_data: `prod_category_${locationId}_${categoryId}` // Возвращаемся к списку товаров в категории
|
||||
}
|
||||
]]
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error in handleViewProduct:', error);
|
||||
console.error('Error in handleProductEdit:', error);
|
||||
await bot.sendMessage(chatId, 'Error loading product details. Please try again.');
|
||||
}
|
||||
}
|
||||
@ -991,22 +989,22 @@ export default class AdminProductHandler {
|
||||
throw new Error('Product not found');
|
||||
}
|
||||
|
||||
const locationId = product.location_id;
|
||||
const categoryId = product.category_id;
|
||||
|
||||
try {
|
||||
await db.runAsync('BEGIN TRANSACTION');
|
||||
await db.runAsync('DELETE FROM products WHERE id=?', [productId.toString()]);
|
||||
await db.runAsync('COMMIT');
|
||||
} catch (e) {
|
||||
await db.runAsync("ROLLBACK");
|
||||
await db.runAsync('ROLLBACK');
|
||||
console.error('Error deleting product:', e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
const keyboard = {
|
||||
inline_keyboard: [
|
||||
[{
|
||||
text: '« Back',
|
||||
callback_data: `prod_subcategory_${product.location_id}_${product.category_id}_${product.subcategory_id}`
|
||||
}]
|
||||
[{ text: '« Back', callback_data: `prod_category_${locationId}_${categoryId}` }] // Возвращаемся к списку товаров в категории
|
||||
]
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user