问题描述
我想要实现的是,
我正在尝试向关注表添加行 使用代码并正确添加但在执行之前保存它 发送验证电子邮件以使用并将电子邮件验证设置为 false。
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;
//return was here
})
.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");
notification.set("priority",_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',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,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,error);
}
}
}
}
);
然后当我保存这个时,我尝试创建通知并分别增加关注者和关注者计数 使用下面的云代码功能:
问题:每次我尝试添加行关注表时,都会关注“jathin”用户,在这种情况下,他会收到验证邮件 并且他的已验证电子邮件设置为 false
我是解析来自 Firebase 的即时消息的新手,请帮忙。
{{1}}
我拯救粉丝的方法错了吗? 我做错了什么
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)