✅ Bug Corregido: Orden Automático de Subpreguntas
He identificado y solucionado el bug que causaba que las subpreguntas recién creadas aparecieran al principio (asociadas a la primera pregunta) hasta que las arrastraras. Problema Identificado: Cuando creabas una subpregunta, el backend asignaba order = 0 por defecto, lo que hacía que: La subpregunta apareciera al principio de la lista Al arrastrarla, el sistema recalculaba el orden y la colocaba correctamente debajo de su padre Solución Implementada: Backend (v1.0.93) - main.py: Modifiqué el endpoint POST /api/questions para calcular automáticamente el order correcto al crear una pregunta:
This commit is contained in:
@@ -209,7 +209,7 @@ def send_completed_inspection_to_n8n(inspection, db):
|
||||
# No lanzamos excepción para no interrumpir el flujo normal
|
||||
|
||||
|
||||
BACKEND_VERSION = "1.0.92"
|
||||
BACKEND_VERSION = "1.0.93"
|
||||
app = FastAPI(title="Checklist Inteligente API", version=BACKEND_VERSION)
|
||||
|
||||
# S3/MinIO configuration
|
||||
@@ -963,7 +963,43 @@ def create_question(
|
||||
if current_user.role != "admin":
|
||||
raise HTTPException(status_code=403, detail="No autorizado")
|
||||
|
||||
db_question = models.Question(**question.dict())
|
||||
# Calcular el order correcto automáticamente
|
||||
question_data = question.dict()
|
||||
|
||||
if question_data.get('parent_question_id'):
|
||||
# Es una subpregunta: obtener el order del padre y colocar después de sus hermanos
|
||||
parent_question = db.query(models.Question).filter(
|
||||
models.Question.id == question_data['parent_question_id']
|
||||
).first()
|
||||
|
||||
if parent_question:
|
||||
# Obtener todas las subpreguntas del mismo padre
|
||||
siblings = db.query(models.Question).filter(
|
||||
models.Question.parent_question_id == question_data['parent_question_id']
|
||||
).all()
|
||||
|
||||
if siblings:
|
||||
# Colocar después del último hermano
|
||||
max_sibling_order = max(s.order for s in siblings)
|
||||
question_data['order'] = max_sibling_order + 1
|
||||
else:
|
||||
# Es la primera subpregunta de este padre
|
||||
question_data['order'] = parent_question.order + 1
|
||||
else:
|
||||
# Es pregunta padre: obtener el último order de preguntas padre
|
||||
max_order = db.query(func.max(models.Question.order)).filter(
|
||||
models.Question.checklist_id == question_data['checklist_id'],
|
||||
models.Question.parent_question_id == None
|
||||
).scalar()
|
||||
|
||||
if max_order is not None:
|
||||
# Redondear al siguiente múltiplo de 10 para dejar espacio a subpreguntas
|
||||
question_data['order'] = ((max_order // 10) + 1) * 10
|
||||
else:
|
||||
# Es la primera pregunta del checklist
|
||||
question_data['order'] = 0
|
||||
|
||||
db_question = models.Question(**question_data)
|
||||
db.add(db_question)
|
||||
db.commit()
|
||||
db.refresh(db_question)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "checklist-frontend",
|
||||
"private": true,
|
||||
"version": "1.0.98",
|
||||
"version": "1.0.99",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Service Worker para PWA con detección de actualizaciones
|
||||
// IMPORTANTE: Actualizar esta versión cada vez que se despliegue una nueva versión
|
||||
const CACHE_NAME = 'ayutec-v1.0.98';
|
||||
const CACHE_NAME = 'ayutec-v1.0.99';
|
||||
const urlsToCache = [
|
||||
'/',
|
||||
'/index.html'
|
||||
|
||||
Reference in New Issue
Block a user