chore: clean up code by removing trailing whitespace and ensuring consistent formatting across various files = prettier

This commit is contained in:
Julien Froidefond
2025-12-01 08:37:30 +01:00
parent 757b1b84ab
commit e715779de7
98 changed files with 5453 additions and 3126 deletions

View File

@@ -14,7 +14,11 @@ export interface BackupSettings {
nextBackup?: string;
}
const SETTINGS_FILE = path.join(process.cwd(), "prisma", "backup-settings.json");
const SETTINGS_FILE = path.join(
process.cwd(),
"prisma",
"backup-settings.json",
);
async function ensureBackupDir() {
if (!existsSync(BACKUP_DIR)) {
@@ -48,20 +52,20 @@ function getDatabasePath(): string {
}
// Remove "file:" prefix if present
let cleanUrl = dbUrl.replace(/^file:/, "");
// Handle absolute paths
if (path.isAbsolute(cleanUrl)) {
return cleanUrl;
}
// Handle relative paths - normalize "./" prefix
if (cleanUrl.startsWith("./")) {
cleanUrl = cleanUrl.substring(2);
}
// Resolve relative to process.cwd()
const resolvedPath = path.resolve(process.cwd(), cleanUrl);
// If file doesn't exist, try common locations
if (!existsSync(resolvedPath)) {
// Try in prisma/ directory
@@ -69,7 +73,7 @@ function getDatabasePath(): string {
if (existsSync(prismaPath)) {
return prismaPath;
}
// Try just the filename in prisma/
const filename = path.basename(cleanUrl);
const prismaFilenamePath = path.resolve(process.cwd(), "prisma", filename);
@@ -77,7 +81,7 @@ function getDatabasePath(): string {
return prismaFilenamePath;
}
}
return resolvedPath;
}
@@ -120,7 +124,7 @@ async function calculateDataHash(): Promise<string> {
// Create a deterministic string representation of all data
const dataString = JSON.stringify({
accounts: accounts.map(a => ({
accounts: accounts.map((a) => ({
id: a.id,
name: a.name,
bankId: a.bankId,
@@ -132,7 +136,7 @@ async function calculateDataHash(): Promise<string> {
lastImport: a.lastImport,
externalUrl: a.externalUrl,
})),
transactions: transactions.map(t => ({
transactions: transactions.map((t) => ({
id: t.id,
accountId: t.accountId,
date: t.date,
@@ -145,14 +149,14 @@ async function calculateDataHash(): Promise<string> {
memo: t.memo,
checkNum: t.checkNum,
})),
folders: folders.map(f => ({
folders: folders.map((f) => ({
id: f.id,
name: f.name,
parentId: f.parentId,
color: f.color,
icon: f.icon,
})),
categories: categories.map(c => ({
categories: categories.map((c) => ({
id: c.id,
name: c.name,
color: c.color,
@@ -166,7 +170,14 @@ async function calculateDataHash(): Promise<string> {
}
export const backupService = {
async createBackup(force: boolean = false): Promise<{ id: string; filename: string; size: number; skipped?: boolean }> {
async createBackup(
force: boolean = false,
): Promise<{
id: string;
filename: string;
size: number;
skipped?: boolean;
}> {
await ensureBackupDir();
const dbPath = getDatabasePath();
@@ -195,7 +206,9 @@ export const backupService = {
// Update settings to reflect that backup is still current
const settings = await loadSettings();
settings.lastBackup = new Date().toISOString();
settings.nextBackup = getNextBackupDate(settings.frequency).toISOString();
settings.nextBackup = getNextBackupDate(
settings.frequency,
).toISOString();
await saveSettings(settings);
// Return existing backup without creating a new file
@@ -263,7 +276,10 @@ export const backupService = {
await fs.unlink(backup.filePath);
}
} catch (error) {
console.error(`Error deleting backup file ${backup.filePath}:`, error);
console.error(
`Error deleting backup file ${backup.filePath}:`,
error,
);
}
// Delete metadata
@@ -339,7 +355,9 @@ export const backupService = {
return loadSettings();
},
async updateSettings(settings: Partial<BackupSettings>): Promise<BackupSettings> {
async updateSettings(
settings: Partial<BackupSettings>,
): Promise<BackupSettings> {
const current = await loadSettings();
const updated = { ...current, ...settings };
@@ -367,4 +385,3 @@ export const backupService = {
return new Date() >= nextBackupDate;
},
};