def update_hygiene():
    user_uuid = str(request.form.get("uuid", None))
    hygiene_name_to_update = request.form.get("hygiene_name", None)
    hygiene_is_done = str(request.form.get("is_done", None))

    if hygiene_is_done is not None:
        if hygiene_is_done.lower() == "true":
            hygiene_is_done = True
        elif hygiene_is_done.lower() == "false":
            hygiene_is_done = False
        else:
            return return_json(success=False,
                               error="Invalid delete all: true | false")
    else:
        hygiene_is_done = True

    if not data_validation.validate_uuid(user_uuid):
        return return_json(success=False, error="Invalid UUID")

    if not data_validation.verify_user(user_uuid):
        return return_json(success=False, error="User not found")

    res = db.get_user_hygiene(user_uuid)

    c_hygienes = hygiene.Hygiene()
    c_hygienes.from_mongo(res)

    res = c_hygienes.update_hygiene(hygiene_name_to_update, hygiene_is_done)
    db.update_one({'user_uuid': user_uuid}, {"$set": c_hygienes.json()})
    return res
def update_reminders():
    user_uuid = str(request.form.get("uuid", None))

    if not data_validation.validate_uuid(user_uuid):
        return return_json(success=False, error="Invalid UUID")

    if not data_validation.verify_user(user_uuid):
        return return_json(success=False, error="User not found")

    sheets_days = request.form.get("sheets", None)
    bathroom_days = request.form.get("bathroom", None)
    house_days = request.form.get("house", None)
    kitchen_days = request.form.get("kitchen", None)
    dishes_days = request.form.get("dishes", None)
    vacuum_days = request.form.get("vacuum", None)

    update_dict = {
        "sheets": sheets_days,
        "bathroom": bathroom_days,
        "house": house_days,
        "kitchen": kitchen_days,
        "dishes": dishes_days,
        "vacuum": vacuum_days
    }

    return db.update_reminders(user_uuid, update_dict)
def get_inc():
    user_uuid = str(request.form.get("uuid", None))

    if not data_validation.validate_uuid(user_uuid):
        return return_json(success=False, error="Invalid user UUID")

    if not data_validation.verify_user(user_uuid):
        return return_json(success=False, error="User not found")

    return db.get_user_expenses(user_uuid)
def get_hygiene():
    user_uuid = str(request.form.get("uuid", None))

    if not data_validation.validate_uuid(user_uuid):
        return return_json(success=False, error="Invalid UUID")

    if not data_validation.verify_user(user_uuid):
        return return_json(success=False, error="User not found")

    c_hygiene = db.get_user_hygiene(user_uuid)

    return return_json(success=True, data={"hygiene": c_hygiene})
def get_schedule():
    user_uuid = str(request.form.get("uuid", None))

    if not data_validation.validate_uuid(user_uuid):
        return return_json(success=False, error="Invalid UUID")

    if not data_validation.verify_user(user_uuid):
        return return_json(success=False, error="User not found")

    res = db.get_user_schedule(user_uuid).get_events()

    return return_json(success=True, data={'schedule': res})
def get_schedule_by_date():
    user_uuid = str(request.form.get("uuid", None))
    date = str(request.form.get("date", None)).replace("-", "/")

    if not data_validation.validate_uuid(user_uuid):
        return return_json(success=False, error="Invalid UUID")

    if not data_validation.verify_user(user_uuid):
        return return_json(success=False, error="User not found")

    if not data_validation.validate_birthdate(date):
        return return_json(success=False,
                           error="Invalid date format: dd/mm/yyyy")

    res = db.get_user_schedule_by_date(user_uuid, date)

    return return_json(success=True, data={'schedule': res})
def update_current():
    user_uuid = str(request.form.get("uuid", None))
    expense_uuid = request.form.get("expense_uuid", None)
    amount = request.form.get("amount", None)

    if not data_validation.validate_uuid(user_uuid):
        return return_json(success=False, error="Invalid user UUID")

    if not data_validation.verify_user(user_uuid):
        return return_json(success=False, error="User not found")

    if amount is None:
        return return_json(success=False, error="Amount must be set")

    if not data_validation.validate_amount(amount):
        return return_json(success=False,
                           error="Est amount must be a number or decimal")

    return db.update_current_value(user_uuid, expense_uuid, amount)
