@@ -25,6 +25,11 @@ AV.LeaderboardOrder = {
2525 DESCENDING : 'descending' ,
2626} ;
2727
28+ AV . LeaderboardUpdateStrategy = {
29+ BETTER : 'better' ,
30+ LAST : 'last' ,
31+ } ;
32+
2833/**
2934 * @class
3035 */
@@ -60,6 +65,14 @@ AV.Leaderboard = function(statisticName) {
6065 * @type {string }
6166 */
6267 this . statisticName = statisticName ;
68+ /**
69+ * @type {AV.LeaderboardOrder }
70+ */
71+ this . order = undefined ;
72+ /**
73+ * @type {AV.LeaderboardUpdateStrategy }
74+ */
75+ this . updateStrategy = undefined ;
6376 /**
6477 * @type {AV.LeaderboardVersionChangeInterval }
6578 */
@@ -72,6 +85,10 @@ AV.Leaderboard = function(statisticName) {
7285 * @type {Date? }
7386 */
7487 this . nextResetAt = undefined ;
88+ /**
89+ * @type {Date? }
90+ */
91+ this . createdAt = undefined ;
7592} ;
7693const Leaderboard = AV . Leaderboard ;
7794
@@ -87,12 +104,13 @@ AV.Leaderboard.createWithoutData = statisticName =>
87104 * @param {Object } options
88105 * @param {string } options.statisticName
89106 * @param {AV.LeaderboardOrder } options.order
90- * @param {AV.LeaderboardVersionChangeInterval } options.versionChangeInterval
107+ * @param {AV.LeaderboardVersionChangeInterval } [options.versionChangeInterval] default to WEEK
108+ * @param {AV.LeaderboardUpdateStrategy } [options.updateStrategy] default to BETTER
91109 * @param {AuthOptions } [authOptions]
92110 * @return {Promise<AV.Leaderboard> }
93111 */
94112AV . Leaderboard . createLeaderboard = (
95- { statisticName, order, versionChangeInterval } ,
113+ { statisticName, order, versionChangeInterval, updateStrategy } ,
96114 authOptions
97115) =>
98116 request ( {
@@ -102,6 +120,7 @@ AV.Leaderboard.createLeaderboard = (
102120 statisticName,
103121 order,
104122 versionChangeInterval,
123+ updateStrategy,
105124 } ,
106125 authOptions,
107126 } ) . then ( data => {
@@ -185,6 +204,9 @@ _.extend(
185204 if ( key === 'expiredAt' ) {
186205 key = 'nextResetAt' ;
187206 }
207+ if ( key === 'createdAt' ) {
208+ value = parseDate ( value ) ;
209+ }
188210 if ( value . __type === 'Date' ) {
189211 value = parseDate ( value . iso ) ;
190212 }
@@ -253,21 +275,31 @@ _.extend(
253275 getResultsAroundUser ( { limit, includeUserKeys } = { } , authOptions ) {
254276 return this . _getResults ( { limit, includeUserKeys } , authOptions , true ) ;
255277 } ,
278+ _update ( data , authOptions ) {
279+ return request ( {
280+ method : 'PUT' ,
281+ path : `/play/leaderboards/${ this . statisticName } ` ,
282+ data,
283+ authOptions,
284+ } ) . then ( result => this . _finishFetch ( result ) ) ;
285+ } ,
256286 /**
257287 * (masterKey required) Update the version change interval of the Leaderboard.
258288 * @param {AV.LeaderboardVersionChangeInterval } versionChangeInterval
259289 * @param {AuthOptions } [authOptions]
260290 * @return {Promise<AV.Leaderboard> }
261291 */
262292 updateVersionChangeInterval ( versionChangeInterval , authOptions ) {
263- return request ( {
264- method : 'PUT' ,
265- path : `/play/leaderboards/${ this . statisticName } ` ,
266- data : {
267- versionChangeInterval,
268- } ,
269- authOptions,
270- } ) . then ( data => this . _finishFetch ( data ) ) ;
293+ return this . _update ( { versionChangeInterval } , authOptions ) ;
294+ } ,
295+ /**
296+ * (masterKey required) Update the version change interval of the Leaderboard.
297+ * @param {AV.LeaderboardUpdateStrategy } updateStrategy
298+ * @param {AuthOptions } [authOptions]
299+ * @return {Promise<AV.Leaderboard> }
300+ */
301+ updateUpdateStrategy ( updateStrategy , authOptions ) {
302+ return this . _update ( { updateStrategy } , authOptions ) ;
271303 } ,
272304 /**
273305 * (masterKey required) Reset the Leaderboard. The version of the Leaderboard will be incremented by 1.
0 commit comments