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

Jesse Houchins Mike Frey
Jesse Houchins
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] || {})
Jesse Houchins Collaborator

should data ever be allowed to be undefined or null?

Mike Frey Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Mike Frey mikefrey commented on the diff
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])
Mike Frey Collaborator

:+1:

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

Looks good to me. Merging and will publish shortly.

Mike Frey mikefrey merged commit 9d2c6b0 into from
Mike Frey 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. Jesse Houchins
  2. Jesse Houchins

    don't wrap delete

    jessehouchins authored
Commits on Apr 11, 2013
  1. Jesse Houchins
This page is out of date. Refresh to see the latest.
8 src/modelbase.js
View
@@ -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])
Mike Frey 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)
}
10 src/sports/flight.js
View
@@ -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,
6 src/sports/flightStage.js
View
@@ -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
}
}, {
2  src/sports/pool.js
View
@@ -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) {
4 src/sports/subseason.js
View
@@ -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) {
4 src/sports/tournament.js
View
@@ -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) {
4 src/users/group.js
View
@@ -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.