Nickname added
This commit is contained in:
parent
a3bde60b87
commit
52779d20ab
BIN
db/shop.db
BIN
db/shop.db
Binary file not shown.
@ -90,6 +90,7 @@ const initDb = async () => {
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
telegram_id TEXT UNIQUE NOT NULL,
|
||||
username TEXT,
|
||||
country TEXT,
|
||||
city TEXT,
|
||||
district TEXT,
|
||||
|
@ -31,7 +31,6 @@ export default class AdminUserHandler {
|
||||
GROUP BY u.id
|
||||
ORDER BY u.created_at DESC
|
||||
`);
|
||||
|
||||
if (users.length === 0) {
|
||||
await this.bot.sendMessage(msg.chat.id, 'No users registered yet.');
|
||||
return;
|
||||
@ -54,7 +53,7 @@ export default class AdminUserHandler {
|
||||
// Create inline keyboard with user list
|
||||
const keyboard = {
|
||||
inline_keyboard: users.map(user => [{
|
||||
text: `ID: ${user.telegram_id} | Balance: $${user.total_balance || 0}`,
|
||||
text: `ID: ${user.telegram_id} | Nickname: ${user.username? "@" + user.username: "None"} | Balance: $${user.total_balance || 0}`,
|
||||
callback_data: `view_user_${user.telegram_id}`
|
||||
}])
|
||||
};
|
||||
|
@ -57,10 +57,11 @@ export default class UserHandler {
|
||||
async handleStart(msg) {
|
||||
const chatId = msg.chat.id;
|
||||
const userId = msg.from.id;
|
||||
const username = msg.chat.username;
|
||||
|
||||
try {
|
||||
// Create user profile
|
||||
await User.create(userId);
|
||||
await User.create(userId, username);
|
||||
|
||||
const keyboard = {
|
||||
reply_markup: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import db from '../config/database.js';
|
||||
|
||||
export default class User {
|
||||
static async create(telegramId) {
|
||||
static async create(telegramId, username) {
|
||||
try {
|
||||
// First check if user exists
|
||||
const existingUser = await this.getById(telegramId);
|
||||
@ -14,8 +14,8 @@ export default class User {
|
||||
|
||||
// Create new user
|
||||
const result = await db.runAsync(
|
||||
'INSERT INTO users (telegram_id) VALUES (?)',
|
||||
[telegramId.toString()]
|
||||
'INSERT INTO users (telegram_id, username) VALUES (?, ?)',
|
||||
[telegramId.toString(), username]
|
||||
);
|
||||
|
||||
// Commit transaction
|
||||
|
Loading…
Reference in New Issue
Block a user