-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
117 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,36 @@ | ||
"use server"; | ||
|
||
import { Events, client } from "@midday/jobs"; | ||
import { getUser } from "@midday/supabase/cached-queries"; | ||
import { createBankAccounts } from "@midday/supabase/mutations"; | ||
import { createClient } from "@midday/supabase/server"; | ||
import { revalidateTag } from "next/cache"; | ||
import { action } from "./safe-action"; | ||
import { connectBankAccountSchema } from "./schema"; | ||
|
||
export const connectBankAccountAction = action( | ||
connectBankAccountSchema, | ||
async (value) => { | ||
async ({ accounts }) => { | ||
const user = await getUser(); | ||
const supabase = createClient(); | ||
const teamId = user.data.team_id; | ||
|
||
return value; | ||
const { data } = await createBankAccounts(supabase, accounts); | ||
|
||
// const event = await client.sendEvent({ | ||
// name: Events.TRANSACTIONS_INITIAL_SYNC, | ||
// payload: { | ||
// id, | ||
// accountId, | ||
// teamId, | ||
// }, | ||
// }); | ||
|
||
revalidateTag(`bank_connections_${teamId}`); | ||
|
||
return { | ||
event, | ||
data, | ||
}; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ body { | |
} | ||
|
||
:root { | ||
--sidebar-width: 662px; | ||
--sidebar-width: 642px; | ||
|
||
/* Counter */ | ||
--transition: 1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,74 @@ | ||
import { getTransactions } from "@midday/gocardless"; | ||
import { eventTrigger } from "@trigger.dev/sdk"; | ||
import { revalidateTag } from "next/cache"; | ||
import { z } from "zod"; | ||
import { client, supabase } from "../client"; | ||
import { Events, Jobs } from "../constants"; | ||
import { transformTransactions } from "../utils"; | ||
// import { getTransactions } from "@midday/gocardless"; | ||
// import { eventTrigger } from "@trigger.dev/sdk"; | ||
// import { revalidateTag } from "next/cache"; | ||
// import { z } from "zod"; | ||
// import { client, supabase } from "../client"; | ||
// import { Events, Jobs } from "../constants"; | ||
// import { transformTransactions } from "../utils"; | ||
// import { scheduler } from "./scheduler"; | ||
|
||
client.defineJob({ | ||
id: Jobs.TRANSACTIONS_INITIAL_SYNC, | ||
name: "🔂 Transactions - Initial Sync", | ||
version: "1.0.2", | ||
trigger: eventTrigger({ | ||
name: Events.TRANSACTIONS_INITIAL_SYNC, | ||
schema: z.object({ | ||
accountId: z.string(), | ||
teamId: z.string(), | ||
recordId: z.string(), | ||
}), | ||
}), | ||
integrations: { supabase }, | ||
run: async (payload, io) => { | ||
const { accountId, teamId, recordId } = payload; | ||
// client.defineJob({ | ||
// id: Jobs.TRANSACTIONS_INITIAL_SYNC, | ||
// name: "🔂 Transactions - Initial Sync", | ||
// version: "1.0.2", | ||
// trigger: eventTrigger({ | ||
// name: Events.TRANSACTIONS_INITIAL_SYNC, | ||
// schema: z.object({ | ||
// accountId: z.string(), | ||
// teamId: z.string(), | ||
// id: z.string(), | ||
// }), | ||
// }), | ||
// integrations: { supabase }, | ||
// run: async (payload, io) => { | ||
// const { accountId, teamId, id } = payload; | ||
|
||
const { transactions } = await getTransactions(accountId); | ||
// const { transactions } = await getTransactions(accountId); | ||
|
||
// Update bank account last_accessed | ||
await io.supabase.client | ||
.from("bank_accounts") | ||
.update({ | ||
last_accessed: new Date().toISOString(), | ||
}) | ||
.eq("id", recordId); | ||
// // Update bank account last_accessed | ||
// await io.supabase.client | ||
// .from("bank_accounts") | ||
// .update({ | ||
// last_accessed: new Date().toISOString(), | ||
// }) | ||
// .eq("id", id); | ||
|
||
const { data: transactionsData, error } = await io.supabase.client | ||
.from("transactions") | ||
.insert( | ||
transformTransactions(transactions?.booked, { | ||
accountId: recordId, // Bank account record id | ||
teamId, | ||
}) | ||
) | ||
.select(); | ||
// const { data: transactionsData, error } = await io.supabase.client | ||
// .from("transactions") | ||
// .insert( | ||
// transformTransactions(transactions?.booked, { | ||
// accountId: id, // Bank account record id | ||
// teamId, | ||
// }) | ||
// ) | ||
// .select(); | ||
|
||
if (transactionsData?.length && transactionsData.length > 0) { | ||
revalidateTag(`transactions_${teamId}`); | ||
revalidateTag(`spending_${teamId}`); | ||
revalidateTag(`metrics_${teamId}`); | ||
// if (transactionsData?.length && transactionsData.length > 0) { | ||
// revalidateTag(`transactions_${teamId}`); | ||
// revalidateTag(`spending_${teamId}`); | ||
// revalidateTag(`metrics_${teamId}`); | ||
|
||
await io.sendEvent("💅 Enrich Transactions", { | ||
name: Events.TRANSACTIONS_ENCRICHMENT, | ||
payload: { | ||
teamId, | ||
}, | ||
}); | ||
} | ||
// await io.sendEvent("💅 Enrich Transactions", { | ||
// name: Events.TRANSACTIONS_ENCRICHMENT, | ||
// payload: { | ||
// teamId, | ||
// }, | ||
// }); | ||
// } | ||
|
||
if (error) { | ||
await io.logger.error(JSON.stringify(error, null, 2)); | ||
} | ||
// if (error) { | ||
// await io.logger.error(JSON.stringify(error, null, 2)); | ||
// } | ||
|
||
await io.logger.info(`Transactions Created: ${transactionsData?.length}`); | ||
}, | ||
}); | ||
// await io.logger.info(`Transactions Created: ${transactionsData?.length}`); | ||
|
||
// // use the bank account row id as the id for the DynamicSchedule | ||
// // so it comes through to run() in the context source.id | ||
// await scheduler.register(id, { | ||
// type: "interval", | ||
// options: { | ||
// seconds: 3600, // every 1h | ||
// }, | ||
// }); | ||
// }, | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters