@dynamatix/cat-shared 0.0.14 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,14 @@
1
+ import AuditConfigModel from '../models/audit-config.model.js';
2
+ import AuditLog from '../models/audit.model.js';
3
+ import { getContext } from '../services/request-context.service.js';
4
+
1
5
 
2
6
  let onAuditLogCreated = null;
3
7
 
4
8
  function applyAuditMiddleware(schema, collectionName) {
5
9
  // Handle create
6
10
  schema.post('save', async function (doc) {
7
- const auditConfig = await AuditConfigModel.findOne({ collectionName });
11
+ const auditConfig = await AuditLog.findOne({ collectionName });
8
12
  if (!auditConfig?.trackCreation) return;
9
13
 
10
14
  const context = getContext();
@@ -20,7 +24,7 @@ function applyAuditMiddleware(schema, collectionName) {
20
24
  contextId
21
25
  };
22
26
  if (onAuditLogCreated) {
23
- onAuditLogCreated(logs); // 👈 Call the hook with the logs
27
+ onAuditLogCreated(logs, contextId); // 👈 Call the hook with the logs
24
28
  }
25
29
 
26
30
  await AuditLog.create(log);
@@ -61,7 +65,7 @@ function applyAuditMiddleware(schema, collectionName) {
61
65
 
62
66
  if (logs.length) await AuditLog.insertMany(logs);
63
67
  if (onAuditLogCreated) {
64
- onAuditLogCreated(logs); // 👈 Call the hook with the logs
68
+ onAuditLogCreated(logs, contextId); // 👈 Call the hook with the logs
65
69
  }
66
70
  });
67
71
  }
@@ -1,2 +1,2 @@
1
1
  export {default as applyAuditMiddleware} from './audit.middleware.js';
2
- export {default as registerAuditHook } from './audit.middleware.js';
2
+ export { registerAuditHook } from './audit.middleware.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamatix/cat-shared",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"