Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

wrap unorthodox sync calls to run through parse #72

Merged
merged 3 commits into from

2 participants

@jessehouchins
Collaborator

No description provided.

src/modelbase.js
@@ -71,6 +71,14 @@ module.exports = function(ngin) {
return attributes
},
+ callbackWithParse: function(callback) {
+ return function(err, data) {
+ var args = _.toArray(arguments)
+ args[1] = this.parse(args[1] || {})
@jessehouchins Collaborator

should data ever be allowed to be undefined or null?

@mikefrey Collaborator

Good point. Maybe we should change this to args[1] = this.parse(args[1] || null)

@mikefrey Collaborator

:+1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mikefrey
Collaborator

Looks good to me. Merging and will publish shortly.

@mikefrey mikefrey merged commit 9d2c6b0 into from
@mikefrey mikefrey deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 8, 2013
  1. @jessehouchins
  2. @jessehouchins

    don't wrap delete

    jessehouchins authored
Commits on Apr 11, 2013
  1. @jessehouchins
This page is out of date. Refresh to see the latest.
View
8 src/modelbase.js
@@ -71,6 +71,14 @@ module.exports = function(ngin) {
return attributes
},
+ callbackWithParse: function(callback) {
+ return function(err, data) {
+ var args = _.toArray(arguments)
+ if (args[1]) args[1] = this.parse(args[1])
@mikefrey Collaborator

:+1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ callback.apply(this, args)
+ }.bind(this)
+ },
+
sync: function(method, options, callback) {
return sync(method, this, options, callback)
}
View
10 src/sports/flight.js
@@ -34,7 +34,7 @@ module.exports = function(ngin) {
addTeam: function(teamID, callback) {
var url = Flight.urlRoot() + '/' + this.id + '/add_team/' + teamID
- return Flight.sync('update', null, { url:url }, callback)
+ return Flight.sync('update', null, { url:url }, this.callbackWithParse(callback))
},
removeTeam: function(teamID, callback) {
@@ -44,12 +44,12 @@ module.exports = function(ngin) {
addToWaitlist: function(teamID, callback) {
var url = Flight.urlRoot() + '/' + this.id + '/add_to_waitlist/' + teamID
- return Flight.sync('update', null, { url:url }, callback)
+ return Flight.sync('update', null, { url:url }, this.callbackWithParse(callback))
},
removeFromWaitlist: function(teamID, callback) {
var url = Flight.urlRoot() + '/' + this.id + '/remove_from_waitlist/' + teamID
- return Flight.sync('update', null, { url:url }, callback)
+ return Flight.sync('update', null, { url:url }, this.callbackWithParse(callback))
},
stages: function(callback){
@@ -58,7 +58,7 @@ module.exports = function(ngin) {
createSchedule: function(callback) {
var url = Flight.tournamentUrlRoot() + '?flight_id=' + this.id
- return Flight.sync('create', null, { url:url }, callback)
+ return Flight.sync('create', null, { url:url }, this.callbackWithParse(callback))
},
schedule: function(callback) {
@@ -68,7 +68,7 @@ module.exports = function(ngin) {
publish: function(callback) {
var url = Flight.tournamentUrlRoot() + '/publish?flight_id=' + this.id
// semantically this is an update (PUT), but must technically be a POST
- return ngin.GameSlot.sync('update', null, { url:url, method:'POST' }, callback)
+ return ngin.GameSlot.sync('update', null, { url:url, method:'POST' }, this.callbackWithParse(callback))
},
// Commenting this out for now. It may be needed later, however,
View
6 src/sports/flightStage.js
@@ -54,7 +54,7 @@ module.exports = function(ngin) {
addTeam: function(teamID, callback) {
var url = scopeUrl({}, this) + '/' + this.id + '/add_team/' + teamID
- return FlightStage.sync('update', null, { url:url }, callback)
+ return FlightStage.sync('update', null, { url:url }, this.callbackWithParse(callback))
},
removeTeam: function(teamID, callback) {
@@ -72,12 +72,12 @@ module.exports = function(ngin) {
teams_advancing: function(callback) {
var url = scopeUrl({}, this) + '/' + this.id + '/teams_advancing'
- return FlightStage.sync('fetch', null, { url:url }, callback)
+ return FlightStage.sync('fetch', null, { url:url }, this.callbackWithParse(callback))
},
advance_teams: function(callback) {
var url = scopeUrl({}, this) + '/' + this.id + '/teams_advancing'
- return FlightStage.sync('create', { teams:this.teams }, { url:url }, callback) // Stat Ngin expects a POST
+ return FlightStage.sync('create', { teams:this.teams }, { url:url }, this.callbackWithParse(callback)) // Stat Ngin expects a POST
}
}, {
View
2  src/sports/pool.js
@@ -34,7 +34,7 @@ module.exports = function(ngin) {
addTeam: function(teamId, callback) {
var url = Pool.urlRoot() + '/' + this.id + '/add_team/' + teamId
- return Pool.sync('update', null, { url:url }, callback)
+ return Pool.sync('update', null, { url:url }, this.callbackWithParse(callback))
},
removeTeam: function(teamId, callback) {
View
4 src/sports/subseason.js
@@ -34,7 +34,7 @@ module.exports = function(ngin) {
addTeam: function(teamId, callback) {
var url = Subseason.urlRoot() + '/' + this.id + '/add_team/' + teamId
- return Subseason.sync('update', null, { url:url }, callback)
+ return Subseason.sync('update', null, { url:url }, this.callbackWithParse(callback))
},
removeTeam: function(teamId, callback) {
@@ -44,7 +44,7 @@ module.exports = function(ngin) {
addDivision: function(divisionId, callback) {
var url = Subseason.urlRoot() + '/' + this.id + '/add_division/' + divisionId
- return Subseason.sync('update', null, { url:url }, callback)
+ return Subseason.sync('update', null, { url:url }, this.callbackWithParse(callback))
},
removeDivision: function(divisionId, callback) {
View
4 src/sports/tournament.js
@@ -43,7 +43,7 @@ module.exports = function(ngin) {
addTeam: function(teamID, callback) {
var url = Tournament.urlRoot() + '/' + this.id + '/add_team/' + teamID
- return Tournament.sync('update', null, { url:url }, callback)
+ return Tournament.sync('update', null, { url:url }, this.callbackWithParse(callback))
},
removeTeam: function(teamID, callback) {
@@ -61,7 +61,7 @@ module.exports = function(ngin) {
addPlayer: function(playerID, callback) {
var url = Tournament.urlRoot() + '/' + this.id + '/add_player/' + playerID
- return Tournament.sync('update', null, { url:url }, callback)
+ return Tournament.sync('update', null, { url:url }, this.callbackWithParse(callback))
},
removePlayer: function(playerID, callback) {
View
4 src/users/group.js
@@ -44,12 +44,12 @@ module.exports = function(ngin) {
addPersona: function(personId, callback) {
var url = Group.urlRoot() + '/' + this.id + '/add_persona/' + personId
- return Group.sync('update', null, { url:url }, callback)
+ return Group.sync('update', null, { url:url }, this.callbackWithParse(callback))
},
removePersona: function(personId, callback) {
var url = Group.urlRoot() + '/' + this.id + '/remove_persona/' + personId
- return Group.sync('update', null, { url:url }, callback)
+ return Group.sync('update', null, { url:url }, this.callbackWithParse(callback))
}
}, {
Something went wrong with that request. Please try again.