@patrickkeller/mongoose-audit
TypeScript icon, indicating that this package has built-in type declarations

1.2.4 • Public • Published

Installation

npm install @patrickkeller/mongoose-audit

Versionen

1.2.4

  • __user nicht mehr per Default zurückgeben.

1.2.3

  • findByLOcation und findById Funktionen.

1.1.3

  • AuditLog Model exportiert um Queries zu vereinfachen.

1.0.0

  • Initiale Version

Config

keine

AuditPlugin

Damit automatisch bei update, create, delete Audit-Logs erstellt werden muss das Plugin eingebunden werden

import {AuditPlugin} from '@patrickkeller/mongoose-audit';
// ...
mongoose.plugin(AuditPlugin);
// ...

Damit auch Benutzerinfos mitgespeichert werden ist eine zusätzliche Middleware in Koa erforderlich. Damit sind keine Controller Anpassungen notwendig. Diese könnte zum Beispiel so aussehen:

  app.use(async function (ctx, next) {
    if (ctx.data && ctx.state.user) {
      lo.extend(ctx.data, {__user: ctx.state.user._id});
    }

    await next();
  });

AuditLog.findbyLocation und AuditLog.findByDocument

In den Controllers können mit diesen beiden Model-Queries die Logs einfach abgefragt werden

// ...
  indexLog: async (ctx) => {
    const page = ctx.query.page || 1;
    let records: any = await AuditLog.findByLocation('users', page);

    ctx.body = { data: records };
  }
// ...
  log: async (ctx) => {
    const page = ctx.query.page || 1;
    let records: any = await AuditLog.findByDocument('users', ctx.params.id, page);

    ctx.body = { data: records };
  }

auditLog

Mit dieser Funktion lassen sich manuell Audit-Einträge erstellen.

import {auditLog} from '@patrickkeller/mongoose-audit';
// ...
auditLog(model, 'delete')
// ...

Readme

Keywords

none

Package Sidebar

Install

npm i @patrickkeller/mongoose-audit

Weekly Downloads

11

Version

1.2.4

License

ISC

Last publish

Collaborators

  • patrickkeller