Skip to content

Commit 231a9ba

Browse files
committed
feat(leaderboard): add AV.Leaderboard.deleteStatistics
1 parent 518fb90 commit 231a9ba

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/leaderboard.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ AV.Leaderboard.getStatistics = (user, { statisticNames } = {}, authOptions) =>
180180
authOptions,
181181
}).then(({ results }) => results.map(parseStatisticData));
182182
});
183+
183184
/**
184185
* Update Statistics for the specified user.
185186
* @param {AV.User} user The specified AV.User pointer.
@@ -207,6 +208,26 @@ AV.Leaderboard.updateStatistics = (user, statistics, options = {}) =>
207208
}).then(({ results }) => results.map(parseStatisticData));
208209
});
209210

211+
/**
212+
* Delete Statistics for the specified user.
213+
* @param {AV.User} user The specified AV.User pointer.
214+
* @param {Object} statistics A name-value pair representing the statistics to delete.
215+
* @param {AuthOptions} [options]
216+
* @return {Promise<void>}
217+
*/
218+
AV.Leaderboard.deleteStatistics = (user, statisticNames, authOptions) =>
219+
Promise.resolve().then(() => {
220+
if (!(user && user.id)) throw new Error('user must be an AV.User');
221+
return request({
222+
method: 'DELETE',
223+
path: `/leaderboard/users/${user.id}/statistics`,
224+
query: {
225+
statistics: ensureArray(statisticNames).join(','),
226+
},
227+
authOptions,
228+
}).then(() => undefined);
229+
});
230+
210231
_.extend(
211232
Leaderboard.prototype,
212233
/** @lends AV.Leaderboard.prototype */ {

storage.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,11 @@ export class Leaderboard {
888888
statistics: { [name: string]: number },
889889
options?: UpdateStatisticsOptions
890890
): Promise<Statistic[]>;
891+
static deleteStatistics(
892+
user: User,
893+
statisticNames: string[],
894+
authOptions?: AuthOptions
895+
): Promise<void>;
891896

892897
fetch(authOptions?: AuthOptions): Promise<Leaderboard>;
893898
getResults(

test/leaderboard.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ describe('Leaderboard', () => {
196196
rankings.map(ranking => ranking.rank).should.eql([0, 1, 2]);
197197
});
198198
});
199+
it('delete statistics', function() {
200+
const leaderboard = this.leaderboard;
201+
return AV.Leaderboard.deleteStatistics(currentUser, statisticName, {
202+
user: currentUser,
203+
})
204+
.then(() => leaderboard.getResults())
205+
.then(rankings => rankings.should.be.length(3));
206+
});
199207
});
200208

201209
after(function() {

0 commit comments

Comments
 (0)