@sera4/essentia 1.1.26 → 1.1.27
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/package.json +1 -1
- package/package.tar.gz +0 -0
- package/paper-trail/index.js +10 -4
package/package.json
CHANGED
package/package.tar.gz
CHANGED
|
Binary file
|
package/paper-trail/index.js
CHANGED
|
@@ -84,8 +84,8 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
84
84
|
const log = options.log || console.log;
|
|
85
85
|
|
|
86
86
|
function createBeforeHook(operation) {
|
|
87
|
-
|
|
88
87
|
const beforeHook = function beforeHook(instance, opt) {
|
|
88
|
+
|
|
89
89
|
if (options.debug) {
|
|
90
90
|
log('beforeHook called');
|
|
91
91
|
log('instance:', instance);
|
|
@@ -100,6 +100,7 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
const destroyOperation = operation === 'destroy';
|
|
103
|
+
const restoreOperation = operation === 'restore';
|
|
103
104
|
|
|
104
105
|
let previousVersion = {};
|
|
105
106
|
let currentVersion = {};
|
|
@@ -189,7 +190,7 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
189
190
|
}
|
|
190
191
|
}
|
|
191
192
|
|
|
192
|
-
if (destroyOperation || (delta && delta.length > 0)) {
|
|
193
|
+
if (destroyOperation || restoreOperation || (delta && delta.length > 0)) {
|
|
193
194
|
const revisionId = (currentRevisionId || 0) + 1;
|
|
194
195
|
instance.set(options.revisionAttribute, revisionId);
|
|
195
196
|
|
|
@@ -224,12 +225,13 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
224
225
|
|
|
225
226
|
const destroyOperation = operation === 'destroy';
|
|
226
227
|
const createOperation = operation === 'create';
|
|
228
|
+
const restoreOperation = operation === 'restore';
|
|
227
229
|
|
|
228
230
|
if (
|
|
229
231
|
instance.context &&
|
|
230
232
|
((instance.context.delta &&
|
|
231
233
|
instance.context.delta.length > 0) ||
|
|
232
|
-
destroyOperation)
|
|
234
|
+
destroyOperation || restoreOperation)
|
|
233
235
|
) {
|
|
234
236
|
const Revision = sequelize.model(options.revisionModel);
|
|
235
237
|
let RevisionChange;
|
|
@@ -245,6 +247,7 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
245
247
|
let previousVersion = {};
|
|
246
248
|
let currentVersion = {};
|
|
247
249
|
if (!destroyOperation && options.enableCompression) {
|
|
250
|
+
opt.fields = opt.fields || instance._options.attributes
|
|
248
251
|
_.forEach(opt.fields, a => {
|
|
249
252
|
previousVersion[a] = instance._previousDataValues[a];
|
|
250
253
|
currentVersion[a] = instance.dataValues[a];
|
|
@@ -284,7 +287,9 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
284
287
|
let document;
|
|
285
288
|
if (destroyOperation) {
|
|
286
289
|
document = { oldValues: currentVersion };
|
|
287
|
-
} else if (createOperation) {
|
|
290
|
+
} else if (createOperation || restoreOperation) {
|
|
291
|
+
// we want to print out the entire object as values MAY have changed when restoring
|
|
292
|
+
// and for NEW objects, we want the initial state
|
|
288
293
|
document = { newValues: currentVersion };
|
|
289
294
|
} else {
|
|
290
295
|
document = { oldValues: previousVersion, newValues: currentVersion };
|
|
@@ -440,6 +445,7 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
440
445
|
// beforeCreate(instance, options, fn)
|
|
441
446
|
// beforeDestroy(instance, options, fn)
|
|
442
447
|
// beforeUpdate(instance, options, fn)
|
|
448
|
+
// beforeRestore(instance, options, fn)
|
|
443
449
|
// (-)
|
|
444
450
|
// create
|
|
445
451
|
// destroy
|