parse.com - iOS + Parse Cloud Code - updating a specific user (not logged in user) -
i trying update user (which not current user). figured have use cloud code make update.
i have created cloud function below update selected user. trying add meetingid's array property belongs user class.
cloud code:
parse.cloud.define('updateuser', function(request, response) { var userid = request.params.userid, meetingid = request.params.meetingid; var user = parse.object.extend('_user'), user = new user({ objectid: userid }); user.addunique("meetingsarray", meetingid) user.save(null, {usermasterkey:true}).then(function(user) { response.success(user); }, function(error) { response.error(error) }); });
objective-c //meetingid - obtained meeting object.
[pfcloud callfunctioninbackground:@"updateuser" withparameters:@{@"objectid":user.objectid, @"meetingsarray":meetingid} block:^(nsstring *result, nserror *error) { if (!error) { nslog(@"%@",result); }else if(error){ nslog(@"%@", error); } }];
when run app - following error code:
error domain=parse code=141 "the operation couldn’t completed. (parse error 141.)" userinfo=0x1704f2780 {code=141, temporary=0, error={"code":201,"message":"missing user password"}, originalerror=error domain=nsurlerrordomain code=-1011 "the operation couldn’t completed. (nsurlerrordomain error -1011.)"}
i'm new cloud code - want update array belongs selected user , add meetingid it. appreciate it.
there few problems code prevent working:
the cloud code expects meeting id parameter named
@"meetingid"
, change parameters passed@{@"objectid":user.objectid, @"meetingid":meetingid}
use
parse.user
, not'_user'
extend user.get - don't build - user being updated
summing up...
parse.cloud.define('updateuser', function(request, response) { var userid = request.params.userid; var meetingid = request.params.meetingid; var query = new parse.query(parse.user); query.get(userid).then(function(user) { user.addunique("meetingsarray", meetingid); return user.save(null, {usemasterkey:true}); }).then(function(user) { response.success(user); }, function(error) { response.error(error); }); });
Comments
Post a Comment