Skip to content

Commit

Permalink
moving postSave() method definition (lint warning)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekDomino committed Jan 21, 2016
1 parent 0064158 commit a0aa306
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions lib/mongoosastic.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,29 @@ function Mongoosastic(schema, pluginOpts) {
}
}

function postSave(doc) {
function onIndex(err, res) {
if (!filter || !filter(doc)) {
doc.emit('es-indexed', err, res);
} else {
doc.emit('es-filtered', err, res);
}
}

if (doc) {
if (populate && populate.length) {
populate.forEach(function (populateOpts) {
doc.populate(populateOpts);
});
doc.execPopulate().then(function (popDoc) {
popDoc.index(onIndex);
});
} else {
doc.index(onIndex);
}
}
}

function clearBulkTimeout() {
clearTimeout(bulkTimeout);
bulkTimeout = undefined;
Expand Down Expand Up @@ -597,29 +620,6 @@ function Mongoosastic(schema, pluginOpts) {
}
}

function postSave(doc) {
function onIndex(err, res) {
if (!filter || !filter(doc)) {
doc.emit('es-indexed', err, res);
} else {
doc.emit('es-filtered', err, res);
}
}

if (doc) {
if (populate && populate.length) {
populate.forEach(function (populateOpts) {
doc.populate(populateOpts);
});
doc.execPopulate().then(function (popDoc) {
popDoc.index(onIndex);
});
} else {
doc.index(onIndex);
}
}
}

/**
* Use standard Mongoose Middleware hooks
* to persist to Elasticsearch
Expand Down

0 comments on commit a0aa306

Please sign in to comment.