Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Parse.Cloud.define("addFriendToFriendsRelation", function(request, response) {
- Parse.Cloud.useMasterKey();
- var friendRequestId = request.params.friendRequest;
- var query = new Parse.Query("FriendRequest");
- //get the friend request object
- query.get(friendRequestId, {
- success: function(friendRequest) {
- //get the user the request was from
- var fromUser = friendRequest.get("from");
- //get the user the request is to
- var toUser = friendRequest.get("to");
- var relation = fromUser.relation("friends");
- //add the user the request was to (the accepting user) to the fromUsers friends
- relation.add(toUser);
- //save the fromUser
- fromUser.save(null, {
- success: function() {
- //saved the user, now edit the request status and save it
- friendRequest.set("status", "accepted");
- friendRequest.save(null, {
- success: function() {
- response.success("saved relation and updated friendRequest");
- },
- error: function(error) {
- response.error("Error 1");
- }
- });
- },
- error: function(error) {
- response.error("Error 2");
- }
- });
- },
- error: function(error) {
- response.error("Error 3");
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement