This repository was archived by the owner on May 1, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed
Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -230,6 +230,12 @@ module.exports.prototype.parse = function parse(query) {
230230 return ;
231231 }
232232
233+ // custom functions
234+ if ( typeof this . custom [ key ] === 'function' ) {
235+ this . custom [ key ] . apply ( null , [ res , val ] ) ;
236+ return ;
237+ }
238+
233239 // array key
234240 if ( val instanceof Array ) {
235241 if ( this . ops . indexOf ( '$in' ) >= 0 && val . length > 0 ) {
@@ -267,12 +273,8 @@ module.exports.prototype.parse = function parse(query) {
267273 return ;
268274 }
269275
270- // custom functions
271- if ( typeof this . custom [ key ] === 'function' ) {
272- this . custom [ key ] ( res , val ) ;
273-
274276 // field exists query
275- } else if ( ! val ) {
277+ if ( ! val ) {
276278 res [ key ] = { $exists : true } ;
277279
278280 // query operators
Original file line number Diff line number Diff line change @@ -886,5 +886,23 @@ describe('parse()', () => {
886886 } ,
887887 } ) ;
888888 } ) ;
889+
890+ it ( 'returns custom function query' , ( ) => {
891+ mqs = new MongoQS ( {
892+ custom : {
893+ assigned : ( query , input ) => {
894+ query [ 'assigned.users._id' ] = {
895+ $in : input . map ( id => parseInt ( id , 10 ) ) ,
896+ } ;
897+ } ,
898+ } ,
899+ } ) ;
900+
901+ assert . deepEqual ( mqs . parse ( {
902+ assigned : [ '1111' , '2222' ]
903+ } ) , {
904+ 'assigned.users._id' : { $in : [ 1111 , 2222 ] } ,
905+ } ) ;
906+ } ) ;
889907 } ) ;
890908} ) ;
You can’t perform that action at this time.
0 commit comments