thank you for ur response.
yes i have is this wrong to do like this, if it is how should i do it?
thanks in advance
what im trying to achive is,
- i have table Notification with to(Pointer to User) and from(Pointer to User).
- i have Follow table with user(Pointer to User) and follows(Pointer to User).
- User table with followers count and following count
I’m trying to add row to Follow Table using code and it adds properly but after executing beforeSave it send verification email to use and sets email veririfed false.
QueryBuilder<ParseUser> follows =
QueryBuilder<ParseUser>(ParseUser.forQuery());
follows.whereEqualTo("username", "jathin");
var res = await follows.query();
if (res.success) {
ParseUser? user = await ParseUser.currentUser();
inspect(user);
ParseObject followsave = new ParseObject("Follow");
followsave.set("user", user);
followsave.set("follows", res.result[0]);
followsave.set("status", "following");
var result = await followsave.save();
inspect(result);
}
then when i save this i trying to create notification and increment followers and following count respectively using cloud code function below:
PROBLEM: every time i try to add row follow table then follows user that is ‘jathin’ in this case he is getting verification mail and his email verified is set to false
Im total new to parse im coming from Firebase please help.
Parse.Cloud.beforeSave("Follow", async (request) => {
const status = request.object.get("status");
var followsname = "";
var _username = "";
if (!request.original) {
if (status == "following") {
const following = new Parse.Query(Parse.User);
following.get(request.object.get("user").id)
.then(function (user) {
const jsondata = JSON.stringify(user);
const userjson = JSON.parse(jsondata);
user.increment("following");
_username = userjson.username;
console.log(_username);
user.save(null, { useMasterKey: true });
})
.catch(function (error) {
console.error("Got an error in following" + error.code + " : " + error.message);
});
const follower = new Parse.Query(Parse.User);
await follower.get(request.object.get("follows").id)
.then(function (user) {
const jsondata = JSON.stringify(user);
const userjson = JSON.parse(jsondata);
user.increment("followers");
followsname = userjson.username;
//return was here
user.save(null, { useMasterKey: true });
})
.catch(function (error) {
console.error("Got an error in follows save" + error.code + " : " + error.message);
});
const notification = new Parse.Object("Notification");
notification.set("from", request.object.get("user"));
notification.set("to", request.object.get("follows"));
notification.set("type", "following");
notification.set("priority", 1);
notification.set("read", false);
notification.set("data", _username + " started following you.");
try {
const result = await notification.save(null, { useMasterKey: true });
console.log('Notification created', result);
request.object.set("notification", notification);
} catch (error) {
console.error('Error while creating Notification: ', error);
}
} else if (status == "requested") {
const follower = new Parse.Query(Parse.User);
await follower.get(request.object.get("user").id)
.then(function (user) {
const jsondata = JSON.stringify(user);
const userjson = JSON.parse(jsondata);
_username = userjson.username;
})
.catch(function (error) {
console.error("Got an error in follows save" + error.code + " : " + error.message);
});
const notification = new Parse.Object("Notification");
notification.set("from", request.object.get("user"));
notification.set("to", request.object.get("follows"));
notification.set("type", "request");
notification.set("priority", 1);
notification.set("read", false);
notification.set("data", _username + " has requested to following you.");
try {
const result = await notification.save(null, { useMasterKey: true });
// Access the Parse Object attributes using the .GET method
console.log('Notification created', result);
request.object.set("notification", notification);
} catch (error) {
console.error('Error while creating Notification: ', error);
}
}
} else {
if (request.original.get("status") == "requested" && request.object.get("status") == "following") {
const following = new Parse.Query(Parse.User);
following.get(request.object.get("user").id)
.then(function (user) {
user.increment("following");
//return was here
user.save();
})
.catch(function (error) {
console.error("Got an error " + error.code + " : " + error.message);
});
const follower = new Parse.Query(Parse.User);
follower.get(request.object.get("follows").id)
.then(function (user) {
user.increment("followers");
//return was here
user.save();
})
.catch(function (error) {
console.error("Got an error " + error.code + " : " + error.message);
});
const notification_user = new Parse.Object("Notification");
notification_user.set("to", request.object.get("user"));
notification_user.set("from", request.object.get("follows"));
notification_user.set("type", "request");
notification_user.set("priority", 1);
notification_user.set("read", false);
notification_user.set("data", request.object.get("follows").username + " has accepted following request.");
try {
const result = await notification_user.save(null, { useMasterKey: true });
// Access the Parse Object attributes using the .GET method
console.log('Notification created', result);
} catch (error) {
console.error('Error while creating Notification: ', error);
}
const notification_follower = new Parse.Object("Notification");
notification_follower.set("from", request.object.get("user"));
notification_follower.set("to", request.object.get("follows"));
notification_follower.set("type", "request");
notification_follower.set("priority", 1);
notification_follower.set("read", false);
notification_follower.set("data", request.object.get("user").username + " has started following you.");
try {
const result = await notification_follower.save(null, { useMasterKey: true });
// Access the Parse Object attributes using the .GET method
console.log('Notification created', result);
} catch (error) {
console.error('Error while creating Notification: ', error);
}
}
}
}
);
is my method to save followers wrong? what im doing wrong