-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ee15ca
commit e7326a1
Showing
2 changed files
with
30 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { confirm } from "@inquirer/prompts"; | ||
import { LunchMoneyAPI, LunchMoneyTransaction } from "@services/lunchmoney"; | ||
|
||
/** | ||
* confirm the import with the user | ||
* and finalize the import if they say it's okay | ||
*/ | ||
const confirmImport = async (lm: LunchMoneyAPI, accounts: { transactions: LunchMoneyTransaction[], lmAccount: string }[]) => { | ||
console.log(`You're about to insert transactions into your LunchMoney budget.`) | ||
const confirmAns = await confirm({ message: `Are you sure you want to import them? ` }); | ||
|
||
if (!confirmAns) { | ||
console.log('alright! bye!'); | ||
process.exit(0); | ||
} | ||
|
||
// insert transactions into LunchMoney | ||
const insertResults = accounts.map((t) => { | ||
console.log(`inserting ${t.transactions.length} transactions into Lunch Money account ${t.lmAccount}`) | ||
return lm.insertTransactions(t.transactions); | ||
}); | ||
|
||
await Promise.allSettled(insertResults); | ||
console.log('results were inserted successfully. Please verify them in Lunch Money.') | ||
console.log('https://my.lunchmoney.app/transactions/') | ||
} | ||
|
||
export default confirmImport; |
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