Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Nov 28, 2024
1 parent 80e9fdc commit 3e9c143
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 42 deletions.
4 changes: 2 additions & 2 deletions apps/dashboard/jobs/tasks/bank/setup/initial.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { schedules, schemaTask } from "@trigger.dev/sdk/v3";
import { generateCron } from "jobs/utils/generate-cron";
import { generateCronTag } from "jobs/utils/generate-cron-tag";
import { z } from "zod";
import { bankSyncScheduler } from "../scheduler/bank-sync";
import { syncConnection } from "../sync/connection";
Expand All @@ -24,7 +24,7 @@ export const initialBankSetup = schemaTask({
// Add teamId as externalId to use it in the bankSyncScheduler task
await schedules.create({
task: bankSyncScheduler.id,
cron: generateCron(teamId),
cron: generateCronTag(teamId),
timezone: "UTC",
externalId: teamId,
deduplicationKey: `${teamId}-${bankSyncScheduler.id}`,
Expand Down
11 changes: 1 addition & 10 deletions apps/dashboard/jobs/tasks/bank/sync/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const syncAccount = schemaTask({
id: "sync-account",
maxDuration: 300,
retry: {
maxAttempts: 2,
maxAttempts: 1,
},
schema: z.object({
id: z.string().uuid(),
Expand Down Expand Up @@ -79,21 +79,12 @@ export const syncAccount = schemaTask({
if (parsedError.code === "disconnected") {
const retries = errorRetries ? errorRetries + 1 : 1;

if (retries > 4) {
logger.error("Account disconnected too many times", {
accountId,
retries,
});
}

// Update the account with the error details and retries
// And disable the account if we've retried too many times
await supabase
.from("bank_accounts")
.update({
error_details: parsedError.message,
error_retries: retries,
enabled: retries <= 4,
})
.eq("id", id);

Expand Down
27 changes: 19 additions & 8 deletions apps/dashboard/jobs/tasks/bank/sync/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,22 @@ export const syncConnection = schemaTask({
})
.eq("id", connectionId);

const { data: bankAccountsData } = await supabase
const query = supabase
.from("bank_accounts")
.select(
"id, team_id, account_id, type, bank_connection:bank_connection_id(id, provider, access_token, status, error_retries)",
"id, team_id, account_id, type, bank_connection:bank_connection_id(id, provider, access_token, status)",
)
.eq("bank_connection_id", connectionId)
.eq("enabled", true)
.eq("manual", false)
.throwOnError();
.eq("manual", false);

// Skip accounts with more than 3 error retries during background sync
// Allow all accounts during manual sync to clear errors after reconnect
if (!manualSync) {
query.or("error_retries.lt.4,error_retries.is.null");
}

const { data: bankAccountsData } = await query.throwOnError();

if (!bankAccountsData) {
logger.info("No bank accounts found");
Expand Down Expand Up @@ -105,19 +112,23 @@ export const syncConnection = schemaTask({
}

// Check connection status by accounts
// If all accounts are disabled (due to errors), we want to disable the connection
// If all accounts have 3+ error retries, disconnect the connection
// So the user will get a notification and can reconnect the bank
try {
const { data: bankAccountsData } = await supabase
.from("bank_accounts")
.select("id, enabled")
.select("id, error_retries")
.eq("bank_connection_id", connectionId)
.eq("manual", false)
.throwOnError();

if (bankAccountsData?.every((account) => !account.enabled)) {
if (
bankAccountsData?.every(
(account) => (account.error_retries ?? 0) >= 3,
)
) {
logger.info(
"All bank accounts are disabled, disconnecting connection",
"All bank accounts have 3+ error retries, disconnecting connection",
);

await supabase
Expand Down
15 changes: 0 additions & 15 deletions apps/dashboard/jobs/utils/generate-cron.ts

This file was deleted.

2 changes: 0 additions & 2 deletions apps/dashboard/src/actions/validate-vat-number-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,5 @@ export const validateVatNumberAction = authActionClient

const data = await response.json();

console.log(data);

return data;
});
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export function SelectBankAccountsModal() {
provider: provider as "gocardless" | "plaid" | "teller",
accessToken: token ?? undefined,
enrollmentId: enrollment_id ?? undefined,
// TODO: GoCardLess Requestion ID or Plaid Item ID
referenceId: ref ?? undefined,
accounts: data.map((account) => ({
name: account.name,
Expand Down
1 change: 0 additions & 1 deletion apps/dashboard/src/components/tracker-export-csv.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export function TrackerExportCSV({ name, teamId, projectId, userId }: Props) {
const supabase = createClient();

async function downloadCSV() {
console.log(date);
const query = supabase
.from("tracker_entries")
.select(
Expand Down
2 changes: 0 additions & 2 deletions apps/engine/src/providers/gocardless/gocardless-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ export class GoCardLessApi {
} catch (error) {
const parsedError = isError(error);

console.log(error);

if (parsedError) {
throw new ProviderError(parsedError);
}
Expand Down
5 changes: 5 additions & 0 deletions apps/engine/src/providers/gocardless/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export const transformTransactionName = (transaction: Transaction) => {

console.log("No transaction name", transaction);

// When there is no name, we use the proprietary bank transaction code (Service Fee)
if (transaction.proprietaryBankTransactionCode) {
return transaction.proprietaryBankTransactionCode;
}

return "No information";
};

Expand Down
2 changes: 0 additions & 2 deletions packages/jobs/src/transactions/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ client.defineJob({
},
});

console.log(attachments);

const rows = data
?.sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime())
.map((transaction, idx) => [
Expand Down

0 comments on commit 3e9c143

Please sign in to comment.