diff options
Diffstat (limited to 'app/src/routes')
| -rw-r--r-- | app/src/routes/+page.svelte | 13 | ||||
| -rw-r--r-- | app/src/routes/methods.remote.ts | 16 |
2 files changed, 20 insertions, 9 deletions
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 @@ <script lang="ts"> import Button from "$lib/ui/button.svelte"; - import { clear_auth_session, init_auth_session } from "./methods.remote"; + import { clear_auth_session, init_auth_session, do_import } from "./methods.remote"; import type { PageProps } from "./$types"; - import { Temporal } from "temporal-polyfill"; - import { instantAsHtmlInputValueString } from "$lib/helpers"; import type { ImportForm } from "$lib/shared"; let { data }: PageProps = $props(); @@ -14,7 +12,12 @@ dryRun: true, }); - async function run() {} + async function run() { + if (!form.mappings.length) { + return; + } + await do_import(form); + } async function authorize() { navigating = true; @@ -34,8 +37,6 @@ mappings.push({ sb1Id, actualId }); form.mappings = mappings; } - - $inspect(form); </script> <main> 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 +} |
