Skip to content

Commit

Permalink
fix restart problem for premium users
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-markin committed Jun 16, 2024
1 parent 5b582cc commit 150011d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const insertMessage = async ({role, content, chat_id, user_id}: MyMessage
return res.rows[0];
}

export const insertUserOrUpdate = async ({user_id, username, default_language_code, language_code=default_language_code, openai_api_key=null, usage_type}: User) => {
export const insertUserOrUpdate = async ({user_id, username, default_language_code, language_code=default_language_code, openai_api_key=null, usage_type=null}: User) => {
try {
const res = await pool.query(`
INSERT INTO users (user_id, username, default_language_code, language_code, openai_api_key, usage_type, created_at)
Expand All @@ -59,8 +59,8 @@ export const insertUserOrUpdate = async ({user_id, username, default_language_co
username = EXCLUDED.username,
default_language_code = EXCLUDED.default_language_code,
language_code = EXCLUDED.language_code,
openai_api_key = EXCLUDED.openai_api_key,
usage_type = EXCLUDED.usage_type,
openai_api_key = COALESCE(EXCLUDED.openai_api_key, users.openai_api_key),
usage_type = COALESCE(EXCLUDED.usage_type, users.usage_type),
created_at = COALESCE(users.created_at, EXCLUDED.created_at)
RETURNING *;
`, [user_id, username, default_language_code, language_code, openai_api_key, usage_type]);
Expand Down

0 comments on commit 150011d

Please sign in to comment.