def confirm_delivery(self):
        """
        Confirm the delivery as delivered, as the current user.

        Also withdraw money.
        """
        with Firestore.batch('packages') as batch:
            batch.update(self.request.uid, {
                'status': Status.DELIVERED,
            })

        assistant_ref = Firestore.get_raw('users').document(
            self.request.assistant.uid).get()
        assistant_balance = assistant_ref._data['balance']

        with Firestore.batch('users') as batch:
            batch.update(
                self.request.assistant.uid, {
                    'balance':
                    assistant_balance + self.request.money_lock +
                    self.request.reward,
                })

        toast("Package confirmed as delivered.")
        self._back_button_handler()
    def get_by_id(delivery_request_id: Text) -> DeliveryRequest:
        """
        Get a specific DeliveryRequest from Firestore

        :param delivery_request_id: The id of the delivery request.
        """
        data = Firestore.get_raw('packages').document(
            delivery_request_id).get().to_dict()
        data['uid'] = delivery_request_id
        data['status'] = Status(data['status'])
        return DeliveryRequest(**data)
示例#3
0
    def get_by_id(user_id: Text) -> Optional[User]:
        """
        Get a specific User from Firestore

        :param user_id: The id of the user.
        """
        if user_id == "":
            return None
        data = Firestore.get_raw('users').document(user_id).get().to_dict()
        if data is not None:
            return User(_uid=user_id, **data)
        else:
            return None
    def query(field_path: Text, op_str: Text,
              value: Any) -> List[DeliveryRequest]:
        """
        Get a list of DeliveryRequest objects by querying Firestore

        :param field_path: The path being filtered on.
        :param op_str: The comparison operation being made
        :param value: The value which each entry is being compared to.
        """
        docs = Firestore.get_raw('packages').where(field_path, op_str,
                                                   value).stream()

        delivery_requests = []
        for doc in docs:
            data = doc.to_dict()
            data['uid'] = doc.id
            data['status'] = Status(data['status'])
            delivery_requests.append(DeliveryRequest(**data))

        return delivery_requests