1.0.13 • Published 5 years ago

tfg-paper-trail v1.0.13

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

TFG Paper Trail

Similar to sequelize-paper-trail.

Key features: 1. Save revisions of documents 2. 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!) 2. 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;

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago