diff --git a/src/hh/bot-commands.ts b/src/hh/bot-commands.ts index 00328a0..26ebf7b 100644 --- a/src/hh/bot-commands.ts +++ b/src/hh/bot-commands.ts @@ -39,7 +39,11 @@ async function doLogin(chatId: number, email: string): Promise { await bot.sendMessage(chatId, '🔄 Логинюсь...') try { await login(email, chatId) - await prisma.user.update({ where: { telegramId: chatId }, data: { hhEmail: email } }) + await prisma.user.upsert({ + where: { telegramId: chatId }, + update: { hhEmail: email }, + create: { telegramId: chatId, hhEmail: email, Settings: { create: {} } }, + }) const state = getState(chatId) @@ -380,9 +384,10 @@ export function registerHHCommands() { if (state.awaitingPrompt) { state.awaitingPrompt = false await bot.deleteMessage(chatId, msg.message_id).catch(() => {}) - await prisma.user.update({ + await prisma.user.upsert({ where: { telegramId: chatId }, - data: { prompt: msg.text }, + update: { prompt: msg.text }, + create: { telegramId: chatId, prompt: msg.text, Settings: { create: {} } }, }) await bot.sendMessage(chatId, '✅ Промт сохранён') return diff --git a/src/hh/scraper.ts b/src/hh/scraper.ts index a10f839..a0b359e 100644 --- a/src/hh/scraper.ts +++ b/src/hh/scraper.ts @@ -96,9 +96,10 @@ export async function login(email: string, chatId: number): Promise { await page.waitForSelector('[data-qa="profileAndResumes-button"]', { timeout: 15000 }) const cookies = await context.cookies() - await prisma.user.update({ + await prisma.user.upsert({ where: { telegramId: chatId }, - data: { session: JSON.stringify(cookies, null, 2) }, + update: { session: JSON.stringify(cookies, null, 2) }, + create: { telegramId: chatId, session: JSON.stringify(cookies, null, 2), Settings: { create: {} } }, }) await bot.sendMessage(chatId, cookies.length > 0 ? '✅ Авторизация выполнена' : '❌ Произошла ошибка')