chore: clean up code by removing trailing whitespace and ensuring consistent formatting across various files = prettier
This commit is contained in:
@@ -20,7 +20,11 @@ async function ensurePasswordFile(): Promise<void> {
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
await fs.writeFile(PASSWORD_FILE, JSON.stringify(defaultData, null, 2), "utf-8");
|
||||
await fs.writeFile(
|
||||
PASSWORD_FILE,
|
||||
JSON.stringify(defaultData, null, 2),
|
||||
"utf-8",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +49,10 @@ export const authService = {
|
||||
}
|
||||
},
|
||||
|
||||
async changePassword(oldPassword: string, newPassword: string): Promise<{ success: boolean; error?: string }> {
|
||||
async changePassword(
|
||||
oldPassword: string,
|
||||
newPassword: string,
|
||||
): Promise<{ success: boolean; error?: string }> {
|
||||
try {
|
||||
// Verify old password
|
||||
const isValid = await this.verifyPassword(oldPassword);
|
||||
@@ -56,17 +63,20 @@ export const authService = {
|
||||
// Hash new password
|
||||
const newHash = await bcrypt.hash(newPassword, 10);
|
||||
const data = await loadPasswordData();
|
||||
|
||||
|
||||
// Update password
|
||||
data.hash = newHash;
|
||||
data.updatedAt = new Date().toISOString();
|
||||
|
||||
|
||||
await savePasswordData(data);
|
||||
|
||||
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error("Error changing password:", error);
|
||||
return { success: false, error: "Erreur lors du changement de mot de passe" };
|
||||
return {
|
||||
success: false,
|
||||
error: "Erreur lors du changement de mot de passe",
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
@@ -79,4 +89,3 @@ export const authService = {
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -60,5 +60,3 @@ export const categoryService = {
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -75,5 +75,3 @@ export const folderService = {
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ export const transactionService = {
|
||||
async createMany(transactions: Transaction[]): Promise<CreateManyResult> {
|
||||
// Get unique account IDs
|
||||
const accountIds = [...new Set(transactions.map((t) => t.accountId))];
|
||||
|
||||
|
||||
// Check for existing transactions by fitId
|
||||
const existingByFitId = await prisma.transaction.findMany({
|
||||
where: {
|
||||
@@ -43,11 +43,11 @@ export const transactionService = {
|
||||
const existingFitIdSet = new Set(
|
||||
existingByFitId.map((t) => `${t.accountId}-${t.fitId}`),
|
||||
);
|
||||
|
||||
|
||||
// Create set for duplicates by amount + date + description
|
||||
const existingCriteriaSet = new Set(
|
||||
allExistingTransactions.map((t) =>
|
||||
`${t.accountId}-${t.date}-${t.amount}-${t.description}`
|
||||
allExistingTransactions.map(
|
||||
(t) => `${t.accountId}-${t.date}-${t.amount}-${t.description}`,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -55,8 +55,10 @@ export const transactionService = {
|
||||
const newTransactions = transactions.filter((t) => {
|
||||
const fitIdKey = `${t.accountId}-${t.fitId}`;
|
||||
const criteriaKey = `${t.accountId}-${t.date}-${t.amount}-${t.description}`;
|
||||
|
||||
return !existingFitIdSet.has(fitIdKey) && !existingCriteriaSet.has(criteriaKey);
|
||||
|
||||
return (
|
||||
!existingFitIdSet.has(fitIdKey) && !existingCriteriaSet.has(criteriaKey)
|
||||
);
|
||||
});
|
||||
|
||||
if (newTransactions.length === 0) {
|
||||
@@ -122,7 +124,10 @@ export const transactionService = {
|
||||
});
|
||||
},
|
||||
|
||||
async deduplicate(): Promise<{ deletedCount: number; duplicatesFound: number }> {
|
||||
async deduplicate(): Promise<{
|
||||
deletedCount: number;
|
||||
duplicatesFound: number;
|
||||
}> {
|
||||
// Get all transactions grouped by account
|
||||
const allTransactions = await prisma.transaction.findMany({
|
||||
orderBy: [
|
||||
@@ -155,7 +160,7 @@ export const transactionService = {
|
||||
for (const [accountId, transactions] of transactionsByAccount.entries()) {
|
||||
for (const transaction of transactions) {
|
||||
const key = `${accountId}-${transaction.date}-${transaction.amount}-${transaction.description}`;
|
||||
|
||||
|
||||
if (seenKeys.has(key)) {
|
||||
// This is a duplicate, mark for deletion
|
||||
duplicatesToDelete.push(transaction.id);
|
||||
@@ -181,5 +186,3 @@ export const transactionService = {
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user