diff --git a/src/handlers/adminHandler.js b/src/handlers/adminHandler.js index 8573c17..7a2e037 100644 --- a/src/handlers/adminHandler.js +++ b/src/handlers/adminHandler.js @@ -1,35 +1,60 @@ -import db from '../config/database.js'; import config from '../config/config.js'; export default class AdminHandler { - constructor(bot) { - this.bot = bot; - } - - isAdmin(userId) { - return config.ADMIN_IDS.includes(userId.toString()); - } - - async handleAdminCommand(msg) { - const chatId = msg.chat.id; - - if (!this.isAdmin(msg.from.id)) { - await this.bot.sendMessage(chatId, 'Unauthorized access.'); - return; + constructor(bot) { + this.bot = bot; } - const keyboard = { - reply_markup: { - keyboard: [ - ['👥 Manage Users', '📦 Manage Products'], - ['💰 Manage Wallets', '📍 Manage Locations'], - ['💾 Database Backup'] - ], - resize_keyboard: true - } - }; + isAdmin(userId) { + return config.ADMIN_IDS.includes(userId.toString()); + } - await this.bot.sendMessage(chatId, 'Admin Panel:', keyboard); - } + async handleAdminCommand(msg) { + const chatId = msg.chat.id; + if (!this.isAdmin(msg.from.id)) { + await this.bot.sendMessage(chatId, 'Unauthorized access.'); + return; + } + + const keyboard = { + reply_markup: { + keyboard: [ + ['👥 Manage Users', '📦 Manage Products'], + ['💰 Manage Wallets', '📍 Manage Locations'], + ['💾 Database Backup'] + ], + resize_keyboard: true + } + }; + + await this.bot.sendMessage(chatId, 'Admin Panel:', keyboard); + } + + async handleAdminQueryCommand(callbackQuery) { + if (!this.isAdmin(callbackQuery.from.id)) return; + + const chatId = callbackQuery.message.chat.id; + const messageId = callbackQuery.message.message_id; + + const keyboard = { + reply_markup: { + keyboard: [ + ['👥 Manage Users', '📦 Manage Products'], + ['💰 Manage Wallets', '📍 Manage Locations'], + ['💾 Database Backup'] + ], + resize_keyboard: true + } + }; + + await this.bot.editMessageText( + `You we're returned to the admin menu`, + { + chat_id: chatId, + message_id: messageId, + reply_markup: keyboard + } + ); + } } \ No newline at end of file diff --git a/src/index.js b/src/index.js index e88cb4c..e14cada 100644 --- a/src/index.js +++ b/src/index.js @@ -214,7 +214,10 @@ bot.on('callback_query', async (callbackQuery) => { } else if (action.startsWith('confirm_delete_')) { logDebug(action, 'handleConfirmDelete'); await adminLocationHandler.handleConfirmDelete(callbackQuery); + } else if (action === 'admin_menu') { + await adminHandler.handleAdminQueryCommand(callbackQuery); } + // Admin product management else if (action === 'manage_products') { logDebug(action, 'handleProductManagement');