tfg-paper-trail
v1.0.13
Published
Similar to sequelize-paper-trail.
Downloads
6
Readme
TFG Paper Trail
Similar to sequelize-paper-trail.
Key features:
- Save revisions of documents
- Save both the id and the display_name of the user making the updates (Useful in microservies where the User is not available as related table!)
- View the delta (information changed on model updates)
Init
Sequelize = require("tfg-paper-trail").init(Sequelize);
require('tfg-paper-trail').defineModels(db);
db.Work.hasPaperTrail(db);
Pass the user detail
Set the userId and the user_display_name if there is no User table e.g. microservices
var getNamespace = require('continuation-local-storage').getNamespace;
var session = getNamespace('my session');
session.runPromise(async ()=>{
let user = session.set('userId', req.user.id);
let user_display_name = session.set('user_display_name', req.user.n);
return next();
});
Include the revisions
` models.Work.findOne({ where : {id:req.params.id}, include: [ { model: models.Revision, separate: true, order: [["createdAt", "desc"]], limit: JSON.parse(req.query.revisionLimit || 100), offset: JSON.parse((req.query.revisionPage || 1) -1) * (req.query.revisionLimit || 100) }
]
})
`
Create the table
For development you can run .sync() For production use your favouriate auto-migration-table package
Options
Default Options excludes_from_delta = ["updatedAt"]; excludes_from_document = []; allowNullUserDisplayName = true; allowNullUserId = false;