diff --git a/src/stores/projects.ts b/src/stores/projects.ts index 05c54bc..c7f1aab 100644 --- a/src/stores/projects.ts +++ b/src/stores/projects.ts @@ -31,7 +31,7 @@ export const useProjectsStore = defineStore('projects', () => { initiative_name: p.initiative_name || p.name, })) - syncToTurso(projects.value) + await syncToTurso(projects.value) } catch (e: any) { error.value = e.message } finally { @@ -39,19 +39,29 @@ export const useProjectsStore = defineStore('projects', () => { } } + function toStr(v: unknown): string | null { + if (v === null || v === undefined) return null + return String(v) + } + async function syncToTurso(list: KappaInitiative[]) { + console.log(`[Alpha] Syncing ${list.length} projects to Turso`) for (const p of list) { - await tauriDb.saveProject({ - id: p.id, - name: p.initiative_name || p.name || `Proyecto ${p.id}`, - key: p.key ?? null, - description: p.description ?? null, - status: p.status || 'active', - start_date: p.start_date ?? null, - end_date: p.end_date ?? null, - hus_count: null, - epics_count: null, - }).catch(() => {}) + try { + await tauriDb.saveProject({ + id: Number(p.id) || 0, + name: p.initiative_name || p.name || `Proyecto ${p.id}`, + key: toStr(p.key), + description: toStr(p.description), + status: toStr(p.status) || 'active', + start_date: toStr(p.start_date), + end_date: toStr(p.end_date), + hus_count: null, + epics_count: null, + }) + } catch (e) { + console.error(`[Alpha] Failed to save project ${p.id}:`, e) + } } }