var Post = Parse.Object.extend(‘Post’, {
backThePost: function() {
var defered = $q.defer()
if (!this.alreadyResponded() && this.status === ‘published’) {
this.addUnique(‘backers’, Parse.User.current())
} else {
this.remove(‘backers’, Parse.User.current())
}
this.save().then(function(_result) {
defered.resolve(_result)
}, function(error) {
defered.reject(error)
})
return defered.promise
},
alreadyResponded: function() {
return !!this.backers && .contains(.pluck(this.get(‘backers’), ‘id’), Parse.User.current().id)
},
updateStatus: function(status) {
var _this = this
return Parse.Cloud.run(‘updateStatus’, {objectId: this.id, objectType: ‘Post’, objectStatus: status})
}
}
Sumanta,
Rewriting your Parse code is outside of what free support covers.
Please use the documentation which provides plenty of sample code.
Mark