@autofleet/shtinker 1.1.6-beta.12 → 1.1.6-beta.14
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.
- package/dist/audit-logger.js +4 -10
- package/package.json +1 -1
- package/src/audit-logger.ts +4 -9
package/dist/audit-logger.js
CHANGED
|
@@ -21,22 +21,20 @@ 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 isEmpty = (value)
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
const isPropertyNotEmpty = (property, instance) => { return !isEmpty(instance.previous(property)) || !isEmpty(instance.get(property)); };
|
|
24
|
+
const isEmpty = value => Array.isArray(value) ? value.length === 0 : value == null;
|
|
25
|
+
const filterOutEmptyFields = (fields, instance) => fields.filter(field => !isEmpty(instance.previous(field)) || !isEmpty(instance.get(field)));
|
|
28
26
|
const getChangedFields = (instance, options) => {
|
|
29
27
|
logger_1.default.info('START getChangedFields');
|
|
30
28
|
// When bulk updating in sequelize using the "returning" option, the instance.changed() stops working.
|
|
31
29
|
// It's a known issut with sequelize.
|
|
32
30
|
if (options.returning) {
|
|
33
|
-
const nonEmptyChangedFields = options.fields
|
|
31
|
+
const nonEmptyChangedFields = filterOutEmptyFields(options.fields, instance);
|
|
34
32
|
logger_1.default.info('BULK UPDATING', { options, nonEmptyChangedFields });
|
|
35
33
|
return nonEmptyChangedFields;
|
|
36
34
|
}
|
|
37
35
|
const changedProperties = instance.changed();
|
|
38
36
|
logger_1.default.info('changedProperties: ', { changedProperties });
|
|
39
|
-
const nonEmptyChangedProperties = changedProperties
|
|
37
|
+
const nonEmptyChangedProperties = filterOutEmptyFields(changedProperties, instance);
|
|
40
38
|
logger_1.default.info('nonEmptyChangedProperties: ', { nonEmptyChangedProperties });
|
|
41
39
|
return nonEmptyChangedProperties;
|
|
42
40
|
};
|
|
@@ -51,7 +49,6 @@ class AuditLogger {
|
|
|
51
49
|
modelType.addHook('afterSave', (instance, options) => __awaiter(this, void 0, void 0, function* () {
|
|
52
50
|
try {
|
|
53
51
|
const auditContext = getAuditContext();
|
|
54
|
-
this.logger.info('auditContext:', { auditContext });
|
|
55
52
|
if (auditContext) {
|
|
56
53
|
const changedProperties = getChangedFields(instance, options);
|
|
57
54
|
const payload = {
|
|
@@ -65,9 +62,6 @@ class AuditLogger {
|
|
|
65
62
|
};
|
|
66
63
|
this.sendAuditLogRows(payload);
|
|
67
64
|
}
|
|
68
|
-
else {
|
|
69
|
-
this.logger.info('NO AUDIT CONTEXT: ', { entityId: instance.id });
|
|
70
|
-
}
|
|
71
65
|
}
|
|
72
66
|
catch (error) {
|
|
73
67
|
logger_1.default.error('Failed to send audit log rows', error);
|
package/package.json
CHANGED
package/src/audit-logger.ts
CHANGED
|
@@ -12,24 +12,22 @@ const getAuditContext = () => {
|
|
|
12
12
|
return auditContext;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
const isEmpty = (value)
|
|
16
|
-
return Array.isArray(value) ? value.length === 0 : value == null;
|
|
17
|
-
};
|
|
15
|
+
const isEmpty = value => Array.isArray(value) ? value.length === 0 : value == null;
|
|
18
16
|
|
|
19
|
-
const
|
|
17
|
+
const filterOutEmptyFields = (fields, instance) => fields.filter(field => !isEmpty(instance.previous(field)) || !isEmpty(instance.get(field)));
|
|
20
18
|
|
|
21
19
|
const getChangedFields = (instance, options) => {
|
|
22
20
|
logger.info('START getChangedFields');
|
|
23
21
|
// When bulk updating in sequelize using the "returning" option, the instance.changed() stops working.
|
|
24
22
|
// It's a known issut with sequelize.
|
|
25
23
|
if (options.returning) {
|
|
26
|
-
const nonEmptyChangedFields = options.fields
|
|
24
|
+
const nonEmptyChangedFields = filterOutEmptyFields(options.fields, instance);
|
|
27
25
|
logger.info('BULK UPDATING', { options, nonEmptyChangedFields });
|
|
28
26
|
return nonEmptyChangedFields;
|
|
29
27
|
}
|
|
30
28
|
const changedProperties = instance.changed();
|
|
31
29
|
logger.info('changedProperties: ', { changedProperties });
|
|
32
|
-
const nonEmptyChangedProperties = changedProperties
|
|
30
|
+
const nonEmptyChangedProperties = filterOutEmptyFields(changedProperties, instance);
|
|
33
31
|
logger.info('nonEmptyChangedProperties: ', { nonEmptyChangedProperties });
|
|
34
32
|
return nonEmptyChangedProperties;
|
|
35
33
|
};
|
|
@@ -52,7 +50,6 @@ class AuditLogger {
|
|
|
52
50
|
modelType.addHook('afterSave', async (instance: any, options: any) => {
|
|
53
51
|
try {
|
|
54
52
|
const auditContext = getAuditContext();
|
|
55
|
-
this.logger.info('auditContext:', { auditContext });
|
|
56
53
|
if (auditContext) {
|
|
57
54
|
const changedProperties = getChangedFields(instance, options);
|
|
58
55
|
const payload: AuditLogPayload = {
|
|
@@ -65,8 +62,6 @@ class AuditLogger {
|
|
|
65
62
|
})),
|
|
66
63
|
};
|
|
67
64
|
this.sendAuditLogRows(payload);
|
|
68
|
-
} else {
|
|
69
|
-
this.logger.info('NO AUDIT CONTEXT: ', { entityId: instance.id });
|
|
70
65
|
}
|
|
71
66
|
} catch (error) {
|
|
72
67
|
logger.error('Failed to send audit log rows', error);
|