nax3t / automated-payroll

1 stars 3 forks source link

Some ideas to make this more readable #5

Closed imcodingideas closed 3 years ago

imcodingideas commented 3 years ago

I have a few ideas to help make this a little more readable, and wonder if I worked on this would you accept the pull request.

API Client

We can create an instance of axios client with the base URL, any credentials thats needed. When we call the API we would do so with our instance.

Add Service Layer

Basically a service is just a function or class that does some work. It just does 1 thing and 1 thing only. GetAccountsPayableService for example.

Personal preferences

https://github.com/nax3t/automated-payroll/blob/main/app.js#L72-L73

We can do something like this instead: action.label?.name === 'Ready to pay'

Create a Webhook instead?

At the end of the day we have an interval when we need to do work.

https://github.com/nax3t/automated-payroll/blob/main/app.js#L181-L186

Consider having some other service, like GitHub, handling the cron to send it to our webhook.

https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#scheduled-events

Track payment ledgers

What happens if a payment failed? why? where are we logging it? what would you do right now if payment failed and someone asked you to look into it? When you do track it in a database this is a secondary action so I would take a instance of eventemitter with something like this pattern

https://refactoring.guru/design-patterns/observer