Update database query and key handling in admin user editor

- Modify get_keys function to return all columns in keys table
- Update admin user editor to handle full key record instead of just email
- Cast tg_id to integer in user record processing
- Adjust key display and callback data generation to use full key record
This commit is contained in:
Zakhar Izmaylov
2025-01-31 02:41:40 +03:00
parent 2b006ecae4
commit 23c6c903ee
2 changed files with 8 additions and 8 deletions
+1 -1
View File
@@ -433,7 +433,7 @@ async def get_keys(tg_id: int, session: Any):
try:
records = await session.fetch(
"""
SELECT client_id, email, created_at, key
SELECT *
FROM keys
WHERE tg_id = $1
""",
+7 -7
View File
@@ -72,7 +72,7 @@ async def handle_username_input(message: types.Message, state: FSMContext, sessi
await state.clear()
return
tg_id = user_record["tg_id"]
tg_id = int(user_record["tg_id"])
username = await session.fetchval("SELECT username FROM users WHERE tg_id = $1", tg_id)
balance = await session.fetchval("SELECT balance FROM connections WHERE tg_id = $1", tg_id)
key_records = await get_keys(tg_id, session)
@@ -90,8 +90,8 @@ async def handle_username_input(message: types.Message, state: FSMContext, sessi
builder = InlineKeyboardBuilder()
for (email,) in key_records:
builder.row(InlineKeyboardButton(text=f"🔑 {email}", callback_data=f"edit_key_{email}"))
for key in key_records:
builder.row(InlineKeyboardButton(text=f"🔑 {key['email']}", callback_data=f"edit_key_{key['email']}"))
builder.row(
InlineKeyboardButton(
@@ -170,8 +170,8 @@ async def handle_tg_id_input(message: types.Message, state: FSMContext, session:
builder = InlineKeyboardBuilder()
for (email,) in key_records:
builder.row(InlineKeyboardButton(text=f"🔑 {email}", callback_data=f"edit_key_{email}"))
for key in key_records:
builder.row(InlineKeyboardButton(text=f"🔑 {key['email']}", callback_data=f"edit_key_{key['email']}"))
builder.row(
InlineKeyboardButton(
@@ -518,8 +518,8 @@ async def handle_user_info(callback_query: types.CallbackQuery, state: FSMContex
builder = InlineKeyboardBuilder()
for (email,) in key_records:
builder.row(InlineKeyboardButton(text=f"🔑 {email}", callback_data=f"edit_key_{email}"))
for key in key_records:
builder.row(InlineKeyboardButton(text=f"🔑 {key['email']}", callback_data=f"edit_key_{key['email']}"))
builder.row(InlineKeyboardButton(text="📝 Изменить баланс", callback_data=f"change_balance_{tg_id}"))
builder.row(InlineKeyboardButton(text="🔄 Восстановить пробник", callback_data=f"restore_trial_{tg_id}"))