def mark_as_complete(transaction: Transaction, task_id): ref: DocumentReference = db.collection('groupTasks').document(task_id) d = ref.get(ref, transaction) m = GroupTaskModel.from_dict(d) if not m.in_process: raise ValueError("task_id: {} is not in process. ".format(task_id)) if m.completed: raise ValueError("task_id: {} is already completed. ".format(task_id)) m.in_process = False m.completed = True transaction.set(m.to_dict())
def start_by_id(transaction: Transaction, task_id): ref: DocumentReference = db.collection('groupTasks').document(task_id) d = ref.get(ref, transaction) m = GroupTaskModel.from_dict(d) if m.in_process: raise ValueError("task_id: {} is already being processed. ".format(task_id)) if m.completed: raise ValueError("task_id: {} is already completed. ".format(task_id)) m.in_process = True transaction.set(m.to_dict()) return m
def add_to_event_schedule_with_transaction( transaction: Transaction, user_ref: str = None, event_ref: DocumentReference = None, event_schedule: AirportEventSchedule = None): """ Description Add a event schedule to users/<userId>/eventSchedule Note that the toEventRideRequestRef will be overwritten without warning if already set. (Same for fromEventRideRequestRef.) :type transaction:Transaction: :param transaction:Transaction: :type user_ref:str: :param user_ref:str: :type event_ref:str: :param event_ref:str: :type event_schedule:dict: :param event_schedule:dict: :raises: :rtype: """ # userRef: DocumentReference = db.collection(u'users').document(userRef) # Get the CollectionReference of the collection that contains AirportEventSchedule's event_schedules_ref: CollectionReference = user_ref.collection( u'eventSchedules') # Retrieve document id to be used as the key event_id = event_ref.id # eventId = 'testeventid1' # warnings.warn("Using mock/test event id. Must replace before release. ") # Get the DocumentReference for the AirportEventSchedule event_schedule_ref: DocumentReference = event_schedules_ref.document( event_id) event_schedule_dict = event_schedule.to_dict() transaction.set( event_schedule_ref, event_schedule_dict, merge=True) # So that 'fromEventRideRequestRef' is not overwritten
def set_with_transaction(transaction: Transaction, newRideRequest: Type[RideRequest], rideRequestRef: DocumentReference): """ Description Note that a read action must have taken place before anything is set with that transaction. :type transaction:Transaction: :param transaction:Transaction: :type newRideRequest:Type[RideRequest]: :param newRideRequest:Type[RideRequest]: :type rideRequestRef:DocumentReference: :param rideRequestRef:DocumentReference: :raises: :rtype: """ return transaction.set(rideRequestRef, newRideRequest.to_dict())
def set_with_transaction(transaction: Transaction, newEventSchedule: Type[AirportEventSchedule], eventScheduleRef: DocumentReference): """ Description Note that a read action must have taken place before anything is set with that transaction. :type self: :param self: :type transaction:Transaction: :param transaction:Transaction: :type newEventSchedule:Type[AirportEventSchedule]: :param newEventSchedule:Type[AirportEventSchedule]: :type eventScheduleRef:DocumentReference: :param eventScheduleRef:DocumentReference: :raises: :rtype: """ raise NotImplementedError # TODO: fix return transaction.set(eventScheduleRef, newEventSchedule)
def set_with_transaction(transaction: Transaction, newLocation: Type[Location], locationRef: DocumentReference): """ Description Note that a read action must have taken place before anything is set with that transaction. :type self: :param self: :type transaction:Transaction: :param transaction:Transaction: :type newLocation:Type[Location]: :param newLocation:Type[Location]: :type locationRef:DocumentReference: :param locationRef:DocumentReference: :raises: :rtype: """ locationDict = newLocation.to_dict() return transaction.set(locationRef, locationDict)
def _set_with_transaction(transaction: Transaction, newLocation: Type[Location], locationRef: DocumentReference): return transaction.set(locationRef, newLocation)
def set_with_transaction(self, transaction: Transaction, new_user: User, user_ref: DocumentReference): transaction.set(user_ref, new_user)
def set_user_with_transaction(transaction: Transaction, newUser: Type[User], userRef: DocumentReference): transaction.set(userRef, newUser.to_firestore_dict())
def set_with_transaction(transaction: Transaction, newOrbit: Orbit, orbitRef: DocumentReference): """ Description Note that a read action must have taken place before anything is set with that transaction. """ return transaction.set(orbitRef, newOrbit.to_dict())