Mamadou DICKO 2023-10-11 09:46:57 +02:00 committed by GitHub
parent 0477cce971
commit 1baf9ee5b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 10 deletions

View File

@ -263,3 +263,7 @@ class Repository(ABC):
@abstractmethod
def update_user_onboarding(self, user_id: UUID, onboarding):
pass
@abstractmethod
def remove_user_onboarding(self, user_id: UUID):
pass

View File

@ -76,3 +76,19 @@ class Onboarding(Repository):
raise HTTPException(404, "User onboarding not updated")
return OnboardingStates(**response[0])
def remove_user_onboarding(self, user_id: UUID) -> OnboardingStates | None:
"""
Remove user onboarding information by user_id
"""
onboarding_data = (
self.db.from_("onboardings")
.delete()
.match({"user_id": str(user_id)})
.execute()
).data
if onboarding_data == []:
return None
return OnboardingStates(**onboarding_data[0])

View File

@ -13,4 +13,9 @@ def update_user_onboarding(
"""Update user onboarding information by user_id"""
supabase_db = get_supabase_db()
return supabase_db.update_user_onboarding(user_id, onboarding)
updated_onboarding = supabase_db.update_user_onboarding(user_id, onboarding)
if all(not value for value in onboarding.dict().values()):
supabase_db.remove_user_onboarding(user_id)
return updated_onboarding

View File

@ -9,7 +9,7 @@ from models.databases.supabase.onboarding import (
)
from models.user_identity import UserIdentity
from repository.onboarding.get_user_onboarding import get_user_onboarding
from repository.onboarding.udpate_user_onboarding import update_user_onboarding
from repository.onboarding.update_user_onboarding import update_user_onboarding
onboarding_router = APIRouter()

View File

@ -17,18 +17,18 @@ export const useOnboarding = () => {
const chatId = params?.chatId as string | undefined;
const {
data: onboarding = {
onboarding_a: false,
onboarding_b1: false,
onboarding_b2: false,
onboarding_b3: false,
},
} = useQuery({
const { data } = useQuery({
queryFn: getOnboarding,
queryKey: [ONBOARDING_DATA_KEY],
});
const onboarding: Onboarding = data ?? {
onboarding_a: false,
onboarding_b1: false,
onboarding_b2: false,
onboarding_b3: false,
};
const updateOnboardingHandler = async (
newOnboardingStatus: Partial<Onboarding>
) => {