-
Notifications
You must be signed in to change notification settings - Fork 509
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
9 changed files
with
1,225 additions
and
1,155 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,20 +1,55 @@ | ||
import { scheduler } from "@midday/jobs/src/transactions/scheduler"; | ||
import { Provider } from "@midday/providers"; | ||
// import { scheduler } from "@midday/jobs/src/transactions/scheduler"; | ||
import { createClient } from "@midday/supabase/server"; | ||
import { NextResponse } from "next/server"; | ||
|
||
export async function GET(req) { | ||
const requestUrl = new URL(req.url); | ||
const teamId = requestUrl.searchParams.get("teamId"); | ||
const supabase = createClient(); | ||
|
||
if (teamId) { | ||
const event = await scheduler.register(teamId, { | ||
type: "interval", | ||
options: { | ||
seconds: 3600, // every 1h | ||
}, | ||
const { data: accountsData, error: accountsError } = await supabase | ||
.from("bank_accounts") | ||
.select( | ||
"id, team_id, account_id, bank_connection:bank_connection_id(provider, access_token, enrollment_id)" | ||
) | ||
.eq("team_id", teamId) | ||
.eq("enabled", true); | ||
|
||
const promises = accountsData?.map(async (account) => { | ||
const provider = new Provider({ | ||
provider: account.bank_connection.provider, | ||
}); | ||
|
||
return provider.getTransactions({ | ||
teamId: account.team_id, | ||
accountId: account.account_id, | ||
accessToken: account.bank_connection?.access_token, | ||
bankAccountId: account.id, | ||
latest: true, | ||
}); | ||
}); | ||
|
||
return NextResponse.json(event); | ||
try { | ||
if (promises) { | ||
const transactions = (await Promise.all(promises)).flat(); | ||
|
||
return NextResponse.json(transactions); | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
|
||
return NextResponse.json({ error: "No team ID provided" }); | ||
// if (teamId) { | ||
// const event = await scheduler.register(teamId, { | ||
// type: "interval", | ||
// options: { | ||
// seconds: 3600, // every 1h | ||
// }, | ||
// }); | ||
|
||
// return NextResponse.json(event); | ||
// } | ||
|
||
// return NextResponse.json({ error: "No team ID provided" }); | ||
} |
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
Oops, something went wrong.