@@ -593,6 +593,39 @@ DataForm.prototype.report = function () {
593
593
} , this ) ;
594
594
} ;
595
595
596
+ DataForm . prototype . hackVariablesInPipeline = function ( runPipeline ) {
597
+ for ( var pipelineSection = 0 ; pipelineSection < runPipeline . length ; pipelineSection ++ ) {
598
+ if ( runPipeline [ pipelineSection ] [ '$match' ] ) {
599
+ this . hackVariables ( runPipeline [ pipelineSection ] [ '$match' ] ) ;
600
+ }
601
+ }
602
+ } ;
603
+
604
+ DataForm . prototype . hackVariables = function ( obj ) {
605
+ // Replace variables that cannot be serialised / deserialised. Bit of a hack, but needs must...
606
+ // Anything formatted 1800-01-01T00:00:00.000Z or 1800-01-01T00:00:00.000+0000 is converted to a Date
607
+ // Only handles the cases I need for now
608
+ // TODO: handle arrays etc
609
+ for ( var prop in obj ) {
610
+ if ( obj . hasOwnProperty ( prop ) ) {
611
+ if ( typeof obj [ prop ] === 'string' ) {
612
+ var dateTest = / ^ ( \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } : \d { 2 } : \d { 2 } .\d { 3 } ) ( Z | [ + - ] \d { 4 } ) $ / . exec ( obj [ prop ] ) ;
613
+ if ( dateTest ) {
614
+ obj [ prop ] = new Date ( dateTest [ 1 ] + 'Z' ) ;
615
+ } else {
616
+ var objectIdTest = / ^ ( [ 0 - 9 a - f A - F ] { 24 } ) $ / . exec ( obj [ prop ] ) ;
617
+ if ( objectIdTest ) {
618
+ obj [ prop ] = new mongoose . Types . ObjectId ( objectIdTest [ 1 ] ) ;
619
+ }
620
+ }
621
+ } else if ( _ . isObject ( obj [ prop ] ) ) {
622
+ this . hackVariables ( obj [ prop ] ) ;
623
+ }
624
+ }
625
+ }
626
+ } ;
627
+
628
+
596
629
DataForm . prototype . reportInternal = function ( req , resource , schema , options , callback ) {
597
630
var runPipeline ,
598
631
self = this ;
@@ -638,36 +671,7 @@ DataForm.prototype.reportInternal = function (req, resource, schema, options, ca
638
671
}
639
672
640
673
runPipeline = JSON . parse ( runPipeline ) ;
641
-
642
- // Replace variables that cannot be serialised / deserialised. Bit of a hack, but needs must...
643
- // Anything formatted 1800-01-01T00:00:00.000Z or 1800-01-01T00:00:00.000+0000 is converted to a Date
644
- // Only handles the cases I need for now
645
- // TODO: handle arrays etc
646
- var hackVariables = function ( obj ) {
647
- for ( var prop in obj ) {
648
- if ( obj . hasOwnProperty ( prop ) ) {
649
- if ( typeof obj [ prop ] === 'string' ) {
650
- var dateTest = / ^ ( \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } : \d { 2 } : \d { 2 } .\d { 3 } ) ( Z | [ + - ] \d { 4 } ) $ / . exec ( obj [ prop ] ) ;
651
- if ( dateTest ) {
652
- obj [ prop ] = new Date ( dateTest [ 1 ] + 'Z' ) ;
653
- } else {
654
- var objectIdTest = / ^ ( [ 0 - 9 a - f A - F ] { 24 } ) $ / . exec ( obj [ prop ] ) ;
655
- if ( objectIdTest ) {
656
- obj [ prop ] = new mongoose . Types . ObjectId ( objectIdTest [ 1 ] ) ;
657
- }
658
- }
659
- } else if ( _ . isObject ( obj [ prop ] ) ) {
660
- hackVariables ( obj [ prop ] ) ;
661
- }
662
- }
663
- }
664
- } ;
665
-
666
- for ( var pipelineSection = 0 ; pipelineSection < runPipeline . length ; pipelineSection ++ ) {
667
- if ( runPipeline [ pipelineSection ] [ '$match' ] ) {
668
- hackVariables ( runPipeline [ pipelineSection ] [ '$match' ] ) ;
669
- }
670
- }
674
+ self . hackVariablesInPipeline ( runPipeline ) ;
671
675
672
676
// Add the findFunc query to the pipeline
673
677
if ( queryObj ) {
@@ -864,7 +868,7 @@ DataForm.prototype.processCollection = function (req) {
864
868
} ;
865
869
866
870
/**
867
- * Renders a view with the list of docs, which may be filtered by the f query parameter
871
+ * Renders a view with the list of docs, which may be modified by query parameters
868
872
*/
869
873
DataForm . prototype . collectionGet = function ( ) {
870
874
return _ . bind ( function ( req , res , next ) {
@@ -881,6 +885,11 @@ DataForm.prototype.collectionGet = function () {
881
885
var skipParam = urlParts . query . s ? JSON . parse ( urlParts . query . s ) : 0 ;
882
886
var orderParam = urlParts . query . o ? JSON . parse ( urlParts . query . o ) : req . resource . options . listOrder ;
883
887
888
+ // Dates in aggregation must be Dates
889
+ if ( aggregationParam ) {
890
+ this . hackVariablesInPipeline ( aggregationParam ) ;
891
+ }
892
+
884
893
var self = this ;
885
894
886
895
this . filteredFind ( req . resource , req , aggregationParam , findParam , orderParam , limitParam , skipParam , function ( err , docs ) {
0 commit comments