Skip to content

Commit cd930c7

Browse files
fix(model): skip applying static hooks by default if static name conflicts with aggregate middleware
1 parent 75e1dd8 commit cd930c7

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/constants.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,13 @@ const queryMiddlewareFunctions = queryOperations.concat([
3434
]);
3535

3636
exports.queryMiddlewareFunctions = queryMiddlewareFunctions;
37+
38+
/*!
39+
* ignore
40+
*/
41+
42+
const aggregateMiddlewareFunctions = [
43+
'aggregate'
44+
];
45+
46+
exports.aggregateMiddlewareFunctions = aggregateMiddlewareFunctions;

lib/helpers/model/applyStaticHooks.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
'use strict';
22

3-
const middlewareFunctions = require('../../constants').queryMiddlewareFunctions;
43
const promiseOrCallback = require('../promiseOrCallback');
4+
const { queryMiddlewareFunctions, aggregateMiddlewareFunctions } = require('../../constants');
5+
6+
const middlewareFunctions = [
7+
...queryMiddlewareFunctions,
8+
...aggregateMiddlewareFunctions
9+
];
510

611
module.exports = function applyStaticHooks(model, hooks, statics) {
712
const kareemOptions = {
@@ -10,7 +15,7 @@ module.exports = function applyStaticHooks(model, hooks, statics) {
1015
};
1116

1217
hooks = hooks.filter(hook => {
13-
// If the custom static overwrites an existing query middleware, don't apply
18+
// If the custom static overwrites an existing middleware, don't apply
1419
// middleware to it by default. This avoids a potential backwards breaking
1520
// change with plugins like `mongoose-delete` that use statics to overwrite
1621
// built-in Mongoose functions.

0 commit comments

Comments
 (0)