Reputation: 884
I am not familiar with Javascript or Cloud Code and only began using CC yesterday. This seems like an extremely simple task, but I am banging my head trying to figure this out.
When a 'Chat' object is saved to parse, I want to increment the 'numberOfMessages' (of type Number) field of a 'ChatRooms' object, where ChatRooms.objectId = Chat.RoomId
Easy. I've tried many many things, here is the latest which is straight from the Parse Docs.
Parse.Cloud.beforeSave("Chat", function(request, response) {
query = new Parse.Query("ChatRooms");
query.get(request.object.get("roomId"), {
success: function(post) {
post.increment("numberOfMessages", 1);
post.save();
response.success();
},
error: function(error) {
console.error("Got an error " + error.code + " : " + error.message);
response.error();
}
});
});
In this example, there error is:
ReferenceError: response is not defined
at query.get.success (main.js:7:33)
at Parse.js:2:7706
at e (Parse.js:2:6486)
at Parse.js:2:5935
at Array.forEach (native)
at Object.x.each.x.forEach [as _arrayEach] (Parse.js:1:664)
at c.extend.resolve (Parse.js:2:5886)
at e (Parse.js:2:6621)
at Parse.js:2:5935
at Array.forEach (native) (Code: 141, Version: 1.5.0)
Any pointers are appreciated.
And finally.. are there any good resources for learning Javascript as it relates to Parse Cloud Code? My search didn't turn up anything useful. Thanks!
Upvotes: 1
Views: 1231
Reputation: 6832
Replace
request.object.get("roomId").id
with
request.object.get("roomId")
since roomId
is a string rather than a Room object.
Update: Also, add response.success()
to the success handler and response.error()
to the error handler to let Parse.com know you're done.
Upvotes: 2