File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
Expand file tree Collapse file tree 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 {
166166
167167 async getObjectCount ( condition ) {
168168 let distinct = undefined
169+ let groupBy = undefined
169170
170171 if ( condition ) {
171172 if ( condition instanceof DataQueryBuilder ) {
172173 distinct = condition . getDistinct ( ) || undefined
174+ groupBy = condition . getGroupBy ( ) || undefined
173175 condition = condition . getWhereClause ( ) || undefined
174176 } else if ( typeof condition !== 'string' ) {
175177 throw new Error ( 'Condition must be a string or an instance of DataQueryBuilder.' )
@@ -178,7 +180,7 @@ export default class DataStore {
178180
179181 return this . app . request . post ( {
180182 url : this . app . urls . dataTableCount ( this . className ) ,
181- data : { where : condition , distinct } ,
183+ data : { where : condition , distinct, groupBy } ,
182184 } )
183185 }
184186
Original file line number Diff line number Diff line change @@ -749,6 +749,31 @@ describe('<Data> Find', function() {
749749 expect ( result3 ) . to . be . equal ( 4 )
750750 } )
751751
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+
752777 it ( 'fails when at least one item is invalid' , async ( ) => {
753778 const errorMsg = 'Condition must be a string or an instance of DataQueryBuilder.'
754779
You can’t perform that action at this time.
0 commit comments