In a beforeSave
hook I want to obtain the state of the object prior to the update. In this particular case it is to stop a user from changing their choice once they have made it. Pseudo-code looks something like:
If (user has already voted) {
deny;
} else {
accept;
}
And the code that I have so far is:
Parse.Cloud.beforeSave('votes', function(request, response) {
if (!request.object.isNew()) {
// This is an update. See if the user already voted
if (request.object.get('choice') !== null) {
response.error('Not allowed to change your choice once submitted');
}
}
response.success();
}
But request.object
is the state of the object with the update already applied.
Note that the 'votes' object is created separately so this isn't allowing an insert but not an update will not suffice; I need to know if a given field is already set in the database.