Skip to content

Commit

Permalink
Sync account ref
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Dec 14, 2024
1 parent c1e7d45 commit ef6c45f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions apps/dashboard/jobs/tasks/bank/accounts/update-reference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { client } from "@midday/engine/client";
import { createClient } from "@midday/supabase/job";
import { schemaTask } from "@trigger.dev/sdk/v3";
import { z } from "zod";

export const updateReference = schemaTask({
id: "update-reference",
maxDuration: 300,
schema: z.object({
connectionId: z.string(),
}),
run: async ({ connectionId }) => {
const supabase = createClient();

const accountsResponse = await client.accounts.$get({
query: {
id: connectionId,
provider: "gocardless",
},
});

const { data: accountsData } = await accountsResponse.json();

await Promise.all(
accountsData.map(async (account) => {
return supabase
.from("bank_accounts")
.update({
account_reference: account.resource_id,
})
.eq("account_id", account.id);
}),
);
},
});

0 comments on commit ef6c45f

Please sign in to comment.