mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-15 17:43:03 +03:00
375f50356c
# Description New Modules folder with "user" module: - controller: contains the current route - entity: contains the current Models (TO be renamed DTO) - repository: contains the current repo - service: methods used by other modules ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
from typing import Optional
|
|
from uuid import UUID
|
|
|
|
from models.settings import get_supabase_client
|
|
from modules.user.entity.user_identity import UserIdentity
|
|
from modules.user.repository import create_user_identity
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class UserUpdatableProperties(BaseModel):
|
|
openai_api_key: Optional[str]
|
|
|
|
|
|
def update_user_properties(
|
|
user_id: UUID,
|
|
user_identity_updatable_properties: UserUpdatableProperties,
|
|
) -> UserIdentity:
|
|
supabase_client = get_supabase_client()
|
|
response = (
|
|
supabase_client.from_("user_identity")
|
|
.update(user_identity_updatable_properties.__dict__)
|
|
.filter("user_id", "eq", user_id) # type: ignore
|
|
.execute()
|
|
)
|
|
|
|
if len(response.data) == 0:
|
|
return create_user_identity(
|
|
user_id, openai_api_key=user_identity_updatable_properties.openai_api_key
|
|
)
|
|
|
|
user_identity = response.data[0]
|
|
openai_api_key = user_identity["openai_api_key"]
|
|
|
|
return UserIdentity(id=user_id, openai_api_key=openai_api_key)
|