aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/routes/methods.remote.ts
blob: d9ba8124decedf3d3f5cdf8b6c00ef5912032e28 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { db } from "$lib/server/db";
import { SyncSessionTable } from "$lib/server/db/schema";
import { command, query } from "$app/server";
import sb1 from "$lib/server/sb1";
import { import_transactions, init_actual } 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(SyncSessionTable)
})

const do_import = command(ImportForm, async (form) => {
    for (const mapping of form.mappings) {
        const transactions = await sb1.data.get_transactions(mapping.sb1Id)
        console.log(transactions)
        continue
        // if (!transactions?.length) continue
        // console.log(await import_transactions(mapping.actualId, transactions, form.dryRun))
    }
})

const init_sb1 = command(async () => {
    return await sb1.init()
})

const _init_actual = command(async () => {
    return await init_actual()
})

export {
    init_auth_session,
    do_import,
    _init_actual as init_actual,
    init_sb1,
    clear_auth_session
}