Skip to content

Commit

Permalink
update: get_or_create function
Browse files Browse the repository at this point in the history
  • Loading branch information
nrjadkry committed Jul 10, 2024
1 parent 2ea7755 commit 407626b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/backend/app/users/user_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 407626b

Please sign in to comment.