Skip to content

Commit 3c38bf5

Browse files
BKNDLSS-31260 getObjectsCount is ignoring groupBy option (#236)
1 parent 47942cd commit 3c38bf5

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/data/store.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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

test/unit/specs/data/find.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)