feat: add subjects and tasks API, hooks, and related types
- 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.
This commit is contained in:
31
src/data/api/notifications.api.ts
Normal file
31
src/data/api/notifications.api.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { supabaseBrowser } from "../supabase/client";
|
||||
import { throwIfError, getUserIdOrThrow, requireData } from "./_helpers";
|
||||
import type { Notificacion, UUID } from "../types/domain";
|
||||
|
||||
export async function notificaciones_mias_list(): Promise<Notificacion[]> {
|
||||
const supabase = supabaseBrowser();
|
||||
const userId = await getUserIdOrThrow(supabase);
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from("notificaciones")
|
||||
.select("id,usuario_id,tipo,payload,leida,creado_en,leida_en")
|
||||
.eq("usuario_id", userId as UUID)
|
||||
.order("creado_en", { ascending: false });
|
||||
|
||||
throwIfError(error);
|
||||
return data ?? [];
|
||||
}
|
||||
|
||||
export async function notificaciones_marcar_leida(notificacionId: UUID): Promise<Notificacion> {
|
||||
const supabase = supabaseBrowser();
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from("notificaciones")
|
||||
.update({ leida: true, leida_en: new Date().toISOString() })
|
||||
.eq("id", notificacionId)
|
||||
.select("id,usuario_id,tipo,payload,leida,creado_en,leida_en")
|
||||
.single();
|
||||
|
||||
throwIfError(error);
|
||||
return requireData(data, "No se pudo marcar notificación.");
|
||||
}
|
||||
Reference in New Issue
Block a user