Files
zellyy-finance/src/utils/syncUtils.ts
gpt-engineer-app[bot] 3bb4781ff0 Address accessibility issue
The screen was not visible. This commit addresses an accessibility issue.
2025-03-15 05:18:48 +00:00

53 lines
1.6 KiB
TypeScript

import { isSyncEnabled, setSyncEnabled, getLastSyncTime, setLastSyncTime, initSyncSettings } from './sync/syncSettings';
import { uploadTransactions, downloadTransactions } from './sync/transactionSync';
import { uploadBudgets, downloadBudgets } from './sync/budgetSync';
// Export all utility functions to maintain the same public API
export {
isSyncEnabled,
setSyncEnabled,
uploadTransactions,
downloadTransactions,
uploadBudgets,
downloadBudgets,
getLastSyncTime,
setLastSyncTime,
initSyncSettings
};
/**
* Synchronize all data with Supabase
*/
export const syncAllData = async (userId: string): Promise<void> => {
if (!userId || !isSyncEnabled()) return;
try {
console.log('데이터 동기화 시작...');
await downloadTransactions(userId);
await downloadBudgets(userId);
await uploadTransactions(userId);
await uploadBudgets(userId);
// 동기화 시간 업데이트
setLastSyncTime();
console.log('데이터 동기화 완료!');
} catch (error) {
console.error('동기화 중 오류 발생:', error);
throw error; // 오류를 상위 호출자에게 전달하여 적절히 처리하도록 함
}
};
// 안전하게 동기화 시도하는 함수 추가
export const trySyncAllData = async (userId: string): Promise<{ success: boolean, error?: any }> => {
if (!userId || !isSyncEnabled()) return { success: true };
try {
await syncAllData(userId);
return { success: true };
} catch (error) {
console.error('동기화 시도 중 오류:', error);
return { success: false, error };
}
};