Skip to content

Instantly share code, notes, and snippets.

@alyssoncm
Created November 17, 2020 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alyssoncm/01265a5cf4f5646286dd4694027cac10 to your computer and use it in GitHub Desktop.
Save alyssoncm/01265a5cf4f5646286dd4694027cac10 to your computer and use it in GitHub Desktop.
Parse.Cloud.afterLiveQueryEvent('DogObject', async (request) => {
if (request.event == "Create") {
// If I am creating a new Dog
const thisDog = request.object;
thisDog.set('name', 'Fido'); // Set its name to Fido
} else if (request.event == "update") {
// Else, if I am Updating an existing Dog
const thisDog = request.object;
thisDog.set('name', 'Rex'); // Set its name to Rex
} else {
// Otherwise, do nothing
return;
}
});
@dblythy
Copy link

dblythy commented Nov 24, 2020

} else if (request.event == "update") {

Related to this issue in the Parse Server repo, at the moment, request.event needs to contain a capitalized first letter. So this should be request.event == 'Update'.

   // Otherwise, do nothing
   return;

These lines here will do nothing, unless there is more below obviously, but it won't prevent the event from firing. If your intention is to do nothing on the client side too by preventing the event from firing, you can use:

    } else {
        // Otherwise, do nothing
        request.sendEvent = false;
        return;
    }

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