Skip to content

Commit

Permalink
Merge pull request #173 from midday-ai/feature/teller-amount
Browse files Browse the repository at this point in the history
Update teller amount
  • Loading branch information
pontusab authored Jun 28, 2024
2 parents d6e1034 + 7168996 commit 28b41ac
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 33 deletions.
14 changes: 6 additions & 8 deletions apps/engine/src/providers/teller/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,22 @@ export const mapTransactionCategory = ({

type TransformTransactionPayload = {
transaction: TransformTransaction;
accountType: AccountType;
};

export const transformTransaction = ({
transaction,
accountType,
}: TransformTransactionPayload): BaseTransaction => {
const method = mapTransactionMethod(transaction.type);

const amount = formatAmountForAsset({
amount: +transaction.amount,
type: accountType,
});
const amount = +transaction.amount;
const description =
(transaction?.details?.counterparty?.name &&
capitalCase(transaction.details.counterparty.name)) ||
null;

return {
date: transaction.date,
name: transaction.description && capitalCase(transaction.description),
description: null,
description,
method,
internal_id: transaction.id,
amount,
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function Hero() {
<p className="text-xs text-[#707070] mt-8 font-mono">
Used by over{" "}
<Link href="/open-startup" prefetch>
<span className="underline">4000+</span>
<span className="underline">4100+</span>
</Link>{" "}
businesses.
</p>
Expand Down
24 changes: 15 additions & 9 deletions packages/jobs/src/transactions/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,26 @@ client.defineJob({
return null;
}

const { error: transactionsError, data: transactionsData } =
await supabase
.from("transactions")
.upsert(transactions, {
onConflict: "internal_id",
ignoreDuplicates: true,
})
.select("*");
const {
error: transactionsError,
data: transactionsData,
statusText,
} = await supabase
.from("transactions")
.upsert(transactions, {
onConflict: "internal_id",
})
.select("*");

if (transactionsError) {
await io.logger.error("Transactions error", transactionsError);
}

if (transactionsData && transactionsData?.length > 0) {
if (
statusText === "Created" &&
transactionsData &&
transactionsData?.length > 0
) {
await io.sendEvent("🔔 Send notifications", {
name: Events.TRANSACTIONS_NOTIFICATION,
payload: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

exports[`Transform pending transaction 1`] = `
{
"amount": -83.62,
"amount": 83.62,
"balance": null,
"bank_account_id": "123",
"category": null,
"category": "income",
"currency": "USD",
"date": "2024-03-05",
"description": null,
"description": "Bank Of Many",
"internal_id": "123_txn_os41r5u90e29shubl2000",
"method": "other",
"name": "Online Check Deposit",
Expand All @@ -19,10 +19,10 @@ exports[`Transform pending transaction 1`] = `

exports[`Transform card payment transaction 1`] = `
{
"amount": 68.9,
"amount": -68.9,
"balance": "83431.46",
"bank_account_id": "123",
"category": "income",
"category": null,
"currency": "USD",
"date": "2024-03-01",
"description": null,
Expand All @@ -36,10 +36,10 @@ exports[`Transform card payment transaction 1`] = `

exports[`Transform income transaction 1`] = `
{
"amount": 20.21,
"amount": -20.21,
"balance": "83296.40",
"bank_account_id": "123",
"category": "income",
"category": null,
"currency": "USD",
"date": "2024-03-03",
"description": null,
Expand All @@ -59,7 +59,7 @@ exports[`Transform type transfer 1`] = `
"category": "transfer",
"currency": "USD",
"date": "2024-01-27",
"description": null,
"description": "Yourself",
"internal_id": "123_txn_os41r5ua0e29shubl2001",
"method": "transfer",
"name": "Recurring Transfer To Savings",
Expand Down
22 changes: 15 additions & 7 deletions packages/providers/src/teller/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,31 @@ export const mapTransactionCategory = ({
}
};

export const transformDescription = (transaction: Transaction) => {
const description =
transaction?.details?.counterparty?.name &&
capitalCase(transaction.details.counterparty.name);

if (transaction.description !== description && description) {
return capitalCase(description);
}

return null;
};

export const transformTransaction = ({
transaction,
teamId,
bankAccountId,
accountType,
}: TransformTransaction): BaseTransaction => {
const method = mapTransactionMethod(transaction.type);

const amount = formatAmountForAsset({
amount: +transaction.amount,
type: accountType,
});
const amount = +transaction.amount;
const description = transformDescription(transaction);

return {
date: transaction.date,
name: transaction.description && capitalCase(transaction.description),
description: null,
description,
method,
internal_id: `${teamId}_${transaction.id}`,
amount,
Expand Down

0 comments on commit 28b41ac

Please sign in to comment.