feature/admin-section #16
@ -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
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user