0

我有卡片的结构,有一个卡片的请求,它出现了属性 InterestUsers,这个属性包含一个模型数组,其中存储了各种属性,包括发送这个请求的用户 ID。

我尝试使用查询仅访问用户添加卡所有者的那些卡,因此我需要知道 isApproved 属性,但由于动态密钥,我无法做到。我还尝试获取当前用户发送请求的所有卡片,要么没有工作,要么我拥有所有卡片,要么结果是 NSNull。

请告诉我我该怎么做?

我的结构

"cards": {
   "-Khv9rUVwErNHBzXcruO": {
      "additionalInfo": {
          "note": ""
      },
      "dateProperties": {
          "day": "Flex",
          "isFlexDate": true,
          "isFlexTime": true,
          "iso8601": "",
          "time": ""
      },
      "interestedUsers": {
          "NfM26A2YcPUFz8rfYa23Kr3mjCO2": {
              "isApproved": false,
              "isNew": true,
              "isoDate": "2017-04-17T13:08:41+04:00",
              "userID": "NfM26A2YcPUFz8rfYa23Kr3mjCO2",
              "userItchableName": "Alexsander K."
          }
      },
      "isNewPendingRequest": true,
      "isPrivateStatus": false,
      "isTest": false,
      "ownerID": "1Cix149ThIOG1ULPVjyy0LyTxbe2",
      "peopleProperties": {
          "availableSeats": 1,
          "numberOfPeople": 1,
          "numberOfPeopleDescription": "1 person"
      },
      "title": "Genius Lounge and Sake Bar",
      "userName": "Tim C.",
      "version": 1
  },

我的请求的选项之一

func getUserEvents() {
    let realmManager = RealmManager()
    guard let currentUserID = realmManager.getCurrentUser()?.id else { return }
    DispatchQueue.global(qos: .background).async {
        let ref = FIRDatabase.database().reference().child(MainGateways.cards.rawValue).queryOrdered(byChild: "\(Keywords.interestedUsers.rawValue)/\(currentUserID)/\(InterestedUserKeywords.userID)").queryEqual(toValue: currentUserID) // currentuser id

        ref.observeSingleEvent(of: .value, with: { (snapshot) in
            if snapshot.value is NSNull {
                debugPrint("snapshot is nsnull")
                return
            }
            debugPrint("getUserEvents", snapshot.value ?? "")
            guard let dict = snapshot.value as? [String : [String : Any]] else { return }
            debugPrint("dict count", dict.values.count, "---")
        }, withCancel: { (error) in
            debugPrint(error.localizedDescription)
        })
    }
}

我为数据库尝试了很多规则组合,但正如它所说的那样,它并没有引导我得到结果,目前卡片的规则是。

   "cards": {
        ".indexOn": ["ownerID", "interestedUsers"],
      },

另外我知道我可以创建一个单独的数据结构,您可以在其中存储每个用户的卡片列表,并在其中得到确认,但我认为第一个选项更正确。谢谢

4

0 回答 0