Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Nov 25, 2024
1 parent a5d6b4c commit 1cb2ced
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
6 changes: 5 additions & 1 deletion apps/dashboard/jobs/tasks/bank/notifications/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createClient } from "@midday/supabase/job";
import { schemaTask } from "@trigger.dev/sdk/v3";
import { handleTransactionEmails } from "jobs/utils/transaction-notifications";
import {
handleTransactionEmails,
handleTransactionSlackNotifications,
} from "jobs/utils/transaction-notifications";
import { handleTransactionNotifications } from "jobs/utils/transaction-notifications";
import { z } from "zod";

Expand Down Expand Up @@ -36,5 +39,6 @@ export const transactionsNotification = schemaTask({

await handleTransactionNotifications(usersData, sortedTransactions);
await handleTransactionEmails(usersData, sortedTransactions);
await handleTransactionSlackNotifications(teamId, sortedTransactions);
},
});
21 changes: 21 additions & 0 deletions apps/dashboard/jobs/utils/transaction-notifications.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { sendSlackTransactionsNotification } from "@midday/app-store/slack";
import TransactionsEmail from "@midday/email/emails/transactions";
import { getI18n } from "@midday/email/locales";
import { getInboxEmail } from "@midday/inbox";
Expand Down Expand Up @@ -119,3 +120,23 @@ export async function handleTransactionEmails(

return validEmailPromises;
}

export async function handleTransactionSlackNotifications(
teamId: string,
sortedTransactions: Transaction[],
) {
// TODO: Get correct locale for formatting the amount
const slackTransactions = sortedTransactions.map((transaction) => ({
date: transaction.date,
amount: Intl.NumberFormat("en-US", {
style: "currency",
currency: transaction.currency,
}).format(transaction.amount),
name: transaction.name,
}));

await sendSlackTransactionsNotification({
teamId,
transactions: slackTransactions,
});
}
3 changes: 1 addition & 2 deletions apps/dashboard/src/app/api/test/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { type NextRequest, NextResponse } from "next/server";

const accessToken =
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzMyNjEzMDg1LCJqdGkiOiJhOWQ2N2NmMzNiYjE0NDhhYWFiZmQwZjRlMjkxODU3YSIsInV1aWQiOiI0MTA2YzVhNi04MmU0LTQ3MDAtYmE4NC03NDQ5NDRhYmZiYjkiLCJhbGxvd2VkX2NpZHJzIjpbIjAuMC4wLjAvMCIsIjo6LzAiXX0.0yDdeGP5hbJjjkmJ-FK8or9npkVB4rERg2Q-eSJmO5Y";
const accessToken = "";

export async function GET(req: NextRequest) {
const requestUrl = new URL(req.url);
Expand Down

0 comments on commit 1cb2ced

Please sign in to comment.