From e3b82bb3dde923956a34bedd99b2494e9922ae40 Mon Sep 17 00:00:00 2001 From: Artyom Ashirov <1323ED5@gmail.com> Date: Thu, 5 Dec 2024 16:18:27 +0300 Subject: [PATCH 1/2] pay with main balance --- src/handlers/userHandlers/userProductHandler.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/handlers/userHandlers/userProductHandler.js b/src/handlers/userHandlers/userProductHandler.js index 5107030..fa4e1e8 100644 --- a/src/handlers/userHandlers/userProductHandler.js +++ b/src/handlers/userHandlers/userProductHandler.js @@ -535,10 +535,7 @@ Subcategory: ${product.subcategory_name} const keyboard = { inline_keyboard: [ - ...cryptoWallets.map(wallet => [{ - text: `Pay with ${wallet.wallet_type}`, - callback_data: `pay_with_${wallet.wallet_type}_${productId}_${quantity}` - }]), + [{ text: `Pay`, callback_data: `pay_with_main_${productId}_${quantity}` }], [{text: '« Cancel', callback_data: `shop_product_${productId}`}] ] }; @@ -547,8 +544,7 @@ Subcategory: ${product.subcategory_name} `🛒 Purchase Summary:\n\n` + `Product: ${product.name}\n` + `Quantity: ${quantity}\n` + - `Total: $${totalPrice}\n\n` + - `Select payment method:`, + `Total: $${totalPrice}\n`, { chat_id: chatId, message_id: callbackQuery.message.message_id, -- 2.45.2 From 82ffa8114150eb53f8a1e5db288934fcb9a1ab2d Mon Sep 17 00:00:00 2001 From: Artyom Ashirov <1323ED5@gmail.com> Date: Thu, 5 Dec 2024 21:29:32 +0300 Subject: [PATCH 2/2] account deletion --- .../userHandlers/userDeletionHandler.js | 53 +++++++++++++++++++ src/index.js | 7 +++ 2 files changed, 60 insertions(+) create mode 100644 src/handlers/userHandlers/userDeletionHandler.js diff --git a/src/handlers/userHandlers/userDeletionHandler.js b/src/handlers/userHandlers/userDeletionHandler.js new file mode 100644 index 0000000..7267950 --- /dev/null +++ b/src/handlers/userHandlers/userDeletionHandler.js @@ -0,0 +1,53 @@ +import config from '../../config/config.js'; +import db from '../../config/database.js'; +import bot from "../../context/bot.js"; +import UserService from "../../services/userService.js"; +import userStates from "../../context/userStates.js"; + +export default class UserDeletionHandler { + static async handleDeleteAccount(callbackQuery) { + const telegramId = callbackQuery.from.id; + const chatId = callbackQuery.message.chat.id; + + try { + const keyboard = { + inline_keyboard: [ + [ + {text: '✅ Confirm Delete', callback_data: `confirm_delete_account`}, + {text: '❌ Cancel', callback_data: `back_to_profile`} + ] + ] + }; + + await bot.editMessageText( + `⚠️ Are you sure you want to delete your account?\n\nThis action will:\n- Delete all user data\n- Remove all wallets\n- Erase purchase history\n\nThis action cannot be undone!`, + { + chat_id: chatId, + message_id: callbackQuery.message.message_id, + reply_markup: keyboard, + parse_mode: 'HTML' + } + ); + } catch (error) { + console.error('Error in handleDeleteUser:', error); + await bot.sendMessage(chatId, 'Error processing delete request. Please try again.'); + } + } + + static async handleConfirmDelete(callbackQuery) { + const telegramId = callbackQuery.from.id; + const chatId = callbackQuery.message.chat.id; + + try { + await UserService.updateUserStatus(telegramId, 1); + + await bot.editMessageText( + '⚠️Your account has been successful deleted', + { chat_id: chatId, message_id: callbackQuery.message.message_id, } + ); + } catch (error) { + console.error('Error in handleConfirmDelete:', error); + await bot.sendMessage(chatId, 'Error deleting user. Please try again.'); + } + } +} \ No newline at end of file diff --git a/src/index.js b/src/index.js index 4951c5b..0df0a90 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,7 @@ import userPurchaseHandler from "./handlers/userHandlers/userPurchaseHandler.js" import userLocationHandler from "./handlers/userHandlers/userLocationHandler.js"; import userProductHandler from "./handlers/userHandlers/userProductHandler.js"; import userWalletsHandler from "./handlers/userHandlers/userWalletsHandler.js"; +import userDeletionHandler from "./handlers/userHandlers/userDeletionHandler.js"; import adminHandler from "./handlers/adminHandlers/adminHandler.js"; import adminUserLocationHandler from "./handlers/adminHandlers/adminUserLocationHandler.js"; import adminDumpHandler from "./handlers/adminHandlers/adminDumpHandler.js"; @@ -171,6 +172,12 @@ bot.on('callback_query', async (callbackQuery) => { } else if (action === 'back_to_balance') { logDebug(action, 'handleBackToBalance'); await userWalletsHandler.handleBackToBalance(callbackQuery); + } else if (action === 'delete_account') { + logDebug(action, 'handleDeleteAccount'); + await userDeletionHandler.handleDeleteAccount(callbackQuery); + } else if (action === 'confirm_delete_account') { + logDebug(action, 'handleConfirmDelete'); + await userDeletionHandler.handleConfirmDelete(callbackQuery); } // Wallet management else if (action === 'add_wallet') { -- 2.45.2