Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract logic from lib index file to dedicated modules - Resolves #90 #91

Merged
merged 7 commits into from
Sep 7, 2020

Conversation

brafdlog
Copy link
Owner

@brafdlog brafdlog commented Sep 7, 2020

Extract the logic from the lib index file into dedicated modules for the different parts of the flow.

Probably easier to review the changes commit by commit because of the folder structure changes.

@brafdlog brafdlog requested a review from baruchiro September 7, 2020 13:01
@brafdlog brafdlog changed the title Extract logic from lib index file to dedicated modules (resolves #90) Extract logic from lib index file to dedicated modules - resolves #90 Sep 7, 2020
@brafdlog brafdlog changed the title Extract logic from lib index file to dedicated modules - resolves #90 Extract logic from lib index file to dedicated modules - Resolves #90 Sep 7, 2020
@baruchiro
Copy link
Collaborator

I'm trying to think about a way to force us to import only from originalBudgetTrackingApp and not from any originalBudgetTrackingApp/* when we are on the FrontEnd code.

Maybe this:
https://eslint.org/docs/rules/no-restricted-imports
Just keep in your mind

Comment on lines 7 to 21
export async function printYnabAccountData() {
const ynabAccountData = await getYnabAccountDetails();
const companyIdToAccountNumbers = await getFinancialAccountNumbers();
console.log();
console.log();
console.log('------YNAB Budgets------');
console.log(ynabAccountData.budgets);
console.log();
console.log('------YNAB Accounts------');
console.log(ynabAccountData.accounts);
console.log();
console.log('------Financial institutions account numbers------');
console.log(companyIdToAccountNumbers);
console.log();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not in ynab module?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered this. Since the setup of ynab requires matching account ids in ynab and the account ids in the financial and fetching all those ids is annoying, I wrote these to make it easier to do the setup. This is another flow of setup scripts (in addition to the flows of config and scrape) so I extracted it to a file of its own.

I get your point that this is ynab specific so I will leave it in ynab and reexport it from here

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought I think we should keep it separated in the setup helpers. As you can see this is very specific code that is only relevant to the setup flow. It uses ynab's getYnabAccountDetails as a building block but the rest is not related to the ynab api and I don't want to mix this code with the regular flow.

WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand you correctly, this is just an "external tool" to easily config the ynab at the first time (?).

If so, yes, let's keep it far from the library/module code. Even in a different folder, tools or something.

But to understand, if it not in the regular config+scrape flow, how can you run it? By running the code itself? How it published?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not pay too much attention to where I said put it. Maybe the file is in the right place.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point it is running the code itself. We could create a ui flow for setup that will do this behind the scenes and instead of printing it to the console will help you fill the config. But at this stage it is just a code tool.

Comment on lines 23 to 40
async function getFinancialAccountNumbers() {
const config = await configManager.getConfig();

const startDate = moment()
.subtract(30, 'days')
.startOf('day')
.toDate();

console.log('Fetching data from financial institutions to determine the account numbers');
const companyIdToTransactions = await scrapeFinancialAccountsAndFetchTransactions(config, startDate);
const companyIdToAccountNumbers: Record<string, string[]> = {};
Object.keys(companyIdToTransactions).forEach((companyId) => {
let accountNumbers = companyIdToTransactions[companyId].map((transaction) => transaction.accountNumber);
accountNumbers = _.uniq(accountNumbers);
companyIdToAccountNumbers[companyId] = accountNumbers;
});
return companyIdToAccountNumbers;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not in bankScraper module?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This I will move into the importTransactions module since it is related logic and uses the scrapeFinancialAccountsAndFetchTransactions function defined there

@brafdlog
Copy link
Owner Author

brafdlog commented Sep 7, 2020

I'm trying to think about a way to force us to import only from originalBudgetTrackingApp and not from any originalBudgetTrackingApp/* when we are on the FrontEnd code.

Maybe this:
https://eslint.org/docs/rules/no-restricted-imports
Just keep in your mind

Opened a separate issue for this #93

@brafdlog brafdlog merged commit 467f7b5 into unifyRepos Sep 7, 2020
@brafdlog brafdlog deleted the breakLibIndex branch September 7, 2020 20:12
brafdlog pushed a commit that referenced this pull request Dec 22, 2020
…nfig-25.1.0

Bump jest-config from 24.9.0 to 25.1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Break the lib index file into separate files for the major parts of the flow
2 participants