account deletion

This commit is contained in:
Artyom Ashirov
2024-12-05 21:29:32 +03:00
parent e3b82bb3dd
commit 82ffa81141
2 changed files with 60 additions and 0 deletions

View File

@@ -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.');
}
}
}