File tree 2 files changed +28
-1
lines changed
2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -166,10 +166,12 @@ export default class DataStore {
166
166
167
167
async getObjectCount ( condition ) {
168
168
let distinct = undefined
169
+ let groupBy = undefined
169
170
170
171
if ( condition ) {
171
172
if ( condition instanceof DataQueryBuilder ) {
172
173
distinct = condition . getDistinct ( ) || undefined
174
+ groupBy = condition . getGroupBy ( ) || undefined
173
175
condition = condition . getWhereClause ( ) || undefined
174
176
} else if ( typeof condition !== 'string' ) {
175
177
throw new Error ( 'Condition must be a string or an instance of DataQueryBuilder.' )
@@ -178,7 +180,7 @@ export default class DataStore {
178
180
179
181
return this . app . request . post ( {
180
182
url : this . app . urls . dataTableCount ( this . className ) ,
181
- data : { where : condition , distinct } ,
183
+ data : { where : condition , distinct, groupBy } ,
182
184
} )
183
185
}
184
186
Original file line number Diff line number Diff line change @@ -749,6 +749,31 @@ describe('<Data> Find', function() {
749
749
expect ( result3 ) . to . be . equal ( 4 )
750
750
} )
751
751
752
+ it ( 'with groupBy ' , async ( ) => {
753
+ const req = prepareMockRequest ( 2 )
754
+
755
+ const query = Backendless . Data . QueryBuilder . create ( )
756
+
757
+ query . setGroupBy ( 'objectId' )
758
+ query . setWhereClause ( 'foo>123' )
759
+
760
+ const result = await dataStore . getObjectCount ( query )
761
+
762
+ expect ( req ) . to . deep . include ( {
763
+ method : 'POST' ,
764
+ path : `${ APP_PATH } /data/${ tableName } /count` ,
765
+ headers : {
766
+ 'Content-Type' : 'application/json'
767
+ } ,
768
+ body : {
769
+ where : 'foo>123' ,
770
+ groupBy : [ 'objectId' ]
771
+ }
772
+ } )
773
+
774
+ expect ( result ) . to . be . equal ( 2 )
775
+ } )
776
+
752
777
it ( 'fails when at least one item is invalid' , async ( ) => {
753
778
const errorMsg = 'Condition must be a string or an instance of DataQueryBuilder.'
754
779
You can’t perform that action at this time.
0 commit comments