jozsi/mystash

Transactions

Opened this issue · 0 comments

Specs for this task as WIP

We need to support two types of transactions

  • Regular transactions (purchases, that are simply subtracted from the transaction's wallet total amount)
  • Inter-wallet transactions (the amount is transferred from one wallet to another, i.e. they are subtracted from the source wallet and added to the destination wallet).
    • Issue: How can we support conversion transactions (i.e. wallet one has one currency, wallet two has a different currency).
      • One option is to detect if the wallets have different currencies and show a popup asking the user for the conversion rate. At some point we can even suggest a conversion rate based on some online conversion tools

Fields

  • CreatedBy (FK on User)
  • Wallet (FK on Wallet)
  • Date
  • Amount
  • Details

If this is a transfer between wallets

  • TransferredTo (FK on Wallet)

Thoughts about encryption (Later Edit)

(please note that the a similar thing would apply for wallet)

  • If we want to encrypt the transaction object before storing it in the database, we would have to store Amount and Details in a field (called Data) and encrypt that entire dict on presave / decrypt on preload
  • I would leave Date, Wallet and outside of the encrypted part because:
    • They do not provide any detailed information on the transaction (i.e. how much was spent or on what)
    • It would be easier to query the database and retrieve only the information needed when querying for a wallet (otherwise we'd have to pull everything, decrypt, and only after the decryption part eliminate what is not needed.

As such the database structure would be something like

{
  _id: ObjId
  CreatedBy: RefId(User)
  Wallet: RefId(Wallet)
  CreatedOn: Date // I renamed this from `Date` to avoid confusion with the `Data` field
  Data: {
    Amount: Number,
    Details: String
  }
}

One question is if the model would support this (if Data was encrypted, it would no longer be a Dict but rather a binary field).

One possible solution would be to store the encrypted data into a separate field, (i.e. EncryptedData) and decrypt it in preload (or whatever Mongoose's equivalent method is) then copy it into Data. At write, the Data variable would be removed (In this case, Data and Encrypted Data would be mutually exclusive fields in the database).
If encryption is used, then, the Data field would only exist in the model, and would not be persisted in the database)