diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts index 82d5bdc..18edefe 100644 --- a/src/api/endpoints.ts +++ b/src/api/endpoints.ts @@ -31,7 +31,8 @@ export function logout(): Promise { // --- PULL --- -export function listProjects(): Promise<{ data?: Project[] } | Project[]> { +/** El backend responde `{ projects: [...] }` (ver ProjectApiController@index). */ +export function listProjects(): Promise<{ projects: Project[] }> { return request('/projects'); } @@ -45,7 +46,8 @@ export function getBundle(projectId: number, since?: string): Promise { }); } -export function getTemplates(since?: string): Promise<{ data?: Template[] } | Template[]> { +/** El backend responde `{ templates: [...] }`. */ +export function getTemplates(since?: string): Promise<{ templates: Template[] }> { return request('/templates', { query: since ? { since } : undefined }); } diff --git a/src/screens/ProjectsScreen.tsx b/src/screens/ProjectsScreen.tsx index 8e3dab4..6ca5915 100644 --- a/src/screens/ProjectsScreen.tsx +++ b/src/screens/ProjectsScreen.tsx @@ -19,8 +19,11 @@ import { RootStackParamList } from '../navigation/types'; type Props = NativeStackScreenProps; -function normalize(res: { data?: Project[] } | Project[]): Project[] { - return Array.isArray(res) ? res : res.data ?? []; +/** Tolerante con la forma de la respuesta: `{projects}` (actual), `{data}` o array. */ +function normalize(res: unknown): Project[] { + if (Array.isArray(res)) return res as Project[]; + const obj = (res ?? {}) as { projects?: Project[]; data?: Project[] }; + return obj.projects ?? obj.data ?? []; } export function ProjectsScreen({ navigation }: Props) { @@ -37,7 +40,8 @@ export function ProjectsScreen({ navigation }: Props) { await saveProjectList(list); } setProjects(await getProjects()); - } catch { + } catch (e) { + console.warn('No se pudo refrescar /projects, usando datos locales:', e); setProjects(await getProjects()); // fallback offline } finally { setLoading(false);