From 407626b1dbe2402d1b5a2d527caab012fc42d62f Mon Sep 17 00:00:00 2001 From: Niraj Adhikari Date: Wed, 10 Jul 2024 11:16:52 +0545 Subject: [PATCH] update: get_or_create function --- src/backend/app/users/user_crud.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/backend/app/users/user_crud.py b/src/backend/app/users/user_crud.py index 28fbbf1f..30d25ff4 100644 --- a/src/backend/app/users/user_crud.py +++ b/src/backend/app/users/user_crud.py @@ -7,7 +7,6 @@ from app.users.user_schemas import AuthUser, ProfileUpdate from databases import Database from fastapi import HTTPException -from app.models.enums import UserRole pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") @@ -103,10 +102,10 @@ async def get_or_create_user( try: update_sql = """ INSERT INTO users ( - id, username, email_address, profile_img, role + id, name, email_address, profile_img, is_active, is_superuser, date_registered ) VALUES ( - :user_id, :username, :email_address, :profile_img, :role + :user_id, :name, :email_address, :profile_img, False, False, now() ) ON CONFLICT (id) DO UPDATE SET profile_img = :profile_img; @@ -116,10 +115,9 @@ async def get_or_create_user( update_sql, { "user_id": str(user_data.id), - "username": user_data.email, # FIXME: remove this + "name": user_data.name, "email_address": user_data.email, "profile_img": user_data.img_url, - "role": UserRole.DRONE_PILOT.name, }, ) return user_data @@ -154,12 +152,13 @@ async def update_user_profile( try: profile_query = """ - INSERT INTO user_profile (user_id, phone_number, country, city, organization_name, organization_address, job_title, notify_for_projects_within_km, + INSERT INTO user_profile (user_id, role, phone_number, country, city, organization_name, organization_address, job_title, notify_for_projects_within_km, experience_years, drone_you_own, certified_drone_operator) - VALUES (:user_id, :phone_number, :country, :city, :organization_name, :organization_address, :job_title, :notify_for_projects_within_km , + VALUES (:user_id, :role, :phone_number, :country, :city, :organization_name, :organization_address, :job_title, :notify_for_projects_within_km , :experience_years, :drone_you_own, :certified_drone_operator) ON CONFLICT (user_id) DO UPDATE SET + role = :role, phone_number = :phone_number, country = :country, city = :city, @@ -176,6 +175,7 @@ async def update_user_profile( profile_query, { "user_id": user_id, + "role": profile_update.role, "phone_number": profile_update.phone_number, "country": profile_update.country, "city": profile_update.city,