Initial commit

This commit is contained in:
Luis Fernando Molina committed 2018-09-03 15:19:57 +02:00
commit f47e08fdcb
2409 files changed
+363607

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
'use strict';
/*!
* Apply query middleware
*
* @param {Query} query constructor
* @param {Model} model
*/
module.exports = function applyQueryMiddleware(Query, model) {
const kareemOptions = {
useErrorHandlers: true,
numCallbackParams: 1,
nullResultByDefault: true
};
// `update()` thunk has a different name because `_update` was already taken
Query.prototype._execUpdate = model.hooks.createWrapper('update',
Query.prototype._execUpdate, null, kareemOptions);
[
'count',
'countDocuments',
'estimatedDocumentCount',
'find',
'findOne',
'findOneAndDelete',
'findOneAndRemove',
'findOneAndUpdate',
'replaceOne',
'updateMany',
'updateOne'
].forEach(fn => {
Query.prototype[`_${fn}`] = model.hooks.createWrapper(fn,
Query.prototype[`_${fn}`], null, kareemOptions);
});
};