【发布时间】:2020-03-23 23:36:51
【问题描述】:
我正在为我的单身汉制作约会应用程序,类似于 tinder。我现在正在创建匹配系统。
我创建了 onCreate 监听器来检查用户何时按下like 按钮并检查其他用户是否已经按下了当前用户的like。所以这就是我尝试过的。
exports.UserPressesLike = functions.database
.ref('/users/{userId}/matches/{otherUserId}')
.onCreate((snapshot, context) => {
// Grab the current value of what was written to the Realtime Database.
const original = snapshot.val();
const userId = context.params.userId;
const matchedUserId = context.params.otherUserId;
const a = checkUserMatch(userId, matchedUserId);
if (a === true) {
console.log('Its a match');
} else {
console.log('There is no match');
console.log(a);
}
return null;
});
checkUserMatch = async (userId, matchedUserId) => {
const snapshot = await admin
.database()
.ref('/users/' + matchedUserId + '/matches/' + userId)
.once('value')
.then(snapshot => {
// let tempuserId = snapshot.val();
// if()
return true;
});
};
如果存在该节点,我希望 checkUserMatch 返回 true,如果没有该节点,则返回 false。
【问题讨论】:
-
目前您的问题非常广泛。特别关注您遇到的问题。你试过什么?是什么不工作。
标签: javascript firebase firebase-realtime-database google-cloud-functions