axatbhardwaj / Multichain-wallet

A wallet application written for Eth and solana
MIT License
0 stars 0 forks source link

Suggestions #1

Open PreetamSing opened 3 months ago

PreetamSing commented 3 months ago
axatbhardwaj commented 2 months ago
  `model.create()` function call already saves the data, so don't need to call `.save()` method after that. Also, assigning return value of `.save()` method to a variable isn't necessary if that variable won't be used. I, personally, use following syntax for saving document to db.
  ```js
  const account = new accountModel({
      address,
      publickey,
      privatekey
  });
  // account.someOtherProp = (some complex logic value)
  await account.save();
  // Use values returned by saving doc, e.g. "_id" or on save hook generated value, to update dependent fields.
  account.dependentProp = account.expiry + account.x;
  await account.save();
  ```

would love to know what is it doing

specifically this part

  account.dependentProp = account.expiry + account.x;
PreetamSing commented 2 months ago

specifically this part

  account.dependentProp = account.expiry + account.x;

That, is just a representation of a fairly rare scenario, where you need database generated value of some fields to calculate the dependent field. Hence, you have to call save method twice. In your exact API that I've referenced, this isn't required.

Hope, that clears it up.