Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Dec 3, 2024
1 parent c59d2a8 commit aac199d
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 41 deletions.
2 changes: 1 addition & 1 deletion apps/dashboard/jobs/tasks/bank/setup/initial.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { schedules, schemaTask } from "@trigger.dev/sdk/v3";
import { generateCronTag } from "jobs/utils/generate-cron-tag";
import { z } from "zod";
import { bankSyncScheduler } from "../scheduler/bank-sync";
import { bankSyncScheduler } from "../scheduler/bank-scheduler";
import { syncConnection } from "../sync/connection";

// This task sets up the bank sync for a new team on a daily schedule and
Expand Down
23 changes: 23 additions & 0 deletions apps/dashboard/jobs/tasks/rates/scheduler/rates-scheduler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { client } from "@midday/engine/client";
import { createClient } from "@midday/supabase/job";
import { logger, schedules } from "@trigger.dev/sdk/v3";

export const ratesScheduler = schedules.task({
id: "rates-scheduler",
cron: "0 0,12 * * *",
run: async () => {
// Only run in production (Set in Trigger.dev)
if (process.env.TRIGGER_ENVIRONMENT !== "production") return;

const ratesResponse = await client.rates.$get();

if (!ratesResponse.ok) {
logger.error("Failed to get rates");
throw new Error("Failed to get rates");
}

const { data: ratesData } = await ratesResponse.json();

console.log(ratesData);
},
});
52 changes: 52 additions & 0 deletions apps/engine/src/routes/connections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ConnectionStatusQuerySchema,
ConnectionStatusSchema,
DeleteConnectionBodySchema,
GoCardLessConnectionsSchema,
} from "./schema";

const app = new OpenAPIHono<{ Bindings: Bindings }>()
Expand Down Expand Up @@ -139,6 +140,57 @@ const app = new OpenAPIHono<{ Bindings: Bindings }>()
}
},
)
.openapi(
createRoute({
method: "get",
path: "/gocardless",
summary: "Get GoCardless Connections",
responses: {
200: {
content: {
"application/json": {
schema: GoCardLessConnectionsSchema,
},
},
description: "Retrieve GoCardless connections",
},
400: {
content: {
"application/json": {
schema: ErrorSchema,
},
},
description: "Returns an error",
},
},
}),
async (c) => {
const envs = env(c);

const api = new GoCardLessApi({
kv: c.env.KV,
envs,
});

try {
const data = await api.getRequisitions();

return c.json(
{
count: data.count,
next: data.next,
previous: data.previous,
results: data.results,
},
200,
);
} catch (error) {
const errorResponse = createErrorResponse(error, c.get("requestId"));

return c.json(errorResponse, 400);
}
},
)
.openapi(
createRoute({
method: "get",
Expand Down
23 changes: 23 additions & 0 deletions apps/engine/src/routes/connections/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,26 @@ export const ConnectionByReferenceSchema = z.object({
accounts: z.array(z.string()),
}),
});

export const GoCardLessConnectionSchema = z.object({
id: z.string(),
created: z.string(),
redirect: z.string(),
status: z.enum(["CR", "GC", "UA", "RJ", "SA", "GA", "LN", "EX"]),
institution_id: z.string(),
agreement: z.string(),
reference: z.string(),
accounts: z.array(z.string()),
user_language: z.string(),
link: z.string(),
ssn: z.string(),
account_selection: z.boolean(),
redirect_immediate: z.boolean(),
});

export const GoCardLessConnectionsSchema = z.object({
count: z.number(),
next: z.string(),
previous: z.string(),
results: z.array(GoCardLessConnectionSchema),
});
1 change: 0 additions & 1 deletion packages/jobs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export * from "./transactions";
export * from "./inbox";
export * from "./client";
export * from "./constants";
export * from "./rates";
1 change: 0 additions & 1 deletion packages/jobs/src/rates/index.ts

This file was deleted.

38 changes: 0 additions & 38 deletions packages/jobs/src/rates/update.ts

This file was deleted.

0 comments on commit aac199d

Please sign in to comment.