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