Update routes/onboarding.py
Browse files- routes/onboarding.py +26 -2
routes/onboarding.py
CHANGED
@@ -102,6 +102,7 @@ async def update_onboarding_question(
|
|
102 |
Atualiza uma pergunta de onboarding com base no ID.
|
103 |
Apenas os campos enviados no payload serão atualizados.
|
104 |
Requer permissão de admin e edit_onboarding=true.
|
|
|
105 |
"""
|
106 |
try:
|
107 |
# Verificar se o usuário é admin e tem permissão para editar onboarding
|
@@ -125,6 +126,7 @@ async def update_onboarding_question(
|
|
125 |
headers = SUPABASE_ROLE_HEADERS.copy()
|
126 |
headers["Prefer"] = "return=representation"
|
127 |
|
|
|
128 |
async with aiohttp.ClientSession() as session:
|
129 |
async with session.patch(query_url, json=update_data, headers=headers) as response:
|
130 |
if response.status != 200:
|
@@ -132,8 +134,30 @@ async def update_onboarding_question(
|
|
132 |
logger.error(f"❌ Erro ao atualizar pergunta: {detail}")
|
133 |
raise HTTPException(status_code=response.status, detail="Erro ao atualizar pergunta")
|
134 |
|
135 |
-
|
136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
except HTTPException as he:
|
139 |
raise he
|
|
|
102 |
Atualiza uma pergunta de onboarding com base no ID.
|
103 |
Apenas os campos enviados no payload serão atualizados.
|
104 |
Requer permissão de admin e edit_onboarding=true.
|
105 |
+
Retorna a pergunta atualizada com todos os seus campos.
|
106 |
"""
|
107 |
try:
|
108 |
# Verificar se o usuário é admin e tem permissão para editar onboarding
|
|
|
126 |
headers = SUPABASE_ROLE_HEADERS.copy()
|
127 |
headers["Prefer"] = "return=representation"
|
128 |
|
129 |
+
# Atualiza os dados
|
130 |
async with aiohttp.ClientSession() as session:
|
131 |
async with session.patch(query_url, json=update_data, headers=headers) as response:
|
132 |
if response.status != 200:
|
|
|
134 |
logger.error(f"❌ Erro ao atualizar pergunta: {detail}")
|
135 |
raise HTTPException(status_code=response.status, detail="Erro ao atualizar pergunta")
|
136 |
|
137 |
+
# Buscar os dados atualizados completos
|
138 |
+
fetch_url = f"{SUPABASE_URL}/rest/v1/Onboarding?id=eq.{payload.id}&select=id,title,description,question_type,options,target_type,optional,lock"
|
139 |
+
async with aiohttp.ClientSession() as session:
|
140 |
+
async with session.get(fetch_url, headers=SUPABASE_HEADERS) as fetch_response:
|
141 |
+
if fetch_response.status != 200:
|
142 |
+
logger.error(f"❌ Erro ao buscar pergunta atualizada: {fetch_response.status}")
|
143 |
+
raise HTTPException(status_code=fetch_response.status, detail="Erro ao buscar pergunta atualizada")
|
144 |
+
|
145 |
+
updated_data = await fetch_response.json()
|
146 |
+
if not updated_data:
|
147 |
+
raise HTTPException(status_code=404, detail="Pergunta atualizada não encontrada")
|
148 |
+
|
149 |
+
question = updated_data[0]
|
150 |
+
formatted = {
|
151 |
+
"id": question["id"],
|
152 |
+
"title": question["title"],
|
153 |
+
"description": question.get("description"),
|
154 |
+
"question_type": question["question_type"],
|
155 |
+
"options": question.get("options", []),
|
156 |
+
"optional": question.get("optional", False),
|
157 |
+
"lock": question.get("lock", False)
|
158 |
+
}
|
159 |
+
|
160 |
+
return {"message": "✅ Pergunta atualizada com sucesso!", "updated": formatted}
|
161 |
|
162 |
except HTTPException as he:
|
163 |
raise he
|