close #10: Al crear un plan de manera manual o con IA y redirigirse a planes/{$planId}/datos, sale el confetti. close #21: Los archivos que se adjuntan en el wizard ya no se pueden subir mas que una vez. close #24: El input de número de ciclos ahora solo permite enteros positivos mayores a 0. close #25: Se quitó el botón de generar borrador. Al adjuntar el primer archivo al wizard, se hace scroll hasta el dropzone. Los archivos añadidos se listan desde el más reciente al más antiguo. Se indica claramente el número de archivos adjuntos y el número máximo de archivos que se pueden adjuntar.
This commit is contained in:
@@ -3,6 +3,7 @@ import { invokeEdge } from '../supabase/invokeEdge'
|
||||
|
||||
import { buildRange, requireData, throwIfError } from './_helpers'
|
||||
|
||||
import type { Database } from '../../types/supabase'
|
||||
import type {
|
||||
Asignatura,
|
||||
CambioPlan,
|
||||
@@ -201,7 +202,56 @@ export type PlansCreateManualInput = {
|
||||
export async function plans_create_manual(
|
||||
input: PlansCreateManualInput,
|
||||
): Promise<PlanEstudio> {
|
||||
return invokeEdge<PlanEstudio>(EDGE.plans_create_manual, input)
|
||||
const supabase = supabaseBrowser()
|
||||
|
||||
// 1. Obtener estado 'BORRADOR'
|
||||
const { data: estado, error: estadoError } = await supabase
|
||||
.from('estados_plan')
|
||||
.select('id,clave,orden')
|
||||
.ilike('clave', 'BORRADOR%')
|
||||
.order('orden', { ascending: true })
|
||||
.limit(1)
|
||||
.maybeSingle()
|
||||
|
||||
if (estadoError) {
|
||||
throw new Error(estadoError.message)
|
||||
}
|
||||
|
||||
// 2. Preparar insert
|
||||
const planInsert: Database['public']['Tables']['planes_estudio']['Insert'] = {
|
||||
activo: true,
|
||||
actualizado_en: new Date().toISOString(),
|
||||
carrera_id: input.carreraId,
|
||||
creado_en: new Date().toISOString(),
|
||||
datos: input.datos || {},
|
||||
estado_actual_id: estado?.id || null,
|
||||
estructura_id: input.estructuraId,
|
||||
nivel: input.nivel,
|
||||
nombre: input.nombre,
|
||||
numero_ciclos: input.numCiclos,
|
||||
tipo_ciclo: input.tipoCiclo,
|
||||
tipo_origen: 'MANUAL',
|
||||
}
|
||||
|
||||
// 3. Insertar
|
||||
const { data: nuevoPlan, error: planError } = await supabase
|
||||
.from('planes_estudio')
|
||||
.insert([planInsert])
|
||||
.select(
|
||||
`
|
||||
*,
|
||||
carreras (*, facultades(*)),
|
||||
estructuras_plan (*),
|
||||
estados_plan (*)
|
||||
`,
|
||||
)
|
||||
.single()
|
||||
|
||||
if (planError) {
|
||||
throw new Error(planError.message)
|
||||
}
|
||||
|
||||
return nuevoPlan as unknown as PlanEstudio
|
||||
}
|
||||
|
||||
/** Wizard: IA genera preview JSON (Edge Function) */
|
||||
|
||||
Reference in New Issue
Block a user