def delete_event():
    user_uuid = str(request.form.get("uuid", None))
    event_uuid = request.form.get("event_uuid", None)
    delete_all = request.form.get("delete_all", None)
    if delete_all is not None:
        if delete_all.lower() == "true":
            delete_all = True
        elif delete_all.lower() == "false":
            delete_all = False
        else:
            return return_json(success=False,
                               error="Invalid delete all: true | false")
    else:
        delete_all = False

    if not data_validation.validate_uuid(user_uuid):
        return return_json(success=False, error="Invalid user UUID")

    if not data_validation.verify_user(user_uuid):
        return return_json(success=False, error="User not found")

    return db.delete_event(user_uuid, event_uuid, delete_all)
def update_event():
    user_uuid = str(request.form.get("uuid", None))
    start = str(request.form.get("start", None)).replace(
        "-", "/")  # Ios datetime uses '-' instead of '/'
    end = str(request.form.get("end", None)).replace("-", "/")
    title = str(request.form.get("title", None))
    content = str(request.form.get("content", None))
    location = str(request.form.get("location", None))
    remind_minutes_before = request.form.get("remind_minutes_before", None)
    event_uuid = request.form.get("event_uuid", None)

    if not data_validation.validate_uuid(user_uuid):
        return return_json(success=False, error="Invalid user UUID")

    if not data_validation.verify_user(user_uuid):
        return return_json(success=False, error="User not found")

    if not data_validation.validate_datetime(start)[0]:
        return return_json(success=False,
                           error=data_validation.validate_datetime(start)[1])

    if not data_validation.validate_datetime(end)[0]:
        return return_json(success=False,
                           error=data_validation.validate_datetime(end)[1])

    time_validation = data_validation.validate_start_before_end(start, end)
    if not time_validation[0]:
        return return_json(success=False, error=time_validation[1])

    if remind_minutes_before is None:
        remind_minutes_before = 30  # Default value
    else:
        if not data_validation.validate_amount(remind_minutes_before):
            return return_json(success=False,
                               error="remind_minutes_before must be a number")
        remind_minutes_before = int(remind_minutes_before)

    return db.update_schedule(user_uuid, start, end, title, content, location,
                              remind_minutes_before, event_uuid)
def update_expenses():
    user_uuid = str(request.form.get("uuid", None))
    expense_type = str(request.form.get("expense_type", None)).lower()
    est_amount = str(request.form.get("est_amount", None))
    title = str(request.form.get("title", None))
    expense_uuid = request.form.get("expense_uuid", None)

    if expense_type != "exp" and expense_type != "inc":
        return return_json(success=False,
                           error="Invalid expense type: inc | exp")

    if not data_validation.validate_uuid(user_uuid):
        return return_json(success=False, error="Invalid user UUID")

    if not data_validation.verify_user(user_uuid):
        return return_json(success=False, error="User not found")

    if not data_validation.validate_amount(est_amount):
        return return_json(success=False,
                           error="Est amount must be a number or decimal")

    return db.update_expense(user_uuid, expense_type, est_amount, title,
                             expense_uuid)
示例#11
0
def set_arduino_uuid():
    user_uuid = request.form.get("uuid", None)
    arduino_uuid = request.form.get("arduino_uuid", None)

    if not data_validation.validate_uuid(user_uuid):
        return return_json(success=False, error="Invalid user UUID")

    if not data_validation.validate_uuid(arduino_uuid):
        return return_json(success=False, error="Invalid arduino UUID")

    if not data_validation.verify_user(user_uuid):
        return return_json(success=False, error="User not found")

    if arduino_db.get_user_uuid_by_arduino_uuid(arduino_uuid):
        c_user_uuid = arduino_db.get_user_uuid_by_arduino_uuid(arduino_uuid)
        if c_user_uuid:  # If the user has an arduino linked we need to remove it from that arduino
            c_arduino_mongo = arduino_db.find_one(
                {'arduino_uuid': arduino_uuid})
            c_arduino = arduino.Arduino.from_mongo(c_arduino_mongo)
            c_arduino.user_uuid = None
            arduino_db.update_one({'arduino_uuid': arduino_uuid},
                                  {"$set": c_arduino.json()})

    return arduino_db.link_arduino(arduino_uuid, user_uuid)