diff --git a/backend/app/main.py b/backend/app/main.py index cb20675..d132cb7 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -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) diff --git a/frontend/package.json b/frontend/package.json index 1855700..72f3d3a 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "checklist-frontend", "private": true, - "version": "1.0.98", + "version": "1.0.99", "type": "module", "scripts": { "dev": "vite", diff --git a/frontend/public/service-worker.js b/frontend/public/service-worker.js index 27499b4..a25bd54 100644 --- a/frontend/public/service-worker.js +++ b/frontend/public/service-worker.js @@ -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'