mirror of
https://github.com/JonasunderscoreJones/jonas_jones-api.git
synced 2025-10-24 17:49:18 +02:00
some progress
This commit is contained in:
parent
aea93a5527
commit
e3c15bd288
1388 changed files with 306946 additions and 68323 deletions
54
node_modules/mongoose/lib/helpers/query/applyQueryMiddleware.js
generated
vendored
Normal file
54
node_modules/mongoose/lib/helpers/query/applyQueryMiddleware.js
generated
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
module.exports = applyQueryMiddleware;
|
||||
|
||||
const validOps = require('./validOps');
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
applyQueryMiddleware.middlewareFunctions = validOps.concat([
|
||||
'validate'
|
||||
]);
|
||||
|
||||
/**
|
||||
* Apply query middleware
|
||||
*
|
||||
* @param {Query} Query constructor
|
||||
* @param {Model} model
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function applyQueryMiddleware(Query, model) {
|
||||
const queryMiddleware = model.schema.s.hooks.filter(hook => {
|
||||
const contexts = _getContexts(hook);
|
||||
if (hook.name === 'validate') {
|
||||
return !!contexts.query;
|
||||
}
|
||||
if (hook.name === 'deleteOne' || hook.name === 'updateOne') {
|
||||
return !!contexts.query || Object.keys(contexts).length === 0;
|
||||
}
|
||||
if (hook.query != null || hook.document != null) {
|
||||
return !!hook.query;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
Query.prototype._queryMiddleware = queryMiddleware;
|
||||
}
|
||||
|
||||
function _getContexts(hook) {
|
||||
const ret = {};
|
||||
if (hook.hasOwnProperty('query')) {
|
||||
ret.query = hook.query;
|
||||
}
|
||||
if (hook.hasOwnProperty('document')) {
|
||||
ret.document = hook.document;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue