-
Notifications
You must be signed in to change notification settings - Fork 47
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
Create an interface for output vendors #78
Conversation
|
name: string; | ||
init?: (config: Config) => Promise<void>; | ||
exportTransactions: (transactionsToCreate: EnrichedTransaction[], startDate: Date, config: Config) => Promise<any>; | ||
isActive: (config: Config) => boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is strange. I also wondered about that, and I realized that maybe we don't need to use isActive
at all.
Think about that, we have a method that takes config
and does scraping (and we have completely different module to save the config
), so if you don't want to export to somewhere, you just need to send the config without it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I'm thinking again. Maybe in the theory, we don't need that, but in real life, we will prefer to set enabled: false
instead of removing it from config
and saving it somewhere, just to test something.
So it should be a field in config
, not method in the outputVendor
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean the export transactions would check the relevant flag in the config and skip if it is not enabled instead of having the check if active or not happen before calling exportTransactions?
Thats fine, the only drawback is that every output vendor needs to remember to check this flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option is to have the config's of the output vendors extend an interface that will have the active boolean field, then the calling code can get for each output vendor it's config and check the active boolean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed the solution that takes it from the config but still in a generic way
export interface OutputVendor { | ||
name: string; | ||
init?: (config: Config) => Promise<void>; | ||
exportTransactions: (transactionsToCreate: EnrichedTransaction[], startDate: Date, config: Config) => Promise<any>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about getting a subset of the whole Config
type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats a good question. I considered making the OutputVendor generic and get the type of its own config. The problem there is that the calling code needs to know which config to fetch. This could be solved by assuming that the name of the output vendor will be the name of the output vendor config. To make that work I think we will need to make the output vendor name and enum instead of string. I will take a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works, but I will need to ts ignore the code that loops over the output vendors and calls export transactions because there the ts compiler is not able to know that we are passing the correct config.
Perhaps if output vendor is a class and would have a base class that has a getVendorConfig function that will return the config for that vendor (generically typed).
Will push a solution with ts ignore and when I do the class implementation will see if the solution with the base class works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's all good, but I'm afraid that I'm over-thinking. I think we can merge it, and I'm sure we will touch this code soon, so maybe the next time we will touch here we will find another solution.
In my head I always thinking about the israeli-bank-scrapers
implementation- they have an object with the names and the fields, this is like your enum
and config
, and they have a factory
to create the instance of outputVendor
(in our case).
But I'm sure after we continue to work, if we did something wrong, we will find and fix it.
if (!Object.keys(executionResult).length) { | ||
throw new Error('You need to set at least one output vendor to be active'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't understand this Error, and now more.
You already did the (none) output, so what is the error?
You just need to warn, with console.warn
for example.
I know, there is no meaning of scraping without exporting, because we don't save any state, but still, something feels wired to me. Maybe because I'm running the process without output, for test the scraping, and I know there are no outputs, so why it's error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error exists because when setting up the project you could easily forget to set any output vendor as active and then it would look as if all went well but actually nothing happened.
This type of check should be an indication in the ui instead of an error thrown. I am all for removing it, once we add an indication in the ui thats makes it clear that you have no active exporters defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Achla, this is kind of what I mean.
|
…very output vendor
@@ -108,7 +108,7 @@ async function createTransactionsInExternalVendors(config: Config, companyIdToTr | |||
|
|||
for (let j = 0; j < outputVendors.length; j++) { | |||
const outputVendor = outputVendors[j]; | |||
if (outputVendor.isActive(config)) { | |||
if (config.outputVendors[outputVendor.name]?.active) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I meant
So just create an object with I'm approving this PR. If you want to merge without finish these comments, just remember to add them to #51 or something. |
This is a basic implementation of the outputVendor interface that stays very high level, basically one main function of
exportTransactions
.A few things I am considering and would like to get your input: