@autofleet/shtinker 1.0.0 → 1.0.2

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.
@@ -21,6 +21,14 @@ const getAuditContext = () => {
21
21
  const auditContext = (_a = currentTrace === null || currentTrace === void 0 ? void 0 : currentTrace.context) === null || _a === void 0 ? void 0 : _a.get(const_1.AUDIT_LOG_CONTEXT_KEY);
22
22
  return auditContext;
23
23
  };
24
+ const getChangedFields = (instance, options) => {
25
+ // When bulk updating in sequelize using the "returning" option, the instance.changed() stops working.
26
+ // It's a known issut with sequelize.
27
+ if (options.returning) {
28
+ return options.fieldsl;
29
+ }
30
+ return instance.changed();
31
+ };
24
32
  class AuditLogger {
25
33
  constructor(options) {
26
34
  this.rabbit = options.rabbit;
@@ -29,10 +37,10 @@ class AuditLogger {
29
37
  }
30
38
  registerHooks() {
31
39
  Object.entries(this.sequelize.models).forEach(([modelName, modelType]) => {
32
- modelType.addHook('afterSave', (instance) => __awaiter(this, void 0, void 0, function* () {
40
+ modelType.addHook('afterSave', (instance, options) => __awaiter(this, void 0, void 0, function* () {
33
41
  const auditContext = getAuditContext();
34
42
  if (auditContext) {
35
- const changedProperties = instance.changed();
43
+ const changedProperties = getChangedFields(instance, options);
36
44
  const payload = {
37
45
  entityType: modelName,
38
46
  entityId: instance.id,
package/dist/types.d.ts CHANGED
@@ -32,7 +32,9 @@ export declare enum Action {
32
32
  UNASSIGN = "unassign",
33
33
  BULK_ASSIGN = "bulk-assign",
34
34
  REASSIGN = "reassign",
35
- DISPATCH = "dispatch"
35
+ DISPATCH = "dispatch",
36
+ JOIN = "join",
37
+ MOVE = "move"
36
38
  }
37
39
  export declare enum EntityType {
38
40
  RIDE = "Ride",
package/dist/types.js CHANGED
@@ -13,6 +13,8 @@ var Action;
13
13
  Action["BULK_ASSIGN"] = "bulk-assign";
14
14
  Action["REASSIGN"] = "reassign";
15
15
  Action["DISPATCH"] = "dispatch";
16
+ Action["JOIN"] = "join";
17
+ Action["MOVE"] = "move";
16
18
  })(Action = exports.Action || (exports.Action = {}));
17
19
  var EntityType;
18
20
  (function (EntityType) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/shtinker",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -12,6 +12,15 @@ const getAuditContext = () => {
12
12
  return auditContext;
13
13
  };
14
14
 
15
+ const getChangedFields = (instance, options) => {
16
+ // When bulk updating in sequelize using the "returning" option, the instance.changed() stops working.
17
+ // It's a known issut with sequelize.
18
+ if (options.returning) {
19
+ return options.fieldsl;
20
+ }
21
+ return instance.changed();
22
+ };
23
+
15
24
  class AuditLogger {
16
25
  private rabbit;
17
26
 
@@ -27,10 +36,10 @@ class AuditLogger {
27
36
 
28
37
  registerHooks(): void {
29
38
  Object.entries(this.sequelize.models).forEach(([modelName, modelType]) => {
30
- modelType.addHook('afterSave', async (instance: any) => {
39
+ modelType.addHook('afterSave', async (instance: any, options: any) => {
31
40
  const auditContext = getAuditContext();
32
41
  if (auditContext) {
33
- const changedProperties = instance.changed();
42
+ const changedProperties = getChangedFields(instance, options);
34
43
  const payload: AuditLogPayload = {
35
44
  entityType: modelName,
36
45
  entityId: instance.id,
package/src/types.ts CHANGED
@@ -39,7 +39,8 @@ export enum Action {
39
39
  BULK_ASSIGN = 'bulk-assign',
40
40
  REASSIGN = 'reassign',
41
41
  DISPATCH = 'dispatch',
42
-
42
+ JOIN = 'join',
43
+ MOVE = 'move',
43
44
  }
44
45
 
45
46
  export enum EntityType {