From 5a5717699b8b2d60b7d92c2087ed2cc22667e1cc Mon Sep 17 00:00:00 2001 From: ivar Date: Sat, 27 Dec 2025 11:25:47 +0100 Subject: Almost there --- app/src/lib/server/actual.ts | 10 ++++++++-- app/src/lib/server/importer.ts | 11 ----------- app/src/lib/shared.d.ts | 5 ----- app/src/lib/shared.ts | 13 +++++++++++++ app/src/routes/+page.svelte | 13 +++++++------ app/src/routes/methods.remote.ts | 16 +++++++++++++--- 6 files changed, 41 insertions(+), 27 deletions(-) delete mode 100644 app/src/lib/server/importer.ts delete mode 100644 app/src/lib/shared.d.ts create mode 100644 app/src/lib/shared.ts (limited to 'app') diff --git a/app/src/lib/server/actual.ts b/app/src/lib/server/actual.ts index 389f390..4cf0262 100644 --- a/app/src/lib/server/actual.ts +++ b/app/src/lib/server/actual.ts @@ -27,15 +27,21 @@ export async function import_transactions(account: string, transactions: Sb1Tran return instant.toString({ timeZone: "Europe/Oslo" }).split("T")[0] } + function notes(transaction: Sb1Transaction) { + const {description,cleanedDescription} =transaction + if (description.toLowerCase().trim() === cleanedDescription.toLowerCase().trim()) return undefined + return description + } + const actualMappedTransactions: ImportTransactionEntity[] = transactions.filter(c => c.bookingStatus === "BOOKED").map(c => ({ account, date: parsedDate(c.date), amount: c.amount, - notes: c.description, + notes: notes(c), payee_name: c.cleanedDescription })) - actual.importTransactions(account, actualMappedTransactions, { dryRun }) + return await actual.importTransactions(account, actualMappedTransactions, { dryRun }) } export async function get_budgets() { diff --git a/app/src/lib/server/importer.ts b/app/src/lib/server/importer.ts deleted file mode 100644 index 02cb94c..0000000 --- a/app/src/lib/server/importer.ts +++ /dev/null @@ -1,11 +0,0 @@ -import sb1 from "./sb1"; -import * as actual from "./actual"; -import type { ImportForm } from "$lib/shared"; - -async function importSince(form: ImportForm) { - for (const mapping of form.mappings) { - const transactions = await sb1.data.get_transactions(mapping.sb1Id); - if (!transactions?.length) continue - - } -} \ No newline at end of file diff --git a/app/src/lib/shared.d.ts b/app/src/lib/shared.d.ts deleted file mode 100644 index e63904b..0000000 --- a/app/src/lib/shared.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -export type ImportForm = { - budgetId: string, - mappings: Array<{ sb1Id: string, actualId: string }>, - dryRun: boolean -} \ No newline at end of file diff --git a/app/src/lib/shared.ts b/app/src/lib/shared.ts new file mode 100644 index 0000000..a7cf207 --- /dev/null +++ b/app/src/lib/shared.ts @@ -0,0 +1,13 @@ +import * as v from 'valibot' + +export type ImportForm = v.InferOutput +export const ImportForm = v.object({ + budgetId: v.string(), + mappings: v.array( + v.object({ + sb1Id: v.string(), + actualId: v.string() + }) + ), + dryRun: v.boolean() +}) diff --git a/app/src/routes/+page.svelte b/app/src/routes/+page.svelte index 6f257f6..ee4148b 100644 --- a/app/src/routes/+page.svelte +++ b/app/src/routes/+page.svelte @@ -1,9 +1,7 @@
diff --git a/app/src/routes/methods.remote.ts b/app/src/routes/methods.remote.ts index c669164..3fca715 100644 --- a/app/src/routes/methods.remote.ts +++ b/app/src/routes/methods.remote.ts @@ -1,20 +1,30 @@ import { db } from "$lib/server/db"; import { syncSession } from "$lib/server/db/schema"; -import * as v from "valibot" import { command, query } from "$app/server"; import sb1 from "$lib/server/sb1"; +import { import_transactions } from "$lib/server/actual"; +import { ImportForm } from "$lib/shared"; const init_auth_session = command(async () => { return await sb1.auth.init_auth_session() }) - const clear_auth_session = query(async () => { await db.delete(syncSession) }) +const do_import = command(ImportForm, async (form) => { + let x + for (const mapping of form.mappings) { + const transactions = await sb1.data.get_transactions(mapping.sb1Id) + if (!transactions?.length || x) continue + x = true + console.log(await import_transactions(mapping.actualId, transactions, form.dryRun)) + } +}) export { init_auth_session, + do_import, clear_auth_session -} \ No newline at end of file +} -- cgit v1.3