sokel
December 19, 2021, 7:37pm
1
Cloud function; given an email address, I want to retrieve the object from Parse.User and in the same function create a new object with a pointer field?
Example:
I have a job class with pointer to User class and when I create a new job object, I have:
JobTitle:
From:( CurrentUser)
To: (this is a pointer and I need to retrieve Parse.User object by querying the given email address and once I retrieve the object, I assigned it to To)
Any help out there?
Would you mind to share what you’ve tried so far?
sokel
December 21, 2021, 4:20pm
3
Parse.Cloud.define(“createTask”, async (request) => {
let currentUser = request.user;
let toUser = new Parse.Query(Parse.User);
const taskmess = request.params.taskmess;
const usernamefrom = request.params.usernamefrom;
const usernameto = request.params.usernameto;
const taskstatus = request.params.taskstatus;
const tasklogo = request.params.tasklogo;
const actionlogo = request.params.actionlogo;
const taskdeadline = request.params.taskdeadline;
const newTask = new Parse.Object('Tasks');
toUser.equalTo("username",req.params.username);
newTask.set('TaskMessage',taskmess);
newTask.set('UserNameFrom',usernamefrom);
newTask.set('UserNameTo',usernameto);
newTask.set('userTo',toUser);
newTask.set('userFrom',currentUser)
newTask.set('TaskStatus',taskstatus);
newTask.set('TaskLogo',tasklogo);
newTask.set('ActionLogo',actionlogo);
newTask.set('TaskDeadline',taskdeadline);
try {
return await newTask.save();
} catch(error) {
console.log('Task -error' + error.code + ' ' + error.message);
}
});
Please note that userTo and userFrom are pointers
You need to fetch the user and pass the object (not the query). Something like this:
Parse.Cloud.define(“createTask”, async (request) => {
let currentUser = request.user;
let toUserQuery = new Parse.Query(Parse.User);
const taskmess = request.params.taskmess;
const usernamefrom = request.params.usernamefrom;
const usernameto = request.params.usernameto;
const taskstatus = request.params.taskstatus;
const tasklogo = request.params.tasklogo;
const actionlogo = request.params.actionlogo;
const taskdeadline = request.params.taskdeadline;
const newTask = new Parse.Object('Tasks');
toUserQuery.equalTo("username",req.params.username);
const toUser = await toUserQuery.first({ useMasterKey: true });
newTask.set('TaskMessage',taskmess);
newTask.set('UserNameFrom',usernamefrom);
newTask.set('UserNameTo',usernameto);
newTask.set('userTo',toUser);
newTask.set('userFrom',currentUser)
newTask.set('TaskStatus',taskstatus);
newTask.set('TaskLogo',tasklogo);
newTask.set('ActionLogo',actionlogo);
newTask.set('TaskDeadline',taskdeadline);
try {
return await newTask.save();
} catch(error) {
console.log('Task -error' + error.code + ' ' + error.message);
}
});