persephone-audit-trail

1.0.3 • Public • Published

Installation

Always use the latest version of the package.

npm install persephone-audit-trail@1.0.2

Operation


Each update will create a history record with jsonDiff of the change. This helps in tracking all the changes happened to an object from the beginning.

Following will be the structure of the diff history being saved:

diff Collection schema:

_id : mongo id of the diff object
collectionName: Name of the collection for which diff is saved
collectionId : Mongo Id of the collection being modified
diff: diff object
user: User who modified
reason: Why the collection is modified
createdAt: When the collection is modified
_v: version

Usage


Use as you would any Mongoose plugin:

var mongoose = require('mongoose'),
    diffHistory = require('persephone-audit-trail'),
    schema = new mongoose.Schema({ ... });
    schema.plugin(diffHistory.plugin);

The plugin also has an omit option which accepts either a string or array. This will omit the given keys from history. Follows dot syntax for deeply nested values.

const mongoose = require("mongoose");
const diffHistory = require("persephone-audit-trail");

const schema = new mongoose.Schema({
  someField: String,
  ignoredField: String,
  some: {
    deepField: String
  }
});

schema.plugin(diffHistory.plugin, { omit: ["ignoredField", "some.deepField"] });

EXAMPLES

CREATE

const workflow = new Workflow({
      name,
      slug,
      description,
      priority,
      status,
      trigger,
      schedule,
      entity,
      end_chain,
      steps,
    });
    workflow.__user = "userID/ workflow"
     await workflow.save();

UPDATE

    createdWorkflow.name = 'rename';
    workflow.__user = "updaterID/ workflow"
    createdWorkflow = await createdWorkflow.save();

DELETE

    await Workflow.findByIdAndDelete( createdWorkflow._id,
        {__user: "deleterID/ workflow"},
    )

Readme

Keywords

none

Package Sidebar

Install

npm i persephone-audit-trail

Weekly Downloads

209

Version

1.0.3

License

ISC

Unpacked Size

19.1 kB

Total Files

9

Last publish

Collaborators

  • sahilchopra
  • en3a