Skip to content

Commit ae792fb

Browse files
committed
Merge pull request #54 from teamsnap/member-stat-persistence
Member Statistics persistence fix
2 parents 661d626 + 1e5f1d5 commit ae792fb

File tree

5 files changed

+55
-9
lines changed

5 files changed

+55
-9
lines changed

lib/teamsnap.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3116,6 +3116,10 @@ ScopedCollection = (function(superClass) {
31163116
return this.commands.exec(this._request, commandName, params, callback);
31173117
};
31183118

3119+
ScopedCollection.prototype.file = function(commandName, params, progress, callback) {
3120+
return this.commands.fileExec(this._request, commandName, params, progress, callback);
3121+
};
3122+
31193123
return ScopedCollection;
31203124

31213125
})(Collection);
@@ -3369,6 +3373,29 @@ MetaList = (function() {
33693373
return this._request(request, 'post', rel, params, 'items').callback(callback);
33703374
};
33713375

3376+
MetaList.prototype.fileExec = function(request, rel, params, progress, callback) {
3377+
var progressEvent, progressHook;
3378+
if (typeof params === 'function') {
3379+
callback = progressEvent;
3380+
progressEvent = params;
3381+
params = void 0;
3382+
}
3383+
progressHook = function(xhr, data) {
3384+
if (data instanceof FormData) {
3385+
return xhr.upload.addEventListener('progress', function(e) {
3386+
if (e.lengthComputable) {
3387+
return progress({
3388+
loaded: e.loaded,
3389+
total: e.total
3390+
});
3391+
}
3392+
});
3393+
}
3394+
};
3395+
request.hook(progressHook);
3396+
return this._request(request, 'post', rel, params, 'items').callback(callback);
3397+
};
3398+
33723399
MetaList.prototype.cloneEmpty = function() {
33733400
var clone, entry, rel;
33743401
clone = new MetaList();
@@ -3838,6 +3865,18 @@ modifySDK = function(sdk) {
38383865
}).callback(callback);
38393866
};
38403867
});
3868+
wrapSave(sdk, 'bulkSaveStatisticData', function(templates) {
3869+
if ((templates[0] != null) && (templates[0].memberId != null)) {
3870+
return sdk.loadMemberStatistics({
3871+
memberId: templates[0].memberId
3872+
});
3873+
}
3874+
});
3875+
wrapSave(sdk, 'saveStatisticDatum', function(statisticDatum) {
3876+
return sdk.loadMemberStatistics({
3877+
statisticId: statisticDatum.statisticId
3878+
});
3879+
});
38413880
wrapMethod(sdk, 'bulkDeleteStatisticData', function(bulkDeleteStatisticData) {
38423881
return function(member, event, callback) {
38433882
var ref1, toRemove;
@@ -4942,7 +4981,7 @@ ref = require('./model'), Collection = ref.Collection, Item = ref.Item;
49424981
require('./errors');
49434982

49444983
TeamSnap = (function() {
4945-
TeamSnap.prototype.version = '1.5.1';
4984+
TeamSnap.prototype.version = '1.6.0';
49464985

49474986
TeamSnap.prototype.promises = promises;
49484987

lib/teamsnap.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "teamsnap.js",
3-
"version": "1.5.1",
3+
"version": "1.6.0",
44
"description": "A JavaScript library for using the TeamSnap API.",
55
"author": "Jacob Wright with TeamSnap (http://www.teamsnap.com)",
66
"homepage": "https://github.com/teamsnap/teamsnap-javascript-sdk",

src/persistence.coffee

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,14 @@ modifySDK = (sdk) ->
324324
linking.linkItems toRemove, lookup
325325
err
326326
).callback callback
327-
327+
328+
# Update member statistics when saving statisticData
329+
wrapSave sdk, 'bulkSaveStatisticData', (templates) ->
330+
if templates[0]? and templates[0].memberId?
331+
sdk.loadMemberStatistics memberId: templates[0].memberId
332+
333+
wrapSave sdk, 'saveStatisticDatum', (statisticDatum) ->
334+
sdk.loadMemberStatistics statisticId: statisticDatum.statisticId
328335

329336
# Remove deleted member statisticData when using bulk delete command
330337
wrapMethod sdk, 'bulkDeleteStatisticData', (bulkDeleteStatisticData) ->
@@ -349,7 +356,7 @@ modifySDK = (sdk) ->
349356
sdk.loadTeamFees(id: memberPayment.teamFeeId)
350357
).then -> result
351358
).callback callback
352-
359+
353360

354361
# Update memberBalances when saving teamFee
355362
wrapMethod sdk, 'saveTeamFee', (saveTeamFee) ->
@@ -358,7 +365,7 @@ modifySDK = (sdk) ->
358365
sdk.loadMemberBalances(teamId: teamFee.teamId).then ->
359366
result
360367
).callback callback
361-
368+
362369

363370
# Update memberBalances when deleting teamFee
364371
wrapMethod sdk, 'deleteTeamFee', (deleteTeamFee) ->

src/teamsnap.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ promises = require './promises'
33
require './errors'
44

55
class TeamSnap
6-
version: '1.5.1'
6+
version: '1.6.0'
77
promises: promises
88
when: promises.when
99
TeamSnap: TeamSnap
@@ -12,7 +12,7 @@ class TeamSnap
1212

1313
constructor: (@apiUrl = 'https://apiv3.teamsnap.com',
1414
@authUrl = 'https://auth.teamsnap.com') ->
15-
15+
1616

1717

1818
module.exports = new TeamSnap()

0 commit comments

Comments
 (0)