User start registration update function

This commit is contained in:
NW 2024-12-16 12:37:44 +00:00
parent 2cfa37ea86
commit d51bc9f0b9
2 changed files with 27 additions and 19 deletions

View File

@ -539,6 +539,22 @@ export default class UserProductHandler {
// Получение баланса пользователя
const userBalance = await UserService.getUserBalance(user.id);
// Проверка баланса пользователя
if (userBalance <= 0) {
await bot.sendMessage(
chatId,
`❌ Insufficient balance. Your current balance is $${userBalance}. You need $${totalPrice} to complete this purchase.`,
{
reply_markup: {
inline_keyboard: [[
{ text: '💰 Top Up Balance', callback_data: 'top_up_wallet' }
]]
}
}
);
return;
}
if (userBalance < totalPrice) {
await bot.sendMessage(
chatId,

View File

@ -51,31 +51,23 @@ class UserService {
static async createUser(userData) {
try {
const existingUser = await this.getUserByTelegramId(userData?.telegram_id);
if (existingUser) {
return existingUser.id;
}
const fields = Object.keys(userData);
const values = [];
for (const field of fields) {
values.push(userData[field]);
}
const marks = [];
for (let i = 0; i < fields.length; i++) {
marks.push("?");
}
const query = [
`INSERT INTO users (${fields.join(', ')})`,
`VALUES (${marks.join(', ')})`
].join("");
const marks = Array(fields.length).fill('?');
const query = `
INSERT INTO users (${fields.join(', ')})
VALUES (${marks.join(', ')})
`;
await db.runAsync('BEGIN TRANSACTION');
const result = await db.runAsync(query, [values]);
const result = await db.runAsync(query, Object.values(userData));
await db.runAsync('COMMIT');
return result.lastID;
} catch (error) {
await db.runAsync('ROLLBACK');