commodo-fields-storage-crud-logs
Appends createdOn
, updatedOn
, and savedOn
fields to your model. The fields are automatically updated with current time before the model is about to be saved.
Install
npm install --save commodo-fields-storage-crud-logs
Or if you prefer yarn:
yarn add commodo-fields-storage-crud-logs
Quick Example:
;;; const Company = ; const company = ;companyname = "Acme Corporation"; // All fields null as a default value.console; // Logs null.console; // Logs null.console; // Logs null. // Upon saving the model for the first time, "createdOn" and "savedOn" fields will receive a value:await company;console; // Logs "2020-04-19T14:34:42.993Z" (same as savedOn). console; // Logs null.console; // Logs "2020-04-19T14:34:42.993Z" (same as createdOn). // On every following save, only the "updatedOn" and "savedOn" fields will be updated:await company;console; // Logs "2020-04-19T14:34:42.993Z" (no change here).console; // Logs "2020-04-19T14:37:05.726Z" (same as savedOn).console; // Logs "2020-04-19T14:34:42.993Z" (same as updatedOn).
withCrudLogs
is used with the withStorage
function
In order to update the field values accordingly, the withCrudLogs
internally utilizes the beforeSave
, beforeCreate
, and beforeUpdate
hooks, which are exposed by the withStorage
function.
Contributors
Thanks goes to these wonderful people (emoji key):
Adrian Smijulj 💻 📖 💡 👀 ⚠️ |
---|
This project follows the all-contributors specification. Contributions of any kind welcome!