- Implemented subjects API with functions for creating, updating, and retrieving subjects, including history and bibliography. - Added tasks API for managing user tasks, including listing and marking tasks as completed. - Created hooks for managing AI interactions, authentication, subjects, tasks, and metadata queries. - Established query keys for caching and managing query states. - Introduced Supabase client and environment variable management for better configuration. - Defined types for database and domain models to ensure type safety across the application.
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { supabaseBrowser } from "../supabase/client";
|
|
import { throwIfError, getUserIdOrThrow, requireData } from "./_helpers";
|
|
import type { TareaRevision, UUID } from "../types/domain";
|
|
|
|
export async function tareas_mias_list(): Promise<TareaRevision[]> {
|
|
const supabase = supabaseBrowser();
|
|
const userId = await getUserIdOrThrow(supabase);
|
|
|
|
const { data, error } = await supabase
|
|
.from("tareas_revision")
|
|
.select("id,plan_estudio_id,asignado_a,rol_id,estado_id,estatus,fecha_limite,creado_en,completado_en")
|
|
.eq("asignado_a", userId as UUID)
|
|
.order("creado_en", { ascending: false });
|
|
|
|
throwIfError(error);
|
|
return data ?? [];
|
|
}
|
|
|
|
export async function tareas_marcar_completada(tareaId: UUID): Promise<TareaRevision> {
|
|
const supabase = supabaseBrowser();
|
|
|
|
const { data, error } = await supabase
|
|
.from("tareas_revision")
|
|
.update({ estatus: "COMPLETADA", completado_en: new Date().toISOString() })
|
|
.eq("id", tareaId)
|
|
.select("id,plan_estudio_id,asignado_a,rol_id,estado_id,estatus,fecha_limite,creado_en,completado_en")
|
|
.single();
|
|
|
|
throwIfError(error);
|
|
return requireData(data, "No se pudo marcar tarea.");
|
|
}
|