feat: Add optional fields to UserIdentity and UserUpdatableProperties (#2341)

This pull request adds optional fields to the UserIdentity and
UserUpdatableProperties classes in order to allow for more flexibility
when updating user properties. The new fields include username, company,
and onboarded. Additionally, the database schema has been updated to
reflect these changes.
This commit is contained in:
Stan Girard 2024-03-12 19:47:45 -07:00 committed by GitHub
parent 6754829d8b
commit 1a52ec38d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 4 deletions

View File

@ -1,6 +1,10 @@
from typing import Optional
from pydantic import BaseModel
class UserUpdatableProperties(BaseModel):
# Nothing for now
empty: bool = True
username: Optional[str] = None
company: Optional[str] = None
onboarded: Optional[bool] = None

View File

@ -7,3 +7,6 @@ from pydantic import BaseModel
class UserIdentity(BaseModel):
id: UUID
email: Optional[str] = None
username: Optional[str] = None
company: Optional[str] = None
onboarded: Optional[bool] = None

View File

@ -44,7 +44,7 @@ class Users(UsersInterface):
def get_user_identity(self, user_id):
response = (
self.db.from_("user_identity")
.select("*")
.select("*, users (email)")
.filter("user_id", "eq", str(user_id))
.execute()
)
@ -53,8 +53,10 @@ class Users(UsersInterface):
return self.create_user_identity(user_id)
user_identity = response.data[0]
print("USER_IDENTITY", user_identity)
return UserIdentity(id=user_id)
user_identity["id"] = user_id # Add 'id' field to the dictionary
user_identity["email"] = user_identity["users"]["email"]
return UserIdentity(**user_identity)
def get_user_id_by_user_email(self, email):
response = (

View File

@ -0,0 +1,15 @@
alter table "public"."user_identity" drop constraint "user_identity_user_id_fkey";
alter table "public"."user_identity" add column "company" text;
alter table "public"."user_identity" add column "onboarded" boolean not null default false;
alter table "public"."user_identity" add column "username" text;
alter table "public"."users" add column "onboarded" boolean not null default false;
alter table "public"."user_identity" add constraint "public_user_identity_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
alter table "public"."user_identity" validate constraint "public_user_identity_user_id_fkey";