Back to admin menu fix
This commit is contained in:
@@ -1,35 +1,60 @@
|
|||||||
import db from '../config/database.js';
|
|
||||||
import config from '../config/config.js';
|
import config from '../config/config.js';
|
||||||
|
|
||||||
export default class AdminHandler {
|
export default class AdminHandler {
|
||||||
constructor(bot) {
|
constructor(bot) {
|
||||||
this.bot = 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const keyboard = {
|
isAdmin(userId) {
|
||||||
reply_markup: {
|
return config.ADMIN_IDS.includes(userId.toString());
|
||||||
keyboard: [
|
}
|
||||||
['👥 Manage Users', '📦 Manage Products'],
|
|
||||||
['💰 Manage Wallets', '📍 Manage Locations'],
|
|
||||||
['💾 Database Backup']
|
|
||||||
],
|
|
||||||
resize_keyboard: true
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -214,7 +214,10 @@ bot.on('callback_query', async (callbackQuery) => {
|
|||||||
} else if (action.startsWith('confirm_delete_')) {
|
} else if (action.startsWith('confirm_delete_')) {
|
||||||
logDebug(action, 'handleConfirmDelete');
|
logDebug(action, 'handleConfirmDelete');
|
||||||
await adminLocationHandler.handleConfirmDelete(callbackQuery);
|
await adminLocationHandler.handleConfirmDelete(callbackQuery);
|
||||||
|
} else if (action === 'admin_menu') {
|
||||||
|
await adminHandler.handleAdminQueryCommand(callbackQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Admin product management
|
// Admin product management
|
||||||
else if (action === 'manage_products') {
|
else if (action === 'manage_products') {
|
||||||
logDebug(action, 'handleProductManagement');
|
logDebug(action, 'handleProductManagement');
|
||||||
|
|||||||
Reference in New Issue
Block a user