Skip to content

Commit

Permalink
Patch(mongoose-audit): updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka47000 authored Mar 11, 2024
1 parent fcc0a18 commit ab4f388
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion plugins/mongoose-audit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "node ../../scripts/esbuild.config.js",
"build:watch": "bash ../../scripts/esbuild.watch.sh",
"bump-version": "bash ../../scripts/bump-version.sh --name=@sliit-foss/express-http-context",
"bump-version": "bash ../../scripts/bump-version.sh --name=@sliit-foss/mongoose-audit",
"lint": "bash ../../scripts/lint.sh",
"release": "bash ../../scripts/release.sh",
"test": "if [ \"$CI\" = \"true\" ]; then \n bash ../../scripts/test/test.sh; else \n echo \"Skipping as it is not a CI environment\"; fi"
Expand Down
29 changes: 17 additions & 12 deletions plugins/mongoose-audit/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#### A rework of the [mongoose-audit-log](https://www.npmjs.com/package/mongoose-audit-log) package to support newer versions of mongoose and more flexible options<br>

#### !IMPORTANT - The behaviour of this is different from the original `mongoose-audit-log` package and cannot be considered as a drop in replacement for it.
#### IMPORTANT - The behaviour of this is different from the original `mongoose-audit-log` package and cannot be considered as a drop in replacement for it.

It is a mongoose plugin to manage an audit log of changes to a MongoDB database.

Expand Down Expand Up @@ -54,15 +54,20 @@ router.get("/api/users/:id/history", (req, res, next) => {

## All supported plugin options

```javascript
const { plugin, AuditType } = require("@sliit-foss/mongoose-audit");
- getUser - () => any
- The user extractor function to use. This probably will be fetching the current user from a context or something similar.

SomeSchema.plugin(plugin, {
getUser: () => "user details from wherever you wish to get it",
types: [AuditType.Edit], // default: ['add', 'edit', 'delete']
exclude: ["field1", "field2"],
onAudit: (audit) => {
// Called before persisting the audit is saved. Use this to use your own audit model instead of the default one.
}
});
```
- types - AuditType[]
- The types of audit to record.

- include - string[]
- The fields to consider for the audit. Cannot be used along with exclude.

- exclude - string[]
- The fields to exclude from the audit. Cannot be used along with include.

- onAudit - (audit) => Promise<void>
- Called before persisting the audit is saved. Use this to use your own audit model instead of the default one.

- background - boolean
- By default audit logs are persisted asynchronously in the background. Change this to false if you want it to be synchronous.
2 changes: 1 addition & 1 deletion plugins/mongoose-audit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface Options {
include?: string[];
/** Called before persisting the audit is saved. Use this to use your own audit model instead of the default one. */
onAudit?: (audit: Audit) => Promise<any>;
/** By default audit logs are persisted asynchronously in the background. Change this to false if you want it to be synchronous" */
/** By default audit logs are persisted asynchronously in the background. Change this to false if you want it to be synchronous." */
background?: boolean;
}

Expand Down

0 comments on commit ab4f388

Please sign in to comment.