Skip to content

Commit a4a4c6a

Browse files
committed
feat(leabderboard): Leaderboard#count()
close #560
1 parent f79d22c commit a4a4c6a

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/leaderboard.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,25 @@ _.extend(
259259
authOptions,
260260
}).then(data => this._finishFetch(data));
261261
},
262+
/**
263+
* Counts the number of users participated in this leaderboard
264+
* @param {Object} [options]
265+
* @param {number} [options.version] Specify the version of the leaderboard
266+
* @param {AuthOptions} [authOptions]
267+
* @return {Promise<number>}
268+
*/
269+
count({ version } = {}, authOptions) {
270+
return request({
271+
method: 'GET',
272+
path: `/leaderboard/leaderboards/${this.statisticName}/ranks`,
273+
query: {
274+
count: 1,
275+
limit: 0,
276+
version,
277+
},
278+
authOptions,
279+
}).then(({ count }) => count);
280+
},
262281
_getResults(
263282
{ skip, limit, selectUserKeys, includeStatistics, version },
264283
authOptions,

storage.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,12 @@ export class Leaderboard {
931931
): Promise<void>;
932932

933933
fetch(authOptions?: AuthOptions): Promise<Leaderboard>;
934+
count(
935+
options?: {
936+
version?: number;
937+
},
938+
authOptions?: AuthOptions
939+
): Promise<Number>;
934940
getResults(
935941
options?: {
936942
skip?: number;

test/leaderboard.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ describe('Leaderboard', () => {
143143
score.version.should.eql(0);
144144
}));
145145

146+
it('count', function() {
147+
return this.leaderboard.count().then(count => count.should.be.eql(4));
148+
});
149+
146150
it('getResults', function() {
147151
const leaderboard = this.leaderboard;
148152
return leaderboard

0 commit comments

Comments
 (0)