Skip to content

Commit ed8c5d3

Browse files
committed
feat(leaderboard): #getArchives
1 parent 528c15d commit ed8c5d3

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

src/leaderboard.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ AV.LeaderboardUpdateStrategy = {
4545
* @property {Statistic[]} [includedStatistics] Other statistics of the user, specified by the `includeStatistic` option of `AV.Leaderboard.getResults()`
4646
*/
4747

48+
/**
49+
* @typedef {Object} LeaderboardArchive
50+
* @property {string} statisticName
51+
* @property {number} version version of the leaderboard
52+
* @property {string} status
53+
* @property {string} url URL for the downloadable archive
54+
* @property {Date} activatedAt time when this version became active
55+
* @property {Date} deactivatedAt time when this version was deactivated by a version incrementing
56+
*/
57+
4858
/**
4959
* @class
5060
*/
@@ -358,5 +368,33 @@ _.extend(
358368
authOptions,
359369
}).then(() => undefined);
360370
},
371+
/**
372+
* (masterKey required) Get archived versions.
373+
* @param {Object} [options]
374+
* @param {number} [options.skip] The number of results to skip. This is useful for pagination.
375+
* @param {number} [options.limit] The limit of the number of results.
376+
* @param {AuthOptions} [authOptions]
377+
* @return {Promise<LeaderboardArchive[]>}
378+
*/
379+
getArchives({ skip, limit } = {}, authOptions) {
380+
return request({
381+
method: 'GET',
382+
path: `/leaderboard/leaderboards/${this.statisticName}/archives`,
383+
query: {
384+
skip,
385+
limit,
386+
},
387+
authOptions,
388+
}).then(({ results }) =>
389+
results.map(({ version, status, url, activatedAt, deactivatedAt }) => ({
390+
statisticName: this.statisticName,
391+
version,
392+
status,
393+
url,
394+
activatedAt: parseDate(activatedAt.iso),
395+
deactivatedAt: parseDate(deactivatedAt.iso),
396+
}))
397+
);
398+
},
361399
}
362400
);

storage.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,15 @@ declare interface UpdateStatisticsOptions extends AuthOptions {
844844
overwrite?: boolean;
845845
}
846846

847+
declare interface LeaderboardArchive {
848+
statisticName: string;
849+
version: number;
850+
status: string;
851+
url: string;
852+
activatedAt: Date;
853+
deactivatedAt: Date;
854+
}
855+
847856
export class Leaderboard {
848857
statisticName: string;
849858
order?: LeaderboardOrder;
@@ -907,6 +916,13 @@ export class Leaderboard {
907916
): Promise<Leaderboard>;
908917
reset(authOptions?: AuthOptions): Promise<Leaderboard>;
909918
destroy(authOptions?: AuthOptions): Promise<void>;
919+
getArchives(
920+
options?: {
921+
skip?: number;
922+
limit?: number;
923+
},
924+
authOptions?: AuthOptions
925+
): Promise<LeaderboardArchive>;
910926
}
911927

912928
export enum LeaderboardOrder {

test/leaderboard.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ describe('Leaderboard', () => {
8080
);
8181
});
8282
});
83+
it('getArchives', function() {
84+
return this.leaderboard.getArchives(undefined, {
85+
useMasterKey: true,
86+
});
87+
});
8388

8489
describe('Statistics', function() {
8590
let users;

0 commit comments

Comments
 (0)