letehaha / budget-tracker-fe

A web app to keep track of your finances. Track and get stats about your income, expenses and investments. WIP
https://gamanets.money
MIT License
0 stars 0 forks source link

Change decimal numbers handle on the backend #245

Open letehaha opened 1 year ago

letehaha commented 1 year ago

Right now we multiply amounts by 100. It's already a problem since we need to multiply currency rates by at least 10,000. Also, it is difficult to maintain since you need to not forget to do multiplications each time.

Need to switch to using decimal.js and store raw decimal values in the DB as strings (or decimals, still TBD).

Pros: – no need to care about multiply/divide logic, you can just work with raw values and return them to the client (so client will be simplified as well) – DB will have readable values format – if there's a need to add crypto support, or etc, it will require zero effort, but only updation to decimal.js config.

Cons: – DB size will be increased compared to storing raw integers – not able to make arithmetical operations directly in the SQL queries (currently we do that only in a single place) – read/create/update operations in the DB require transformation from number to string and vice versa


TBD:

  1. What data format return to client – number or string
  2. What data format use to store in the DB – decimal number or string. Since we will still need to transform data in the DB => Model layer, there's no much difference in what format we need to store it. So in that case decimal might be better, since we will be able to make arithmetic operations with SQL queries in urgent cases (because we need to aim to make these calculations using JS in the services anyway).