File size: 893 Bytes
c09f67c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import { capitalCase } from "change-case";
import { v4 as uuidv4 } from "uuid";
import type { Transaction } from "./types";
import { formatAmountValue, formatDate } from "./utils";
export function transform({
transaction,
inverted,
}: {
transaction: Transaction;
inverted: boolean;
}) {
return {
internal_id: `${transaction.teamId}_${uuidv4()}`,
team_id: transaction.teamId,
status: "posted",
method: "other",
date: formatDate(transaction.date),
amount: formatAmountValue({ amount: transaction.amount, inverted }),
name: transaction?.description && capitalCase(transaction.description),
manual: true,
category_slug:
formatAmountValue({ amount: transaction.amount, inverted }) > 0
? "income"
: null,
bank_account_id: transaction.bankAccountId,
currency: transaction.currency.toUpperCase(),
notified: true,
};
}
|