Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #60 from nassor/revert-59-master
Browse files Browse the repository at this point in the history
Revert "change pre to post (findOneAndUpdate)"
  • Loading branch information
nassor authored Oct 14, 2020
2 parents 0a93df0 + 1111116 commit 8fc54eb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 369 deletions.
11 changes: 2 additions & 9 deletions lib/mongoose-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ module.exports = function historyPlugin(schema, options) {
});

// Listen on findOneAndUpdate
schema.post('findOneAndUpdate', function (doc, next) {
if (doc) { processPostUpdate.call(this, doc, next) } else { return next(); }
schema.pre('findOneAndUpdate', function (next) {
processUpdate.call(this, next);
});

// Create a copy on remove
Expand Down Expand Up @@ -143,13 +143,6 @@ module.exports = function historyPlugin(schema, options) {
saveHistoryModel(this.toObject, d, historyDoc, this.mongooseCollection.collectionName, next);
}

function processPostUpdate(doc, next) {
let d = this._update.$set || this._update;
let historyDoc = createHistoryDoc(d, 'u');

saveHistoryModel(this.toObject, d, historyDoc, this.mongooseCollection.collectionName, next);
}

function processRemove(doc, next) {
let d = doc.toObject();
let historyDoc = createHistoryDoc(d, 'r');
Expand Down
360 changes: 0 additions & 360 deletions yarn.lock

This file was deleted.

0 comments on commit 8fc54eb

Please sign in to comment.