This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
set check_function_bodies = off;
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.set_actualizado_en()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
begin
|
||||
new.actualizado_en = now();
|
||||
return new;
|
||||
end;
|
||||
$function$
|
||||
;
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.unaccent_immutable(text)
|
||||
RETURNS text
|
||||
LANGUAGE sql
|
||||
IMMUTABLE PARALLEL SAFE STRICT
|
||||
AS $function$
|
||||
SELECT public.unaccent('public.unaccent', $1);
|
||||
$function$
|
||||
;
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.validar_numero_ciclo_asignatura()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
declare
|
||||
v_numero_ciclos int;
|
||||
begin
|
||||
if new.numero_ciclo is null then
|
||||
return new;
|
||||
end if;
|
||||
|
||||
select pe.numero_ciclos into v_numero_ciclos
|
||||
from planes_estudio pe
|
||||
where pe.id = new.plan_estudio_id;
|
||||
|
||||
if v_numero_ciclos is null then
|
||||
raise exception 'plan_estudio_id inválido %, plan no encontrado', new.plan_estudio_id;
|
||||
end if;
|
||||
|
||||
if new.numero_ciclo < 1 then
|
||||
raise exception 'numero_ciclo debe ser >= 1 (recibido %)', new.numero_ciclo;
|
||||
end if;
|
||||
|
||||
if new.numero_ciclo > v_numero_ciclos then
|
||||
raise exception 'numero_ciclo % excede planes_estudio.numero_ciclos % para plan_estudio_id %',
|
||||
new.numero_ciclo, v_numero_ciclos, new.plan_estudio_id;
|
||||
end if;
|
||||
|
||||
return new;
|
||||
end;
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
@@ -19,12 +19,16 @@ type TipoCicloType =
|
||||
Database["public"]["Tables"]["planes_estudio"]["Insert"]["tipo_ciclo"];
|
||||
|
||||
Deno.serve(async (req) => {
|
||||
const url = new URL(req.url);
|
||||
const functionName = url.pathname.split("/").pop();
|
||||
console.log(
|
||||
`[${new Date().toISOString()}][${functionName}]: Request received`,
|
||||
);
|
||||
|
||||
if (req.method === "OPTIONS") {
|
||||
return new Response(null, { status: 204, headers: corsHeaders });
|
||||
}
|
||||
|
||||
const url = new URL(req.url);
|
||||
const functionName = url.pathname.split("/").pop();
|
||||
try {
|
||||
const method = req.method;
|
||||
if (method !== "POST") {
|
||||
@@ -143,7 +147,7 @@ Deno.serve(async (req) => {
|
||||
: {};
|
||||
|
||||
const aiStructuredPayload: StructuredResponseOptions = {
|
||||
model: "gpt-5-mini",
|
||||
model: "gpt-5-nano",
|
||||
input: [
|
||||
{ role: "system", content: systemPrompt },
|
||||
{ role: "user", content: userPrompt },
|
||||
@@ -241,6 +245,8 @@ Deno.serve(async (req) => {
|
||||
)
|
||||
.single();
|
||||
|
||||
// TODO: interaccion con IA y cambio de estado
|
||||
|
||||
if (planError) {
|
||||
throw new Error("Error inserting plan: " + planError.message);
|
||||
}
|
||||
@@ -251,6 +257,11 @@ Deno.serve(async (req) => {
|
||||
plan,
|
||||
};
|
||||
|
||||
console.log(
|
||||
`[${
|
||||
new Date().toISOString()
|
||||
}][${functionName}]: Request processed successfully`,
|
||||
);
|
||||
return new Response(
|
||||
JSON.stringify(jsonResponse),
|
||||
{
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
alter type "public"."tipo_cambio" rename to "tipo_cambio__old_version_to_be_dropped";
|
||||
|
||||
create type "public"."tipo_cambio" as enum ('ACTUALIZACION_CAMPO', 'ACTUALIZACION_MAPA', 'TRANSICION_ESTADO', 'OTRO', 'CREACION');
|
||||
|
||||
alter table "public"."cambios_asignatura" alter column tipo type "public"."tipo_cambio" using tipo::text::"public"."tipo_cambio";
|
||||
|
||||
alter table "public"."cambios_plan" alter column tipo type "public"."tipo_cambio" using tipo::text::"public"."tipo_cambio";
|
||||
|
||||
drop type "public"."tipo_cambio__old_version_to_be_dropped";
|
||||
|
||||
set check_function_bodies = off;
|
||||
|
||||
create or replace view "public"."plantilla_plan" as SELECT plan.id AS plan_estudio_id,
|
||||
struct.id AS estructura_id,
|
||||
struct.template_id
|
||||
FROM (public.planes_estudio plan
|
||||
JOIN public.estructuras_plan struct ON ((plan.estructura_id = struct.id)));
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.set_actualizado_en()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
begin
|
||||
new.actualizado_en = now();
|
||||
return new;
|
||||
end;
|
||||
$function$
|
||||
;
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.unaccent_immutable(text)
|
||||
RETURNS text
|
||||
LANGUAGE sql
|
||||
IMMUTABLE PARALLEL SAFE STRICT
|
||||
AS $function$
|
||||
SELECT public.unaccent('public.unaccent', $1);
|
||||
$function$
|
||||
;
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.validar_numero_ciclo_asignatura()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
declare
|
||||
v_numero_ciclos int;
|
||||
begin
|
||||
if new.numero_ciclo is null then
|
||||
return new;
|
||||
end if;
|
||||
|
||||
select pe.numero_ciclos into v_numero_ciclos
|
||||
from planes_estudio pe
|
||||
where pe.id = new.plan_estudio_id;
|
||||
|
||||
if v_numero_ciclos is null then
|
||||
raise exception 'plan_estudio_id inválido %, plan no encontrado', new.plan_estudio_id;
|
||||
end if;
|
||||
|
||||
if new.numero_ciclo < 1 then
|
||||
raise exception 'numero_ciclo debe ser >= 1 (recibido %)', new.numero_ciclo;
|
||||
end if;
|
||||
|
||||
if new.numero_ciclo > v_numero_ciclos then
|
||||
raise exception 'numero_ciclo % excede planes_estudio.numero_ciclos % para plan_estudio_id %',
|
||||
new.numero_ciclo, v_numero_ciclos, new.plan_estudio_id;
|
||||
end if;
|
||||
|
||||
return new;
|
||||
end;
|
||||
$function$
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user