-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Call `loadInfo` again after creating the sheet * Simpler flow * Move row schema to own file * Retry getting the sheet * Better auth * Fix service account setup link * Even nicer * Smaller payload in hashes * Remove retry + sheet creation
- Loading branch information
1 parent
4704322
commit 54ffc57
Showing
4 changed files
with
108 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { format, parseISO } from "date-fns"; | ||
import { systemName } from "../config.js"; | ||
import type { TransactionRow } from "../types.js"; | ||
import { normalizeCurrency } from "../utils/currency.js"; | ||
|
||
const currentDate = format(Date.now(), "yyyy-MM-dd"); | ||
const { TRANSACTION_HASH_TYPE } = process.env; | ||
|
||
export const TableHeaders = [ | ||
"date", | ||
"amount", | ||
"description", | ||
"memo", | ||
"category", | ||
"account", | ||
"hash", | ||
"comment", | ||
"scraped at", | ||
"scraped by", | ||
"identifier", | ||
"chargedCurrency", | ||
] as const; | ||
|
||
export type TableRow = Omit< | ||
Record<(typeof TableHeaders)[number], string>, | ||
"amount" | ||
> & { | ||
amount: number; | ||
}; | ||
|
||
export function tableRow(tx: TransactionRow): TableRow { | ||
return { | ||
date: format(parseISO(tx.date), "dd/MM/yyyy", {}), | ||
amount: tx.chargedAmount, | ||
description: tx.description, | ||
memo: tx.memo ?? "", | ||
category: tx.category ?? "", | ||
account: tx.account, | ||
hash: TRANSACTION_HASH_TYPE === "moneyman" ? tx.uniqueId : tx.hash, | ||
comment: "", | ||
"scraped at": currentDate, | ||
"scraped by": systemName, | ||
identifier: `${tx.identifier ?? ""}`, | ||
// Assuming the transaction is not pending, so we can use the original currency as the charged currency | ||
chargedCurrency: | ||
normalizeCurrency(tx.chargedCurrency) || | ||
normalizeCurrency(tx.originalCurrency), | ||
}; | ||
} |