From 76243d4c501933e30e043baf10bc030ddbf710dd Mon Sep 17 00:00:00 2001
From: Pradip-p <thapapradip542@gmail.com>
Date: Wed, 1 Jan 2025 10:16:25 +0545
Subject: [PATCH] fix:Ensure password is saved during user creation if provided

- Updated logic to handle cases where a password is provided during profile creation.

Improved user creation flow to avoid incomplete records.

Added checks to hash and save the password if it's present.
---
 src/backend/app/users/user_schemas.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/backend/app/users/user_schemas.py b/src/backend/app/users/user_schemas.py
index 058a8590..a46eb24b 100644
--- a/src/backend/app/users/user_schemas.py
+++ b/src/backend/app/users/user_schemas.py
@@ -251,6 +251,18 @@ async def create(db: Connection, user_id: int, profile_create: UserProfileCreate
         async with db.cursor() as cur:
             await cur.execute(sql, model_data)
 
+            if profile_create.password:
+                password_update_query = """
+                    UPDATE users
+                    SET password = %(password)s
+                    WHERE id = %(user_id)s;
+                """
+                hashed_password = user_logic.get_password_hash(profile_create.password)
+                await cur.execute(
+                    password_update_query,
+                    {"password": hashed_password, "user_id": user_id},
+                )
+
         for file_type, url_key in field_mapping.items():
             if results.get(file_type):
                 model_data[url_key] = results[file_type].get("presigned_url")