@autofleet/shtinker 1.1.6-beta.18 → 1.1.6-beta.19
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 -22
- package/package.json +1 -2
- package/src/audit-logger.ts +4 -22
package/dist/audit-logger.js
CHANGED
|
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const moment_1 = __importDefault(require("moment"));
|
|
16
15
|
const zehut_1 = require("@autofleet/zehut");
|
|
17
16
|
const const_1 = require("./const");
|
|
18
17
|
const logger_1 = __importDefault(require("./logger"));
|
|
@@ -29,36 +28,19 @@ const isEmpty = (field) => {
|
|
|
29
28
|
if (Array.isArray(field)) {
|
|
30
29
|
return field.length === 0;
|
|
31
30
|
}
|
|
32
|
-
if (typeof field === 'object') {
|
|
33
|
-
if (moment_1.default.isMoment(field)) {
|
|
34
|
-
logger_1.default.info(`Field ${field} is moment obj: `, { keysLength: Object.keys(field).length });
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
if (moment_1.default.isDate(field)) {
|
|
38
|
-
logger_1.default.info(`Field ${field} is date obj: `, { keysLength: Object.keys(field).length });
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
31
|
+
if (typeof field === 'object' && !(field instanceof Date)) {
|
|
41
32
|
return Object.keys(field).length === 0;
|
|
42
33
|
}
|
|
43
34
|
return false;
|
|
44
35
|
};
|
|
45
|
-
const filterOutEmptyFields = (fields, instance) => fields.filter((field) =>
|
|
46
|
-
logger_1.default.info('filterOutEmptyFields: ', { field, previousValue: instance.previous(field), newValue: instance.get(field) });
|
|
47
|
-
return !isEmpty(instance.previous(field)) || !isEmpty(instance.get(field));
|
|
48
|
-
});
|
|
36
|
+
const filterOutEmptyFields = (fields, instance) => fields.filter((field) => !isEmpty(instance.get(field)) || !isEmpty(instance.previous(field)));
|
|
49
37
|
const getChangedFields = (instance, options) => {
|
|
50
38
|
// When bulk updating in sequelize using the "returning" option, the instance.changed() stops working.
|
|
51
39
|
// It's a known issut with sequelize.
|
|
52
40
|
if (options.returning) {
|
|
53
|
-
|
|
54
|
-
logger_1.default.info('BULK UPDATING', { options, nonEmptyChangedFields });
|
|
55
|
-
return nonEmptyChangedFields;
|
|
41
|
+
return filterOutEmptyFields(options.fields, instance);
|
|
56
42
|
}
|
|
57
|
-
|
|
58
|
-
logger_1.default.info('changedProperties: ', { changedProperties });
|
|
59
|
-
const nonEmptyChangedProperties = filterOutEmptyFields(changedProperties, instance);
|
|
60
|
-
logger_1.default.info('nonEmptyChangedProperties: ', { nonEmptyChangedProperties });
|
|
61
|
-
return nonEmptyChangedProperties;
|
|
43
|
+
return instance.changed();
|
|
62
44
|
};
|
|
63
45
|
class AuditLogger {
|
|
64
46
|
constructor(options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/shtinker",
|
|
3
|
-
"version": "1.1.6-beta.
|
|
3
|
+
"version": "1.1.6-beta.19",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
"@autofleet/netwrok": "^1.0.0",
|
|
19
19
|
"@autofleet/rabbit": "^3.2.14",
|
|
20
20
|
"@autofleet/zehut": "^3.0.10",
|
|
21
|
-
"moment": "^2.30.1",
|
|
22
21
|
"sequelize-typescript": "^2.1.5"
|
|
23
22
|
},
|
|
24
23
|
"devDependencies": {
|
package/src/audit-logger.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import moment from 'moment';
|
|
2
1
|
import { getCurrentPayload as getCurrentTrace } from '@autofleet/zehut';
|
|
3
2
|
import { Sequelize } from 'sequelize';
|
|
4
3
|
|
|
@@ -20,38 +19,21 @@ const isEmpty = (field) => {
|
|
|
20
19
|
if (Array.isArray(field)) {
|
|
21
20
|
return field.length === 0;
|
|
22
21
|
}
|
|
23
|
-
if (typeof field === 'object') {
|
|
24
|
-
if (moment.isMoment(field)) {
|
|
25
|
-
logger.info(`Field ${field} is moment obj: `, { keysLength: Object.keys(field).length });
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
if (moment.isDate(field)) {
|
|
29
|
-
logger.info(`Field ${field} is date obj: `, { keysLength: Object.keys(field).length });
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
22
|
+
if (typeof field === 'object' && !(field instanceof Date)) {
|
|
32
23
|
return Object.keys(field).length === 0;
|
|
33
24
|
}
|
|
34
25
|
return false;
|
|
35
26
|
}
|
|
36
27
|
|
|
37
|
-
const filterOutEmptyFields = (fields, instance) => fields.filter((field) =>
|
|
38
|
-
logger.info('filterOutEmptyFields: ', { field, previousValue: instance.previous(field), newValue: instance.get(field) })
|
|
39
|
-
return !isEmpty(instance.previous(field)) || !isEmpty(instance.get(field))
|
|
40
|
-
});
|
|
28
|
+
const filterOutEmptyFields = (fields, instance) => fields.filter((field) => !isEmpty(instance.get(field)) || !isEmpty(instance.previous(field)));
|
|
41
29
|
|
|
42
30
|
const getChangedFields = (instance, options) => {
|
|
43
31
|
// When bulk updating in sequelize using the "returning" option, the instance.changed() stops working.
|
|
44
32
|
// It's a known issut with sequelize.
|
|
45
33
|
if (options.returning) {
|
|
46
|
-
|
|
47
|
-
logger.info('BULK UPDATING', { options, nonEmptyChangedFields });
|
|
48
|
-
return nonEmptyChangedFields;
|
|
34
|
+
return filterOutEmptyFields(options.fields, instance);
|
|
49
35
|
}
|
|
50
|
-
|
|
51
|
-
logger.info('changedProperties: ', { changedProperties });
|
|
52
|
-
const nonEmptyChangedProperties = filterOutEmptyFields(changedProperties, instance);
|
|
53
|
-
logger.info('nonEmptyChangedProperties: ', { nonEmptyChangedProperties });
|
|
54
|
-
return nonEmptyChangedProperties;
|
|
36
|
+
return instance.changed();
|
|
55
37
|
};
|
|
56
38
|
|
|
57
39
|
class AuditLogger {
|