def add_available_date(room: Room, start_date: datetime.datetime,
                       days: int) -> Room:
    booking = Booking()
    booking.check_in_date = start_date
    booking.check_out_date = start_date + datetime.timedelta(days=days)

    room = Room.objects(id=room.id).first()
    room.bookings.append(booking)
    room.save()

    return room
def book_room(account: Owner, guest: Guest, selected_room: Room,
              start_date: datetime, end_date: datetime):
    booking: Optional[Booking] = None
    for b in selected_room.bookings:
        if b.check_in_date <= start_date and b.check_out_date >= end_date \
                and b.guest_id is None:
            booking = b
            break
    booking.guest_owner_id = account.id
    booking.guest_id = guest.id
    booking.booked_date = datetime.now()
    booking.check_in_date = start_date
    booking.check_out_date = end_date

    selected_room.save()
def register_room(active_account: Owner, name, allow_deepthroat,
                  has_instruments, milf, price) -> Room:
    room = Room()

    room.name = name
    room.is_milf = milf
    room.has_instruments = has_instruments
    room.allow_deepthroat = allow_deepthroat
    room.price = price

    room.save()

    account = find_account_by_email(active_account.email)
    account.room_ids.append(room.id)
    account.save()

    return room
def register_room(account: Owner, number: str, rtype: str, price: float,
                  area: float, allow_pets: bool) -> Room:
    room = Room()
    room.number = number
    room.rtype = rtype
    room.price = price
    room.area = area
    room.allow_pets = allow_pets
    # Save the room to DB.
    room.save()

    # Get latest owner info from the db
    account = find_account_by_email(account.email)
    # Append it to the list of rooms
    account.room_ids.append(room.id)
    account.save()

    return room
def get_available_rooms(start_date: datetime, end_date: datetime,
                        allow_pets: bool) -> List[Room]:
    query = Room.objects().filter(bookings__check_in_date__lte=start_date)\
        .filter(bookings__check_out_date__gte=end_date)
    if allow_pets:
        query = query.filter(allow_pets=True)

    rooms = list(query.order_by('price', '-area'))

    for room in rooms:
        for booking in room.bookings:
            if (booking.check_in_date > start_date) and booking.check_out_date \
                    < end_date and booking.guest_id is not None:
                rooms.remove(room)

    return rooms
def get_bookings_for_user(email: str) -> List[Booking]:
    account = find_account_by_email(email)

    booked_rooms = Room.objects() \
        .filter(bookings__guest_owner_id=account.id) \
        .only('bookings', 'name')

    def map_room_to_booking(room, booking):
        booking.room = room
        return booking

    bookings = [
        map_room_to_booking(room, booking) for room in booked_rooms
        for booking in room.bookings if booking.guest_owner_id == account.id
    ]

    return bookings
def get_available_rooms(checkin: datetime.datetime,
                        checkout: datetime.datetime,
                        bitch: Bitch) -> List[Room]:

    query = Room.objects() \
        .filter(bookings__check_in_date__lte=checkin) \
        .filter(bookings__check_out_date__gte=checkout)

    if bitch.is_cruel:
        query = query.filter(allow_deepthroat=True)

    rooms = query.order_by('price')

    final_rooms = []
    for c in rooms:
        for b in c.bookings:
            if b.check_in_date <= checkin and b.check_out_date >= checkout and b.guest_snake_id is None:
                final_rooms.append(c)

    return final_rooms
def find_rooms_for_user(account: Owner) -> List[Room]:
    query = Room.objects(id__in=account.room_ids)
    rooms = list(query)

    return rooms
def find_room_by_number(room_number: str) -> Room:
    return Room.objects(number=room_number).first()
def find_rooms_for_user(account: Owner) -> List[Room]:
    return list(Room.objects(id__in=account.room_ids))