Skip to content

Commit d72b826

Browse files
Update countEntityTotal function following review
1 parent 43cf418 commit d72b826

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

README.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,39 @@ const client = new SlicingDice({
320320
readKey: 'READ_KEY'
321321
}, usesTestEndpoint = true);
322322

323-
const tables = {
324-
"tables": [
325-
"default"
326-
]
327-
};
323+
client.countEntityTotal().then((resp) => {
324+
console.log(resp);
325+
}, (err) => {
326+
console.error(err);
327+
});
328+
```
329+
330+
#### Output example
331+
332+
```json
333+
{
334+
"status": "success",
335+
"result": {
336+
"total": 42
337+
},
338+
"took": 0.103
339+
}
340+
```
341+
342+
### `countEntityTotal(tables)`
343+
Count the total number of inserted entities in the given tables. This method corresponds to a [POST request at /query/count/entity/total](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-query-count-entity-total).
344+
345+
#### Request example
346+
347+
```javascript
348+
let SlicingDice = require('slicerjs');
349+
350+
const client = new SlicingDice({
351+
masterKey: 'MASTER_KEY',
352+
readKey: 'READ_KEY'
353+
}, usesTestEndpoint = true);
354+
355+
const tables = ["default"];
328356

329357
client.countEntityTotal(tables).then((resp) => {
330358
console.log(resp);

src/slicer.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -556,15 +556,15 @@
556556
*
557557
* @param (array) tables - the tables in which the total query will be performed
558558
*/
559-
countEntityTotal(tables = {}) {
560-
if(!tables){
561-
tables = {};
562-
}
559+
countEntityTotal(tables = []) {
560+
let query = {
561+
"tables": tables
562+
};
563563
let path = this._sdRoutes.countEntityTotal;
564564
return this.makeRequest({
565565
path: path,
566566
reqType: "POST",
567-
data: tables,
567+
data: query,
568568
levelKey: 0
569569
})
570570
}

0 commit comments

Comments
 (0)