0

我正在使用 reactjs,我的数据库是 firebase。

我正在尝试发送一个群组的邀请。传递给函数的变量是组的 id (groupID)、组的名称 (groupName)(不用于检查但传递给邀请函数)以及被邀请者的电子邮件地址 (invite)。它检查邀请是否已经存在,如果不存在,它会调用邀请代码,如果不存在,它只会发送一个警报,说明用户已经有一个邀请。这是我的检查代码:

await props.firestore
              .collection("invites")
              .where("groupID", "==", groupID)
              .where("invitee", "==", invite)
              .get()
              .then(async (invitation) => {
                if (invitation.exists) {
                  alert("User already has invite");
                } else {
                  // Send Invite!
                  await props.firestore
                    .collection("invites")
                    .add({})
                    .then(async (ref) => {
                      SendInvite(invite,groupID,groupName);
                      alert("INVITE SENT");
                    });
                }
              });

问题是它实际上并没有抓住任何东西并且总是发送邀请。这是我的数据库的设置方式:在此处输入图像描述

4

1 回答 1

1

有 2 个问题阻止它工作。

首先,变量“invite”似乎是一个字符串,并且表现得像一个字符串,但是与数据库中的内容相比,它会返回一个错误。因此,我不得不修改它以""+invite将其转换为字符串。我不确定为什么它不是一开始的字符串。

其次,应该是“.empty”,而不是“.exist”。这些是最终的变化:

.collection("invites")
              .where("invitee", "==", "" + invite)
              .where("groupID", "==", "" + groupID)
              .get()
              .then(async (inviteData) => {
                if (inviteData.empty) {
于 2020-06-23T20:13:11.003 回答